aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2005-05-08 17:34:56 +0000
committerChris Lattner <sabre@nondot.org>2005-05-08 17:34:56 +0000
commit120347e8d115cf40aed10e63d406713b46f327df (patch)
treeecc3069a9f0eb1fa6d2b4cd8f64779994478c2f2
parenta9c83c73daa8eb5410ff17be9b19218245b52de2 (diff)
Strength reduce SAR into SHR if there is no way sign bits could be shifted
in. This tends to get cases like this: X = cast ubyte to int Y = shr int X, ... Tested by: shift.ll:test24 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21775 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/Transforms/Scalar/InstructionCombining.cpp10
1 files changed, 10 insertions, 0 deletions
diff --git a/lib/Transforms/Scalar/InstructionCombining.cpp b/lib/Transforms/Scalar/InstructionCombining.cpp
index 6cafc25777..40d107a810 100644
--- a/lib/Transforms/Scalar/InstructionCombining.cpp
+++ b/lib/Transforms/Scalar/InstructionCombining.cpp
@@ -3136,6 +3136,16 @@ Instruction *InstCombiner::visitShiftInst(ShiftInst &I) {
if (Instruction *R = FoldOpIntoSelect(I, SI, this))
return R;
+ // See if we can turn a signed shr into an unsigned shr.
+ if (!isLeftShift && I.getType()->isSigned()) {
+ if (MaskedValueIsZero(Op0, ConstantInt::getMinValue(I.getType()))) {
+ Value *V = InsertCastBefore(Op0, I.getType()->getUnsignedVersion(), I);
+ V = InsertNewInstBefore(new ShiftInst(Instruction::Shr, V, Op1,
+ I.getName()), I);
+ return new CastInst(V, I.getType());
+ }
+ }
+
if (ConstantUInt *CUI = dyn_cast<ConstantUInt>(Op1)) {
// shl uint X, 32 = 0 and shr ubyte Y, 9 = 0, ... just don't eliminate shr
// of a signed value.