[llvm] r185284 - ConstantFold: Check that truncating the other side is safe under a sext when trying to remove a sext from a compare.

Benjamin Kramer benny.kra at googlemail.com
Sun Jun 30 06:47:43 PDT 2013


Author: d0k
Date: Sun Jun 30 08:47:43 2013
New Revision: 185284

URL: http://llvm.org/viewvc/llvm-project?rev=185284&view=rev
Log:
ConstantFold: Check that truncating the other side is safe under a sext when trying to remove a sext from a compare.

Fixes PR16462.

Modified:
    llvm/trunk/lib/IR/ConstantFold.cpp
    llvm/trunk/test/Transforms/InstCombine/2010-03-03-ExtElim.ll

Modified: llvm/trunk/lib/IR/ConstantFold.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/ConstantFold.cpp?rev=185284&r1=185283&r2=185284&view=diff
==============================================================================
--- llvm/trunk/lib/IR/ConstantFold.cpp (original)
+++ llvm/trunk/lib/IR/ConstantFold.cpp Sun Jun 30 08:47:43 2013
@@ -1857,9 +1857,9 @@ Constant *llvm::ConstantFoldCompareInstr
         if (CE1Inverse == CE1Op0) {
           // Check whether we can safely truncate the right hand side.
           Constant *C2Inverse = ConstantExpr::getTrunc(C2, CE1Op0->getType());
-          if (ConstantExpr::getZExt(C2Inverse, C2->getType()) == C2) {
+          if (ConstantExpr::getCast(CE1->getOpcode(), C2Inverse,
+                                    C2->getType()) == C2)
             return ConstantExpr::getICmp(pred, CE1Inverse, C2Inverse);
-          }
         }
       }
     }

Modified: llvm/trunk/test/Transforms/InstCombine/2010-03-03-ExtElim.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/2010-03-03-ExtElim.ll?rev=185284&r1=185283&r2=185284&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/2010-03-03-ExtElim.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/2010-03-03-ExtElim.ll Sun Jun 30 08:47:43 2013
@@ -1,5 +1,4 @@
 ; RUN: opt -instcombine -S < %s | FileCheck %s
-; PR6486
 
 target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:32:32-n8:16:32"
 target triple = "i386-unknown-linux-gnu"
@@ -7,8 +6,8 @@ target triple = "i386-unknown-linux-gnu"
 @g_92 = common global [2 x i32*] zeroinitializer, align 4 ; <[2 x i32*]*> [#uses=1]
 @g_177 = constant i32** bitcast (i8* getelementptr (i8* bitcast ([2 x i32*]* @g_92 to i8*), i64 4) to i32**), align 4 ; <i32***> [#uses=1]
 
-define i1 @test() nounwind {
-; CHECK: @test
+define i1 @PR6486() nounwind {
+; CHECK: @PR6486
   %tmp = load i32*** @g_177                       ; <i32**> [#uses=1]
   %cmp = icmp ne i32** null, %tmp                 ; <i1> [#uses=1]
   %conv = zext i1 %cmp to i32                     ; <i32> [#uses=1]
@@ -16,3 +15,18 @@ define i1 @test() nounwind {
   ret i1 %cmp1
 ; CHECK: ret i1 true
 }
+
+ at d = common global i32 0, align 4
+ at a = common global [1 x i32] zeroinitializer, align 4
+
+define i1 @PR16462_1() nounwind {
+; CHECK: @PR16462_1
+  ret i1 icmp sgt (i32 sext (i16 trunc (i32 select (i1 icmp eq (i32* getelementptr inbounds ([1 x i32]* @a, i32 0, i32 0), i32* @d), i32 0, i32 1) to i16) to i32), i32 65535)
+; CHECK: ret i1 icmp sgt (i32 sext (i16 trunc (i32 select (i1 icmp eq (i32* getelementptr inbounds ([1 x i32]* @a, i32 0, i32 0), i32* @d), i32 0, i32 1) to i16) to i32), i32 65535)
+}
+
+define i1 @PR16462_2() nounwind {
+; CHECK: @PR16462_2
+  ret i1 icmp sgt (i32 sext (i16 trunc (i32 select (i1 icmp eq (i32* getelementptr inbounds ([1 x i32]* @a, i32 0, i32 0), i32* @d), i32 0, i32 1) to i16) to i32), i32 42)
+; CHECK: ret i1 icmp sgt (i16 trunc (i32 select (i1 icmp eq (i32* getelementptr inbounds ([1 x i32]* @a, i32 0, i32 0), i32* @d), i32 0, i32 1) to i16), i16 42)
+}





More information about the llvm-commits mailing list