aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/Transforms/Scalar/InstructionCombining.cpp5
-rw-r--r--test/Transforms/InstCombine/2006-10-19-SignedToUnsignedCastAndConst-2.ll9
2 files changed, 12 insertions, 2 deletions
diff --git a/lib/Transforms/Scalar/InstructionCombining.cpp b/lib/Transforms/Scalar/InstructionCombining.cpp
index 7e75dca..97b7ceb 100644
--- a/lib/Transforms/Scalar/InstructionCombining.cpp
+++ b/lib/Transforms/Scalar/InstructionCombining.cpp
@@ -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
index 0000000..c10e62d
--- /dev/null
+++ b/test/Transforms/InstCombine/2006-10-19-SignedToUnsignedCastAndConst-2.ll
@@ -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
+ }
+