For immediate encodings of icmp, zero or sign extend first. Then
authorChad Rosier <mcrosier@apple.com>
Thu, 10 Nov 2011 01:30:39 +0000 (01:30 +0000)
committerChad Rosier <mcrosier@apple.com>
Thu, 10 Nov 2011 01:30:39 +0000 (01:30 +0000)
determine if the value is negative and flip the sign accordingly.
rdar://10422026

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@144258 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Target/ARM/ARMFastISel.cpp
test/CodeGen/ARM/fast-isel-cmp-imm.ll

index 44c88aa7fd7ea8319bcbe18bd38f674c14264e04..4c47ff9cdfb43c42a6809b9c861cb32decaaf366 100644 (file)
@@ -1216,7 +1216,6 @@ bool ARMFastISel::ARMEmitCmp(const Value *Src1Value, const Value *Src2Value,
 
   // Check to see if the 2nd operand is a constant that we can encode directly
   // in the compare.
-  uint64_t Imm;
   int EncodedImm = 0;
   bool EncodeImm = false;
   bool isNegativeImm = false;
@@ -1224,10 +1223,11 @@ bool ARMFastISel::ARMEmitCmp(const Value *Src1Value, const Value *Src2Value,
     if (SrcVT == MVT::i32 || SrcVT == MVT::i16 || SrcVT == MVT::i8 ||
         SrcVT == MVT::i1) {
       const APInt &CIVal = ConstInt->getValue();
-
-      isNegativeImm = CIVal.isNegative();
-      Imm = (isNegativeImm) ? (-CIVal).getZExtValue() : CIVal.getZExtValue();
-      EncodedImm = (int)Imm;
+      EncodedImm = (isZExt) ? (int)CIVal.getZExtValue() : (int)CIVal.getSExtValue();
+      if (EncodedImm < 0) {
+        isNegativeImm = true;
+        EncodedImm = -EncodedImm;
+      }
       EncodeImm = isThumb2 ? (ARM_AM::getT2SOImmVal(EncodedImm) != -1) :
         (ARM_AM::getSOImmVal(EncodedImm) != -1);
     }
index 220dadd88bc8c9d22620b2a6bc7bd09cf921c9a0..b1bf63f816612f9d1038027a6868a18e49878ccb 100644 (file)
@@ -212,3 +212,20 @@ if.then:                                          ; preds = %entry
 if.end:                                           ; preds = %if.then, %entry
   ret void
 }
+
+define void @t12(i8 %a) uwtable ssp {
+entry:
+; ARM: t12
+; THUMB: t12
+  %cmp = icmp ugt i8 %a, -113
+; ARM: cmp r{{[0-9]}}, #143
+; THUMB: cmp r{{[0-9]}}, #143
+  br i1 %cmp, label %if.then, label %if.end
+
+if.then:                                          ; preds = %entry
+  tail call void @foo()
+  br label %if.end
+
+if.end:                                           ; preds = %if.then, %entry
+  ret void
+}