It is OK to remove extra cast if operation is EQ/NE even though source
authorDevang Patel <dpatel@apple.com>
Thu, 19 Oct 2006 20:59:13 +0000 (20:59 +0000)
committerDevang Patel <dpatel@apple.com>
Thu, 19 Oct 2006 20:59:13 +0000 (20:59 +0000)
and destination sign may not match but other conditions are met.

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

lib/Transforms/Scalar/InstructionCombining.cpp
test/Transforms/InstCombine/2006-10-19-SignedToUnsignedCastAndConst-2.ll [new file with mode: 0644]

index 7e75dcab1df5903a1a4b31bfa3d51618c25d1377..97b7cebbb682c4a88a765d52563fa8d1c287680d 100644 (file)
@@ -4795,8 +4795,9 @@ Instruction *InstCombiner::visitSetCondInstWithCastAndCast(SetCondInst &SCI) {
       // %B = setgt short %X, 1330 
       // 
       // because %A may have negative value. 
-      // However, it is OK if SrcTy is bool. See cast-set.ll testcase.
-      if (isSignSrc == isSignDest || SrcTy == Type::BoolTy)
+      // However, it is OK if SrcTy is bool (See cast-set.ll testcase)
+      // OR operation is EQ/NE.
+      if (isSignSrc == isSignDest || SrcTy == Type::BoolTy || SCI.isEquality())
         RHSCIOp = Res;
       else
         return 0;
diff --git a/test/Transforms/InstCombine/2006-10-19-SignedToUnsignedCastAndConst-2.ll b/test/Transforms/InstCombine/2006-10-19-SignedToUnsignedCastAndConst-2.ll
new file mode 100644 (file)
index 0000000..c10e62d
--- /dev/null
@@ -0,0 +1,9 @@
+; The optimizer should be able to remove cast operation here.
+; RUN: llvm-as %s -o - | opt -instcombine | llvm-dis | not grep 'cast.*int'
+
+bool %eq_signed_to_small_unsigned(sbyte %SB) {
+   %Y = cast sbyte %SB to uint         ; <uint> [#uses=1]
+   %C = seteq uint %Y, 17              ; <bool> [#uses=1]
+   ret bool %C
+ }
+