[llvm-commits] [SignlessTypes] CVS: llvm/lib/Transforms/Scalar/InstructionCombining.cpp
Reid Spencer
reid at x10sys.com
Sun Oct 22 16:27:36 PDT 2006
Changes in directory llvm/lib/Transforms/Scalar:
InstructionCombining.cpp updated: 1.520.2.7 -> 1.520.2.8
---
Log message:
Don't try to replicate integer transforms/folding for floating point values.
Its not valid!
---
Diffs of the changes: (+4 -36)
InstructionCombining.cpp | 40 ++++------------------------------------
1 files changed, 4 insertions(+), 36 deletions(-)
Index: llvm/lib/Transforms/Scalar/InstructionCombining.cpp
diff -u llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.520.2.7 llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.520.2.8
--- llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.520.2.7 Sun Oct 22 03:59:00 2006
+++ llvm/lib/Transforms/Scalar/InstructionCombining.cpp Sun Oct 22 18:27:20 2006
@@ -1983,7 +1983,7 @@
// 0 - (X sdiv C) -> (X sdiv -C)
if (Op1I->getOpcode() == Instruction::SDiv)
if (ConstantInt *CSI = dyn_cast<ConstantInt>(Op0))
- if (CSI->isNullValue() && CSI->getType()->isSigned())
+ if (CSI->getType()->isSigned() && CSI->isNullValue())
if (Constant *DivRHS = dyn_cast<Constant>(Op1I->getOperand(1)))
return BinaryOperator::createSDiv(Op1I->getOperand(0),
ConstantExpr::getNeg(DivRHS));
@@ -2356,39 +2356,6 @@
if (common)
return common;
- // If right hand side is a constant floating point ...
- if (ConstantFP *RHS = dyn_cast<ConstantFP>(Op1)) {
- // div X, 1 == X
- if (RHS->isExactlyValue(1.0))
- return ReplaceInstUsesWith(I, Op0);
-
- // div X, -1 == -X
- if (RHS->isExactlyValue(-1.0))
- return BinaryOperator::createNeg(Op0);
-
- // (X / C1) / C2 -> X / (C1*C2)
- if (Instruction *LHS = dyn_cast<Instruction>(Op0))
- if (LHS->getOpcode()==Instruction::FDiv)
- if (ConstantFP *LHSRHS = dyn_cast<ConstantFP>(LHS->getOperand(1))) {
- return BinaryOperator::create(Instruction::FDiv, LHS->getOperand(0),
- ConstantExpr::getMul(RHS, LHSRHS));
- }
-
- if (!RHS->isNullValue()) { // avoid X fdiv 0
- if (SelectInst *SI = dyn_cast<SelectInst>(Op0))
- if (Instruction *R = FoldOpIntoSelect(I, SI, this))
- return R;
- if (isa<PHINode>(Op0))
- if (Instruction *NV = FoldOpIntoPhi(I))
- return NV;
- }
- }
-
- // 0 / X == 0
- if (ConstantFP *LHS = dyn_cast<ConstantFP>(Op0))
- if (LHS->isExactlyValue(0))
- return ReplaceInstUsesWith(I, Constant::getNullValue(I.getType()));
-
// Handle div X, Cond?Y:Z
if (SelectInst *SI = dyn_cast<SelectInst>(Op1)) {
// div X, (Cond ? 0 : Y) -> div X, Y. If the div and the select are in the
@@ -3838,7 +3805,9 @@
static bool MulWithOverflow(ConstantInt *&Result, ConstantInt *In1,
ConstantInt *In2) {
Result = cast<ConstantInt>(ConstantExpr::getMul(In1, In2));
- return !In2->isNullValue() && ConstantExpr::getSDiv(Result, In2) != In1;
+ return !In2->isNullValue() && (In2->getType()->isSigned() ?
+ ConstantExpr::getSDiv(Result, In2) :
+ ConstantExpr::getUDiv(Result, In2)) != In1;
}
static bool isPositive(ConstantInt *C) {
@@ -4497,7 +4466,6 @@
case Instruction::SDiv:
case Instruction::UDiv:
- case Instruction::FDiv:
// Fold: (div X, C1) op C2 -> range check
if (ConstantInt *DivRHS = dyn_cast<ConstantInt>(LHSI->getOperand(1))) {
// Fold this div into the comparison, producing a range check.
More information about the llvm-commits
mailing list