OSDN Git Service

Merge "Take HOST_PREFER_32_BIT into account"
[android-x86/external-llvm.git] / lib / Target / Hexagon / HexagonNewValueJump.cpp
1 //===----- HexagonNewValueJump.cpp - Hexagon Backend New Value Jump -------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This implements NewValueJump pass in Hexagon.
11 // Ideally, we should merge this as a Peephole pass prior to register
12 // allocation, but because we have a spill in between the feeder and new value
13 // jump instructions, we are forced to write after register allocation.
14 // Having said that, we should re-attempt to pull this earlier at some point
15 // in future.
16
17 // The basic approach looks for sequence of predicated jump, compare instruciton
18 // that genereates the predicate and, the feeder to the predicate. Once it finds
19 // all, it collapses compare and jump instruction into a new valu jump
20 // intstructions.
21 //
22 //
23 //===----------------------------------------------------------------------===//
24 #include "llvm/PassSupport.h"
25 #include "Hexagon.h"
26 #include "HexagonInstrInfo.h"
27 #include "HexagonMachineFunctionInfo.h"
28 #include "HexagonRegisterInfo.h"
29 #include "HexagonSubtarget.h"
30 #include "HexagonTargetMachine.h"
31 #include "llvm/ADT/DenseMap.h"
32 #include "llvm/ADT/Statistic.h"
33 #include "llvm/CodeGen/LiveVariables.h"
34 #include "llvm/CodeGen/MachineFunctionAnalysis.h"
35 #include "llvm/CodeGen/MachineFunctionPass.h"
36 #include "llvm/CodeGen/MachineInstrBuilder.h"
37 #include "llvm/CodeGen/MachineRegisterInfo.h"
38 #include "llvm/CodeGen/Passes.h"
39 #include "llvm/CodeGen/ScheduleDAGInstrs.h"
40 #include "llvm/Support/CommandLine.h"
41 #include "llvm/Support/Compiler.h"
42 #include "llvm/Support/Debug.h"
43 #include "llvm/Target/TargetInstrInfo.h"
44 #include "llvm/Target/TargetMachine.h"
45 #include "llvm/Target/TargetRegisterInfo.h"
46 #include <map>
47 using namespace llvm;
48
49 #define DEBUG_TYPE "hexagon-nvj"
50
51 STATISTIC(NumNVJGenerated, "Number of New Value Jump Instructions created");
52
53 static cl::opt<int>
54 DbgNVJCount("nvj-count", cl::init(-1), cl::Hidden, cl::desc(
55   "Maximum number of predicated jumps to be converted to New Value Jump"));
56
57 static cl::opt<bool> DisableNewValueJumps("disable-nvjump", cl::Hidden,
58     cl::ZeroOrMore, cl::init(false),
59     cl::desc("Disable New Value Jumps"));
60
61 namespace llvm {
62   void initializeHexagonNewValueJumpPass(PassRegistry&);
63 }
64
65
66 namespace {
67   struct HexagonNewValueJump : public MachineFunctionPass {
68     const HexagonInstrInfo    *QII;
69     const HexagonRegisterInfo *QRI;
70
71   public:
72     static char ID;
73
74     HexagonNewValueJump() : MachineFunctionPass(ID) {
75       initializeHexagonNewValueJumpPass(*PassRegistry::getPassRegistry());
76     }
77
78     void getAnalysisUsage(AnalysisUsage &AU) const override {
79       AU.addRequired<MachineBranchProbabilityInfo>();
80       MachineFunctionPass::getAnalysisUsage(AU);
81     }
82
83     const char *getPassName() const override {
84       return "Hexagon NewValueJump";
85     }
86
87     bool runOnMachineFunction(MachineFunction &Fn) override;
88
89   private:
90     /// \brief A handle to the branch probability pass.
91     const MachineBranchProbabilityInfo *MBPI;
92
93   };
94
95 } // end of anonymous namespace
96
97 char HexagonNewValueJump::ID = 0;
98
99 INITIALIZE_PASS_BEGIN(HexagonNewValueJump, "hexagon-nvj",
100                       "Hexagon NewValueJump", false, false)
101 INITIALIZE_PASS_DEPENDENCY(MachineBranchProbabilityInfo)
102 INITIALIZE_PASS_END(HexagonNewValueJump, "hexagon-nvj",
103                     "Hexagon NewValueJump", false, false)
104
105
106 // We have identified this II could be feeder to NVJ,
107 // verify that it can be.
108 static bool canBeFeederToNewValueJump(const HexagonInstrInfo *QII,
109                                       const TargetRegisterInfo *TRI,
110                                       MachineBasicBlock::iterator II,
111                                       MachineBasicBlock::iterator end,
112                                       MachineBasicBlock::iterator skip,
113                                       MachineFunction &MF) {
114
115   // Predicated instruction can not be feeder to NVJ.
116   if (QII->isPredicated(II))
117     return false;
118
119   // Bail out if feederReg is a paired register (double regs in
120   // our case). One would think that we can check to see if a given
121   // register cmpReg1 or cmpReg2 is a sub register of feederReg
122   // using -- if (QRI->isSubRegister(feederReg, cmpReg1) logic
123   // before the callsite of this function
124   // But we can not as it comes in the following fashion.
125   //    %D0<def> = Hexagon_S2_lsr_r_p %D0<kill>, %R2<kill>
126   //    %R0<def> = KILL %R0, %D0<imp-use,kill>
127   //    %P0<def> = CMPEQri %R0<kill>, 0
128   // Hence, we need to check if it's a KILL instruction.
129   if (II->getOpcode() == TargetOpcode::KILL)
130     return false;
131
132
133   // Make sure there there is no 'def' or 'use' of any of the uses of
134   // feeder insn between it's definition, this MI and jump, jmpInst
135   // skipping compare, cmpInst.
136   // Here's the example.
137   //    r21=memub(r22+r24<<#0)
138   //    p0 = cmp.eq(r21, #0)
139   //    r4=memub(r3+r21<<#0)
140   //    if (p0.new) jump:t .LBB29_45
141   // Without this check, it will be converted into
142   //    r4=memub(r3+r21<<#0)
143   //    r21=memub(r22+r24<<#0)
144   //    p0 = cmp.eq(r21, #0)
145   //    if (p0.new) jump:t .LBB29_45
146   // and result WAR hazards if converted to New Value Jump.
147
148   for (unsigned i = 0; i < II->getNumOperands(); ++i) {
149     if (II->getOperand(i).isReg() &&
150         (II->getOperand(i).isUse() || II->getOperand(i).isDef())) {
151       MachineBasicBlock::iterator localII = II;
152       ++localII;
153       unsigned Reg = II->getOperand(i).getReg();
154       for (MachineBasicBlock::iterator localBegin = localII;
155                         localBegin != end; ++localBegin) {
156         if (localBegin == skip ) continue;
157         // Check for Subregisters too.
158         if (localBegin->modifiesRegister(Reg, TRI) ||
159             localBegin->readsRegister(Reg, TRI))
160           return false;
161       }
162     }
163   }
164   return true;
165 }
166
167 // These are the common checks that need to performed
168 // to determine if
169 // 1. compare instruction can be moved before jump.
170 // 2. feeder to the compare instruction can be moved before jump.
171 static bool commonChecksToProhibitNewValueJump(bool afterRA,
172                           MachineBasicBlock::iterator MII) {
173
174   // If store in path, bail out.
175   if (MII->getDesc().mayStore())
176     return false;
177
178   // if call in path, bail out.
179   if (MII->getOpcode() == Hexagon::J2_call)
180     return false;
181
182   // if NVJ is running prior to RA, do the following checks.
183   if (!afterRA) {
184     // The following Target Opcode instructions are spurious
185     // to new value jump. If they are in the path, bail out.
186     // KILL sets kill flag on the opcode. It also sets up a
187     // single register, out of pair.
188     //    %D0<def> = Hexagon_S2_lsr_r_p %D0<kill>, %R2<kill>
189     //    %R0<def> = KILL %R0, %D0<imp-use,kill>
190     //    %P0<def> = CMPEQri %R0<kill>, 0
191     // PHI can be anything after RA.
192     // COPY can remateriaze things in between feeder, compare and nvj.
193     if (MII->getOpcode() == TargetOpcode::KILL ||
194         MII->getOpcode() == TargetOpcode::PHI  ||
195         MII->getOpcode() == TargetOpcode::COPY)
196       return false;
197
198     // The following pseudo Hexagon instructions sets "use" and "def"
199     // of registers by individual passes in the backend. At this time,
200     // we don't know the scope of usage and definitions of these
201     // instructions.
202     if (MII->getOpcode() == Hexagon::TFR_condset_ii ||
203         MII->getOpcode() == Hexagon::TFR_condset_ri ||
204         MII->getOpcode() == Hexagon::TFR_condset_ir ||
205         MII->getOpcode() == Hexagon::LDriw_pred     ||
206         MII->getOpcode() == Hexagon::STriw_pred)
207       return false;
208   }
209
210   return true;
211 }
212
213 static bool canCompareBeNewValueJump(const HexagonInstrInfo *QII,
214                                      const TargetRegisterInfo *TRI,
215                                      MachineBasicBlock::iterator II,
216                                      unsigned pReg,
217                                      bool secondReg,
218                                      bool optLocation,
219                                      MachineBasicBlock::iterator end,
220                                      MachineFunction &MF) {
221
222   MachineInstr *MI = II;
223
224   // If the second operand of the compare is an imm, make sure it's in the
225   // range specified by the arch.
226   if (!secondReg) {
227     int64_t v = MI->getOperand(2).getImm();
228
229     if (!(isUInt<5>(v) ||
230          ((MI->getOpcode() == Hexagon::C2_cmpeqi ||
231            MI->getOpcode() == Hexagon::C2_cmpgti) &&
232           (v == -1))))
233       return false;
234   }
235
236   unsigned cmpReg1, cmpOp2 = 0; // cmpOp2 assignment silences compiler warning.
237   cmpReg1 = MI->getOperand(1).getReg();
238
239   if (secondReg) {
240     cmpOp2 = MI->getOperand(2).getReg();
241
242     // Make sure that that second register is not from COPY
243     // At machine code level, we don't need this, but if we decide
244     // to move new value jump prior to RA, we would be needing this.
245     MachineRegisterInfo &MRI = MF.getRegInfo();
246     if (secondReg && !TargetRegisterInfo::isPhysicalRegister(cmpOp2)) {
247       MachineInstr *def = MRI.getVRegDef(cmpOp2);
248       if (def->getOpcode() == TargetOpcode::COPY)
249         return false;
250     }
251   }
252
253   // Walk the instructions after the compare (predicate def) to the jump,
254   // and satisfy the following conditions.
255   ++II ;
256   for (MachineBasicBlock::iterator localII = II; localII != end;
257        ++localII) {
258
259     // Check 1.
260     // If "common" checks fail, bail out.
261     if (!commonChecksToProhibitNewValueJump(optLocation, localII))
262       return false;
263
264     // Check 2.
265     // If there is a def or use of predicate (result of compare), bail out.
266     if (localII->modifiesRegister(pReg, TRI) ||
267         localII->readsRegister(pReg, TRI))
268       return false;
269
270     // Check 3.
271     // If there is a def of any of the use of the compare (operands of compare),
272     // bail out.
273     // Eg.
274     //    p0 = cmp.eq(r2, r0)
275     //    r2 = r4
276     //    if (p0.new) jump:t .LBB28_3
277     if (localII->modifiesRegister(cmpReg1, TRI) ||
278         (secondReg && localII->modifiesRegister(cmpOp2, TRI)))
279       return false;
280   }
281   return true;
282 }
283
284 // Given a compare operator, return a matching New Value Jump
285 // compare operator. Make sure that MI here is included in
286 // HexagonInstrInfo.cpp::isNewValueJumpCandidate
287 static unsigned getNewValueJumpOpcode(MachineInstr *MI, int reg,
288                                       bool secondRegNewified,
289                                       MachineBasicBlock *jmpTarget,
290                                       const MachineBranchProbabilityInfo
291                                       *MBPI) {
292   bool taken = false;
293   MachineBasicBlock *Src = MI->getParent();
294   const BranchProbability Prediction =
295     MBPI->getEdgeProbability(Src, jmpTarget);
296
297   if (Prediction >= BranchProbability(1,2))
298     taken = true;
299
300   switch (MI->getOpcode()) {
301     case Hexagon::C2_cmpeq:
302       return taken ? Hexagon::J4_cmpeq_t_jumpnv_t
303                    : Hexagon::J4_cmpeq_t_jumpnv_nt;
304
305     case Hexagon::C2_cmpeqi: {
306       if (reg >= 0)
307         return taken ? Hexagon::J4_cmpeqi_t_jumpnv_t
308                      : Hexagon::J4_cmpeqi_t_jumpnv_nt;
309       else
310         return taken ? Hexagon::J4_cmpeqn1_t_jumpnv_t
311                      : Hexagon::J4_cmpeqn1_t_jumpnv_nt;
312     }
313
314     case Hexagon::C2_cmpgt: {
315       if (secondRegNewified)
316         return taken ? Hexagon::J4_cmplt_t_jumpnv_t
317                      : Hexagon::J4_cmplt_t_jumpnv_nt;
318       else
319         return taken ? Hexagon::J4_cmpgt_t_jumpnv_t
320                      : Hexagon::J4_cmpgt_t_jumpnv_nt;
321     }
322
323     case Hexagon::C2_cmpgti: {
324       if (reg >= 0)
325         return taken ? Hexagon::J4_cmpgti_t_jumpnv_t
326                      : Hexagon::J4_cmpgti_t_jumpnv_nt;
327       else
328         return taken ? Hexagon::J4_cmpgtn1_t_jumpnv_t
329                      : Hexagon::J4_cmpgtn1_t_jumpnv_nt;
330     }
331
332     case Hexagon::C2_cmpgtu: {
333       if (secondRegNewified)
334         return taken ? Hexagon::J4_cmpltu_t_jumpnv_t
335                      : Hexagon::J4_cmpltu_t_jumpnv_nt;
336       else
337         return taken ? Hexagon::J4_cmpgtu_t_jumpnv_t
338                      : Hexagon::J4_cmpgtu_t_jumpnv_nt;
339     }
340
341     case Hexagon::C2_cmpgtui:
342       return taken ? Hexagon::J4_cmpgtui_t_jumpnv_t
343                    : Hexagon::J4_cmpgtui_t_jumpnv_nt;
344
345     default:
346        llvm_unreachable("Could not find matching New Value Jump instruction.");
347   }
348   // return *some value* to avoid compiler warning
349   return 0;
350 }
351
352 bool HexagonNewValueJump::runOnMachineFunction(MachineFunction &MF) {
353
354   DEBUG(dbgs() << "********** Hexagon New Value Jump **********\n"
355                << "********** Function: "
356                << MF.getName() << "\n");
357
358   // If we move NewValueJump before register allocation we'll need live variable
359   // analysis here too.
360
361   QII = static_cast<const HexagonInstrInfo *>(MF.getSubtarget().getInstrInfo());
362   QRI = static_cast<const HexagonRegisterInfo *>(
363       MF.getSubtarget().getRegisterInfo());
364   MBPI = &getAnalysis<MachineBranchProbabilityInfo>();
365
366   if (DisableNewValueJumps) {
367     return false;
368   }
369
370   int nvjCount = DbgNVJCount;
371   int nvjGenerated = 0;
372
373   // Loop through all the bb's of the function
374   for (MachineFunction::iterator MBBb = MF.begin(), MBBe = MF.end();
375         MBBb != MBBe; ++MBBb) {
376     MachineBasicBlock* MBB = MBBb;
377
378     DEBUG(dbgs() << "** dumping bb ** "
379                  << MBB->getNumber() << "\n");
380     DEBUG(MBB->dump());
381     DEBUG(dbgs() << "\n" << "********** dumping instr bottom up **********\n");
382     bool foundJump    = false;
383     bool foundCompare = false;
384     bool invertPredicate = false;
385     unsigned predReg = 0; // predicate reg of the jump.
386     unsigned cmpReg1 = 0;
387     int cmpOp2 = 0;
388     bool MO1IsKill = false;
389     bool MO2IsKill = false;
390     MachineBasicBlock::iterator jmpPos;
391     MachineBasicBlock::iterator cmpPos;
392     MachineInstr *cmpInstr = nullptr, *jmpInstr = nullptr;
393     MachineBasicBlock *jmpTarget = nullptr;
394     bool afterRA = false;
395     bool isSecondOpReg = false;
396     bool isSecondOpNewified = false;
397     // Traverse the basic block - bottom up
398     for (MachineBasicBlock::iterator MII = MBB->end(), E = MBB->begin();
399              MII != E;) {
400       MachineInstr *MI = --MII;
401       if (MI->isDebugValue()) {
402         continue;
403       }
404
405       if ((nvjCount == 0) || (nvjCount > -1 && nvjCount <= nvjGenerated))
406         break;
407
408       DEBUG(dbgs() << "Instr: "; MI->dump(); dbgs() << "\n");
409
410       if (!foundJump &&
411          (MI->getOpcode() == Hexagon::J2_jumpt ||
412           MI->getOpcode() == Hexagon::J2_jumpf ||
413           MI->getOpcode() == Hexagon::J2_jumptnewpt ||
414           MI->getOpcode() == Hexagon::J2_jumptnew ||
415           MI->getOpcode() == Hexagon::J2_jumpfnewpt ||
416           MI->getOpcode() == Hexagon::J2_jumpfnew)) {
417         // This is where you would insert your compare and
418         // instr that feeds compare
419         jmpPos = MII;
420         jmpInstr = MI;
421         predReg = MI->getOperand(0).getReg();
422         afterRA = TargetRegisterInfo::isPhysicalRegister(predReg);
423
424         // If ifconverter had not messed up with the kill flags of the
425         // operands, the following check on the kill flag would suffice.
426         // if(!jmpInstr->getOperand(0).isKill()) break;
427
428         // This predicate register is live out out of BB
429         // this would only work if we can actually use Live
430         // variable analysis on phy regs - but LLVM does not
431         // provide LV analysis on phys regs.
432         //if(LVs.isLiveOut(predReg, *MBB)) break;
433
434         // Get all the successors of this block - which will always
435         // be 2. Check if the predicate register is live in in those
436         // successor. If yes, we can not delete the predicate -
437         // I am doing this only because LLVM does not provide LiveOut
438         // at the BB level.
439         bool predLive = false;
440         for (MachineBasicBlock::const_succ_iterator SI = MBB->succ_begin(),
441                             SIE = MBB->succ_end(); SI != SIE; ++SI) {
442           MachineBasicBlock* succMBB = *SI;
443          if (succMBB->isLiveIn(predReg)) {
444             predLive = true;
445           }
446         }
447         if (predLive)
448           break;
449
450         jmpTarget = MI->getOperand(1).getMBB();
451         foundJump = true;
452         if (MI->getOpcode() == Hexagon::J2_jumpf ||
453             MI->getOpcode() == Hexagon::J2_jumpfnewpt ||
454             MI->getOpcode() == Hexagon::J2_jumpfnew) {
455           invertPredicate = true;
456         }
457         continue;
458       }
459
460       // No new value jump if there is a barrier. A barrier has to be in its
461       // own packet. A barrier has zero operands. We conservatively bail out
462       // here if we see any instruction with zero operands.
463       if (foundJump && MI->getNumOperands() == 0)
464         break;
465
466       if (foundJump &&
467          !foundCompare &&
468           MI->getOperand(0).isReg() &&
469           MI->getOperand(0).getReg() == predReg) {
470
471         // Not all compares can be new value compare. Arch Spec: 7.6.1.1
472         if (QII->isNewValueJumpCandidate(MI)) {
473
474           assert((MI->getDesc().isCompare()) &&
475               "Only compare instruction can be collapsed into New Value Jump");
476           isSecondOpReg = MI->getOperand(2).isReg();
477
478           if (!canCompareBeNewValueJump(QII, QRI, MII, predReg, isSecondOpReg,
479                                         afterRA, jmpPos, MF))
480             break;
481
482           cmpInstr = MI;
483           cmpPos = MII;
484           foundCompare = true;
485
486           // We need cmpReg1 and cmpOp2(imm or reg) while building
487           // new value jump instruction.
488           cmpReg1 = MI->getOperand(1).getReg();
489           if (MI->getOperand(1).isKill())
490             MO1IsKill = true;
491
492           if (isSecondOpReg) {
493             cmpOp2 = MI->getOperand(2).getReg();
494             if (MI->getOperand(2).isKill())
495               MO2IsKill = true;
496           } else
497             cmpOp2 = MI->getOperand(2).getImm();
498           continue;
499         }
500       }
501
502       if (foundCompare && foundJump) {
503
504         // If "common" checks fail, bail out on this BB.
505         if (!commonChecksToProhibitNewValueJump(afterRA, MII))
506           break;
507
508         bool foundFeeder = false;
509         MachineBasicBlock::iterator feederPos = MII;
510         if (MI->getOperand(0).isReg() &&
511             MI->getOperand(0).isDef() &&
512            (MI->getOperand(0).getReg() == cmpReg1 ||
513             (isSecondOpReg &&
514              MI->getOperand(0).getReg() == (unsigned) cmpOp2))) {
515
516           unsigned feederReg = MI->getOperand(0).getReg();
517
518           // First try to see if we can get the feeder from the first operand
519           // of the compare. If we can not, and if secondOpReg is true
520           // (second operand of the compare is also register), try that one.
521           // TODO: Try to come up with some heuristic to figure out which
522           // feeder would benefit.
523
524           if (feederReg == cmpReg1) {
525             if (!canBeFeederToNewValueJump(QII, QRI, MII, jmpPos, cmpPos, MF)) {
526               if (!isSecondOpReg)
527                 break;
528               else
529                 continue;
530             } else
531               foundFeeder = true;
532           }
533
534           if (!foundFeeder &&
535                isSecondOpReg &&
536                feederReg == (unsigned) cmpOp2)
537             if (!canBeFeederToNewValueJump(QII, QRI, MII, jmpPos, cmpPos, MF))
538               break;
539
540           if (isSecondOpReg) {
541             // In case of CMPLT, or CMPLTU, or EQ with the second register
542             // to newify, swap the operands.
543             if (cmpInstr->getOpcode() == Hexagon::C2_cmpeq &&
544                                      feederReg == (unsigned) cmpOp2) {
545               unsigned tmp = cmpReg1;
546               bool tmpIsKill = MO1IsKill;
547               cmpReg1 = cmpOp2;
548               MO1IsKill = MO2IsKill;
549               cmpOp2 = tmp;
550               MO2IsKill = tmpIsKill;
551             }
552
553             // Now we have swapped the operands, all we need to check is,
554             // if the second operand (after swap) is the feeder.
555             // And if it is, make a note.
556             if (feederReg == (unsigned)cmpOp2)
557               isSecondOpNewified = true;
558           }
559
560           // Now that we are moving feeder close the jump,
561           // make sure we are respecting the kill values of
562           // the operands of the feeder.
563
564           bool updatedIsKill = false;
565           for (unsigned i = 0; i < MI->getNumOperands(); i++) {
566             MachineOperand &MO = MI->getOperand(i);
567             if (MO.isReg() && MO.isUse()) {
568               unsigned feederReg = MO.getReg();
569               for (MachineBasicBlock::iterator localII = feederPos,
570                    end = jmpPos; localII != end; localII++) {
571                 MachineInstr *localMI = localII;
572                 for (unsigned j = 0; j < localMI->getNumOperands(); j++) {
573                   MachineOperand &localMO = localMI->getOperand(j);
574                   if (localMO.isReg() && localMO.isUse() &&
575                       localMO.isKill() && feederReg == localMO.getReg()) {
576                     // We found that there is kill of a use register
577                     // Set up a kill flag on the register
578                     localMO.setIsKill(false);
579                     MO.setIsKill();
580                     updatedIsKill = true;
581                     break;
582                   }
583                 }
584                 if (updatedIsKill) break;
585               }
586             }
587             if (updatedIsKill) break;
588           }
589
590           MBB->splice(jmpPos, MI->getParent(), MI);
591           MBB->splice(jmpPos, MI->getParent(), cmpInstr);
592           DebugLoc dl = MI->getDebugLoc();
593           MachineInstr *NewMI;
594
595            assert((QII->isNewValueJumpCandidate(cmpInstr)) &&
596                       "This compare is not a New Value Jump candidate.");
597           unsigned opc = getNewValueJumpOpcode(cmpInstr, cmpOp2,
598                                                isSecondOpNewified,
599                                                jmpTarget, MBPI);
600           if (invertPredicate)
601             opc = QII->getInvertedPredicatedOpcode(opc);
602
603           if (isSecondOpReg)
604             NewMI = BuildMI(*MBB, jmpPos, dl,
605                                   QII->get(opc))
606                                     .addReg(cmpReg1, getKillRegState(MO1IsKill))
607                                     .addReg(cmpOp2, getKillRegState(MO2IsKill))
608                                     .addMBB(jmpTarget);
609
610           else if ((cmpInstr->getOpcode() == Hexagon::C2_cmpeqi ||
611                     cmpInstr->getOpcode() == Hexagon::C2_cmpgti) &&
612                     cmpOp2 == -1 )
613             // Corresponding new-value compare jump instructions don't have the
614             // operand for -1 immediate value.
615             NewMI = BuildMI(*MBB, jmpPos, dl,
616                                   QII->get(opc))
617                                     .addReg(cmpReg1, getKillRegState(MO1IsKill))
618                                     .addMBB(jmpTarget);
619
620           else
621             NewMI = BuildMI(*MBB, jmpPos, dl,
622                                   QII->get(opc))
623                                     .addReg(cmpReg1, getKillRegState(MO1IsKill))
624                                     .addImm(cmpOp2)
625                                     .addMBB(jmpTarget);
626
627           assert(NewMI && "New Value Jump Instruction Not created!");
628           (void)NewMI;
629           if (cmpInstr->getOperand(0).isReg() &&
630               cmpInstr->getOperand(0).isKill())
631             cmpInstr->getOperand(0).setIsKill(false);
632           if (cmpInstr->getOperand(1).isReg() &&
633               cmpInstr->getOperand(1).isKill())
634             cmpInstr->getOperand(1).setIsKill(false);
635           cmpInstr->eraseFromParent();
636           jmpInstr->eraseFromParent();
637           ++nvjGenerated;
638           ++NumNVJGenerated;
639           break;
640         }
641       }
642     }
643   }
644
645   return true;
646
647 }
648
649 FunctionPass *llvm::createHexagonNewValueJump() {
650   return new HexagonNewValueJump();
651 }