[llvm-commits] [llvm] r94997 - in /llvm/trunk: lib/VMCore/ConstantFold.cpp test/Transforms/InstCombine/icmp.ll

Chris Lattner sabre at nondot.org
Mon Feb 1 12:04:40 PST 2010


Author: lattner
Date: Mon Feb  1 14:04:40 2010
New Revision: 94997

URL: http://llvm.org/viewvc/llvm-project?rev=94997&view=rev
Log:
fix PR6195, a bug constant folding scalar -> vector compares.

Modified:
    llvm/trunk/lib/VMCore/ConstantFold.cpp
    llvm/trunk/test/Transforms/InstCombine/icmp.ll

Modified: llvm/trunk/lib/VMCore/ConstantFold.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/ConstantFold.cpp?rev=94997&r1=94996&r2=94997&view=diff

==============================================================================
--- llvm/trunk/lib/VMCore/ConstantFold.cpp (original)
+++ llvm/trunk/lib/VMCore/ConstantFold.cpp Mon Feb  1 14:04:40 2010
@@ -2017,10 +2017,12 @@
       return ConstantInt::get(Type::getInt1Ty(Context), Result);
 
     // If the right hand side is a bitcast, try using its inverse to simplify
-    // it by moving it to the left hand side.
+    // it by moving it to the left hand side.  We can't do this if it would turn
+    // a vector compare into scalar compare of visa versa.
     if (ConstantExpr *CE2 = dyn_cast<ConstantExpr>(C2)) {
-      if (CE2->getOpcode() == Instruction::BitCast) {
-        Constant *CE2Op0 = CE2->getOperand(0);
+      Constant *CE2Op0 = CE2->getOperand(0);
+      if (CE2->getOpcode() == Instruction::BitCast &&
+          isa<VectorType>(CE2->getType()) ==isa<VectorType>(CE2Op0->getType())){
         Constant *Inverse = ConstantExpr::getBitCast(C1, CE2Op0->getType());
         return ConstantExpr::getICmp(pred, Inverse, CE2Op0);
       }

Modified: llvm/trunk/test/Transforms/InstCombine/icmp.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/icmp.ll?rev=94997&r1=94996&r2=94997&view=diff

==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/icmp.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/icmp.ll Mon Feb  1 14:04:40 2010
@@ -112,3 +112,12 @@
 ; CHECK: ret i1 true
 }
 
+; PR6195
+define i1 @test12(i1 %A) {
+  %S = select i1 %A, i64 -4294967295, i64 8589934591
+  %B = icmp ne i64 bitcast (<2 x i32> <i32 1, i32 -1> to i64), %S
+  ret i1 %B
+; CHECK: @test12
+; CHECK-NEXT: %B = select i1
+; CHECK-NEXT: ret i1 %B
+}





More information about the llvm-commits mailing list