[llvm-commits] CVS: llvm/lib/Transforms/Scalar/InstructionCombining.cpp
Chris Lattner
lattner at cs.uiuc.edu
Wed Jun 15 13:53:42 PDT 2005
Changes in directory llvm/lib/Transforms/Scalar:
InstructionCombining.cpp updated: 1.348 -> 1.349
---
Log message:
Fix PR577: http://llvm.cs.uiuc.edu/PR577 and testcase InstCombine/2005-06-15-ShiftSetCCCrash.ll.
Do not perform undefined out of range shifts.
---
Diffs of the changes: (+16 -2)
InstructionCombining.cpp | 18 ++++++++++++++++--
1 files changed, 16 insertions(+), 2 deletions(-)
Index: llvm/lib/Transforms/Scalar/InstructionCombining.cpp
diff -u llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.348 llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.349
--- llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.348 Wed Jun 15 13:25:30 2005
+++ llvm/lib/Transforms/Scalar/InstructionCombining.cpp Wed Jun 15 15:53:31 2005
@@ -2560,6 +2560,14 @@
default: break;
case Instruction::SetEQ:
case Instruction::SetNE: {
+ unsigned TypeBits = CI->getType()->getPrimitiveSizeInBits();
+
+ // Check that the shift amount is in range. If not, don't perform
+ // undefined shifts. When the shift is visited it will be
+ // simplified.
+ if (ShAmt->getValue() >= TypeBits)
+ break;
+
// If we are comparing against bits always shifted out, the
// comparison cannot succeed.
Constant *Comp =
@@ -2573,7 +2581,6 @@
if (LHSI->hasOneUse()) {
// Otherwise strength reduce the shift into an and.
unsigned ShAmtVal = (unsigned)ShAmt->getValue();
- unsigned TypeBits = CI->getType()->getPrimitiveSizeInBits();
uint64_t Val = (1ULL << (TypeBits-ShAmtVal))-1;
Constant *Mask;
@@ -2603,6 +2610,14 @@
default: break;
case Instruction::SetEQ:
case Instruction::SetNE: {
+
+ // Check that the shift amount is in range. If not, don't perform
+ // undefined shifts. When the shift is visited it will be
+ // simplified.
+ unsigned TypeBits = ShAmt->getType()->getPrimitiveSizeInBits();
+ if (ShAmt->getValue() >= TypeBits)
+ break;
+
// If we are comparing against bits always shifted out, the
// comparison cannot succeed.
Constant *Comp =
@@ -2623,7 +2638,6 @@
Constant *Mask;
if (CI->getType()->isUnsigned()) {
- unsigned TypeBits = CI->getType()->getPrimitiveSizeInBits();
Val &= ~0ULL >> (64-TypeBits);
Mask = ConstantUInt::get(CI->getType(), Val);
} else {
More information about the llvm-commits
mailing list