Make the ptrtoint comparison simplification work if one side is a global.
authorEli Friedman <eli.friedman@gmail.com>
Thu, 17 Dec 2009 21:27:47 +0000 (21:27 +0000)
committerEli Friedman <eli.friedman@gmail.com>
Thu, 17 Dec 2009 21:27:47 +0000 (21:27 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@91624 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/Scalar/InstructionCombining.cpp
test/Transforms/InstCombine/cast_ptr.ll

index c7359c4de762f1da2aa925dd464c3d030e858dcb..2c73e7ae0fe87360726ca02316e2d1c73bf79bb2 100644 (file)
@@ -6452,7 +6452,7 @@ Instruction *InstCombiner::visitICmpInst(ICmpInst &I) {
     //   if (X) ...
     // For generality, we handle any zero-extension of any operand comparison
     // with a constant or another cast from the same type.
-    if (isa<ConstantInt>(Op1) || isa<CastInst>(Op1))
+    if (isa<Constant>(Op1) || isa<CastInst>(Op1))
       if (Instruction *R = visitICmpInstWithCastAndCast(I))
         return R;
   }
index 6544e7d735a44d1bef7b8cd57f4f32effc6cee0a..6a00e83978482bd705dd7484ebb2b1e24b92a9ab 100644 (file)
@@ -27,3 +27,12 @@ define i1 @test2(i8* %a, i8* %b) {
         ret i1 %r
 }
 
+; These casts should also be folded away.
+; CHECK: @test3
+; CHECK: icmp eq i8* %a, @global
+@global = global i8 0
+define i1 @test3(i8* %a) {
+        %tmpa = ptrtoint i8* %a to i32
+        %r = icmp eq i32 %tmpa, ptrtoint (i8* @global to i32)
+        ret i1 %r
+}