diff options
author | Devang Patel <dpatel@apple.com> | 2006-10-19 20:59:13 +0000 |
---|---|---|
committer | Devang Patel <dpatel@apple.com> | 2006-10-19 20:59:13 +0000 |
commit | 002e499650ee97df34dd53f1a6806860132a256c (patch) | |
tree | c1c32c2e264b34ef50e9233ba8511c739a5db950 | |
parent | df308fa7aba36d9c7ca29abe24489adbcdfff697 (diff) |
It is OK to remove extra cast if operation is EQ/NE even though source
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
-rw-r--r-- | lib/Transforms/Scalar/InstructionCombining.cpp | 5 | ||||
-rw-r--r-- | test/Transforms/InstCombine/2006-10-19-SignedToUnsignedCastAndConst-2.ll | 9 |
2 files changed, 12 insertions, 2 deletions
diff --git a/lib/Transforms/Scalar/InstructionCombining.cpp b/lib/Transforms/Scalar/InstructionCombining.cpp index 7e75dcab1d..97b7cebbb6 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 0000000000..c10e62db8e --- /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 + } + |