[llvm-commits] CVS: llvm/lib/Transforms/Scalar/InstructionCombining.cpp
Chris Lattner
lattner at cs.uiuc.edu
Tue Sep 28 10:54:21 PDT 2004
Changes in directory llvm/lib/Transforms/Scalar:
InstructionCombining.cpp updated: 1.251 -> 1.252
---
Log message:
shl is always zero extending, so always use a zero extending shift right.
This latent bug was exposed by recent changes, and is tested as:
llvm/test/Regression/Transforms/InstCombine/2004-09-28-BadShiftAndSetCC.llx
---
Diffs of the changes: (+12 -5)
Index: llvm/lib/Transforms/Scalar/InstructionCombining.cpp
diff -u llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.251 llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.252
--- llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.251 Mon Sep 27 14:29:18 2004
+++ llvm/lib/Transforms/Scalar/InstructionCombining.cpp Tue Sep 28 12:54:07 2004
@@ -1506,7 +1506,7 @@
// rights, as they sign-extend.
if (ShAmt) {
bool CanFold = Shift->getOpcode() != Instruction::Shr ||
- Shift->getType()->isUnsigned();
+ Shift->getType()->isUnsigned();
if (!CanFold) {
// To test for the bad case of the signed shr, see if any
// of the bits shifted in could be tested after the mask.
@@ -1519,9 +1519,11 @@
}
if (CanFold) {
- unsigned ShiftOp = Shift->getOpcode() == Instruction::Shl
- ? Instruction::Shr : Instruction::Shl;
- Constant *NewCst = ConstantExpr::get(ShiftOp, CI, ShAmt);
+ Constant *NewCst;
+ if (Shift->getOpcode() == Instruction::Shl)
+ NewCst = ConstantExpr::getUShr(CI, ShAmt);
+ else
+ NewCst = ConstantExpr::getShl(CI, ShAmt);
// Check to see if we are shifting out any of the bits being
// compared.
@@ -1535,7 +1537,12 @@
return ReplaceInstUsesWith(I, ConstantBool::True);
} else {
I.setOperand(1, NewCst);
- LHSI->setOperand(1, ConstantExpr::get(ShiftOp, AndCST,ShAmt));
+ Constant *NewAndCST;
+ if (Shift->getOpcode() == Instruction::Shl)
+ NewAndCST = ConstantExpr::getUShr(AndCST, ShAmt);
+ else
+ NewAndCST = ConstantExpr::getShl(AndCST, ShAmt);
+ LHSI->setOperand(1, NewAndCST);
LHSI->setOperand(0, Shift->getOperand(0));
WorkList.push_back(Shift); // Shift is dead.
AddUsesToWorkList(I);
More information about the llvm-commits
mailing list