[llvm-commits] CVS: llvm/lib/Transforms/Scalar/InstructionCombining.cpp
Chris Lattner
lattner at cs.uiuc.edu
Sun May 8 10:35:10 PDT 2005
Changes in directory llvm/lib/Transforms/Scalar:
InstructionCombining.cpp updated: 1.341 -> 1.342
---
Log message:
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
---
Diffs of the changes: (+10 -0)
InstructionCombining.cpp | 10 ++++++++++
1 files changed, 10 insertions(+)
Index: llvm/lib/Transforms/Scalar/InstructionCombining.cpp
diff -u llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.341 llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.342
--- llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.341 Sat May 7 18:49:08 2005
+++ llvm/lib/Transforms/Scalar/InstructionCombining.cpp Sun May 8 12:34:56 2005
@@ -3136,6 +3136,16 @@
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.
More information about the llvm-commits
mailing list