[AArch64, fast-isel] Fall back to SelectionDAG to select tail calls.
[oota-llvm.git] / lib / Target / AArch64 / AArch64InstrInfo.cpp
index e9fecbf81d7fac8a57d621794fca5a6b53c18a69..df883d35fa18be09ad7ba9616a7b5b857a449e13 100644 (file)
@@ -641,7 +641,8 @@ bool AArch64InstrInfo::analyzeCompare(const MachineInstr *MI, unsigned &SrcReg,
     SrcReg = MI->getOperand(1).getReg();
     SrcReg2 = 0;
     CmpMask = ~0;
-    CmpValue = MI->getOperand(2).getImm();
+    // FIXME: In order to convert CmpValue to 0 or 1
+    CmpValue = (MI->getOperand(2).getImm() != 0);
     return true;
   case AArch64::ANDSWri:
   case AArch64::ANDSXri:
@@ -650,9 +651,14 @@ bool AArch64InstrInfo::analyzeCompare(const MachineInstr *MI, unsigned &SrcReg,
     SrcReg = MI->getOperand(1).getReg();
     SrcReg2 = 0;
     CmpMask = ~0;
-    CmpValue = AArch64_AM::decodeLogicalImmediate(
-        MI->getOperand(2).getImm(),
-        MI->getOpcode() == AArch64::ANDSWri ? 32 : 64);
+    // FIXME:The return val type of decodeLogicalImmediate is uint64_t,
+    // while the type of CmpValue is int. When converting uint64_t to int,
+    // the high 32 bits of uint64_t will be lost.
+    // In fact it causes a bug in spec2006-483.xalancbmk
+    // CmpValue is only used to compare with zero in OptimizeCompareInstr
+    CmpValue = (AArch64_AM::decodeLogicalImmediate(
+                    MI->getOperand(2).getImm(),
+                    MI->getOpcode() == AArch64::ANDSWri ? 32 : 64) != 0);
     return true;
   }
 
@@ -749,6 +755,9 @@ bool AArch64InstrInfo::optimizeCompareInstr(
   }
 
   // Continue only if we have a "ri" where immediate is zero.
+  // FIXME:CmpValue has already been converted to 0 or 1 in analyzeCompare
+  // function.
+  assert((CmpValue == 0 || CmpValue == 1) && "CmpValue must be 0 or 1!");
   if (CmpValue != 0 || SrcReg2 != 0)
     return false;
 
@@ -2409,7 +2418,7 @@ bool AArch64InstrInfo::hasPattern(
 ///  ADD R,I,C
 ///  ==> MADD R,A,B,C
 /// \param Root is the ADD instruction
-/// \param [out] InsInstr is a vector of machine instructions and will
+/// \param [out] InsInstrs is a vector of machine instructions and will
 /// contain the generated madd instruction
 /// \param IdxMulOpd is index of operand in Root that is the result of
 /// the MUL. In the example above IdxMulOpd is 1.
@@ -2444,7 +2453,7 @@ static MachineInstr *genMadd(MachineFunction &MF, MachineRegisterInfo &MRI,
 ///   ==> ORR  V, ZR, Imm
 ///   ==> MADD R,A,B,V
 /// \param Root is the ADD instruction
-/// \param [out] InsInstr is a vector of machine instructions and will
+/// \param [out] InsInstrs is a vector of machine instructions and will
 /// contain the generated madd instruction
 /// \param IdxMulOpd is index of operand in Root that is the result of
 /// the MUL. In the example above IdxMulOpd is 1.
@@ -2545,7 +2554,7 @@ void AArch64InstrInfo::genAlternativeCodeSequence(
       if (AArch64_AM::processLogicalImmediate(UImm, BitSize, Encoding)) {
         MachineInstrBuilder MIB1 =
             BuildMI(MF, Root.getDebugLoc(), TII->get(OrrOpc))
-                .addOperand(MachineOperand::CreateReg(NewVR, RegState::Define))
+                .addOperand(MachineOperand::CreateReg(NewVR, true))
                 .addReg(ZeroReg)
                 .addImm(Encoding);
         InsInstrs.push_back(MIB1);
@@ -2577,7 +2586,7 @@ void AArch64InstrInfo::genAlternativeCodeSequence(
     // SUB NewVR, 0, C
     MachineInstrBuilder MIB1 =
         BuildMI(MF, Root.getDebugLoc(), TII->get(SubOpc))
-            .addOperand(MachineOperand::CreateReg(NewVR, RegState::Define))
+            .addOperand(MachineOperand::CreateReg(NewVR, true))
             .addReg(ZeroReg)
             .addOperand(Root.getOperand(2));
     InsInstrs.push_back(MIB1);
@@ -2626,7 +2635,7 @@ void AArch64InstrInfo::genAlternativeCodeSequence(
     if (AArch64_AM::processLogicalImmediate(UImm, BitSize, Encoding)) {
       MachineInstrBuilder MIB1 =
           BuildMI(MF, Root.getDebugLoc(), TII->get(OrrOpc))
-              .addOperand(MachineOperand::CreateReg(NewVR, RegState::Define))
+              .addOperand(MachineOperand::CreateReg(NewVR, true))
               .addReg(ZeroReg)
               .addImm(Encoding);
       InsInstrs.push_back(MIB1);