summaryrefslogtreecommitdiff
path: root/lib/Transforms
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2005-04-08 04:03:26 +0000
committerChris Lattner <sabre@nondot.org>2005-04-08 04:03:26 +0000
commitbf70b838e77875d7ca039456f1ac300e1f0bc897 (patch)
treef8a1cb6b74f8e0a92a8562de7afcee222ccd5d90 /lib/Transforms
parentb37246d65ec28bfa6d6356ae931f0998ba98a246 (diff)
Fix bug: InstCombine/2005-05-07-UDivSelectCrash.ll
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21152 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms')
-rw-r--r--lib/Transforms/Scalar/InstructionCombining.cpp30
1 files changed, 16 insertions, 14 deletions
diff --git a/lib/Transforms/Scalar/InstructionCombining.cpp b/lib/Transforms/Scalar/InstructionCombining.cpp
index 2a54366728a..b2609fe38bc 100644
--- a/lib/Transforms/Scalar/InstructionCombining.cpp
+++ b/lib/Transforms/Scalar/InstructionCombining.cpp
@@ -1068,23 +1068,25 @@ Instruction *InstCombiner::visitDiv(BinaryOperator &I) {
I.setOperand(1, SFO);
return &I;
} else if (SFO->getValue() == 0) {
- I.setOperand(1, STO);
+ I.setOperand(2, STO);
return &I;
}
- if (uint64_t TSA = Log2(STO->getValue()))
- if (uint64_t FSA = Log2(SFO->getValue())) {
- Constant *TC = ConstantUInt::get(Type::UByteTy, TSA);
- Instruction *TSI = new ShiftInst(Instruction::Shr, Op0,
- TC, SI->getName()+".t");
- TSI = InsertNewInstBefore(TSI, I);
-
- Constant *FC = ConstantUInt::get(Type::UByteTy, FSA);
- Instruction *FSI = new ShiftInst(Instruction::Shr, Op0,
- FC, SI->getName()+".f");
- FSI = InsertNewInstBefore(FSI, I);
- return new SelectInst(SI->getOperand(0), TSI, FSI);
- }
+ uint64_t TVA = STO->getValue(), FVA = SFO->getValue();
+ unsigned TSA = 0, FSA = 0;
+ if ((TVA == 1 || (TSA = Log2(TVA))) && // Log2 fails for 0 & 1.
+ (FVA == 1 || (FSA = Log2(FVA)))) {
+ Constant *TC = ConstantUInt::get(Type::UByteTy, TSA);
+ Instruction *TSI = new ShiftInst(Instruction::Shr, Op0,
+ TC, SI->getName()+".t");
+ TSI = InsertNewInstBefore(TSI, I);
+
+ Constant *FC = ConstantUInt::get(Type::UByteTy, FSA);
+ Instruction *FSI = new ShiftInst(Instruction::Shr, Op0,
+ FC, SI->getName()+".f");
+ FSI = InsertNewInstBefore(FSI, I);
+ return new SelectInst(SI->getOperand(0), TSI, FSI);
+ }
}
// 0 / X == 0, we don't need to preserve faults!