aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/IR/ConstantFold.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/lib/IR/ConstantFold.cpp')
-rw-r--r--llvm/lib/IR/ConstantFold.cpp32
1 files changed, 8 insertions, 24 deletions
diff --git a/llvm/lib/IR/ConstantFold.cpp b/llvm/lib/IR/ConstantFold.cpp
index 05ab096..a6f46da 100644
--- a/llvm/lib/IR/ConstantFold.cpp
+++ b/llvm/lib/IR/ConstantFold.cpp
@@ -731,11 +731,11 @@ Constant *llvm::ConstantFoldBinaryInstruction(unsigned Opcode, Constant *C1,
// Handle simplifications when the RHS is a constant int.
if (ConstantInt *CI2 = dyn_cast<ConstantInt>(C2)) {
+ if (C2 == ConstantExpr::getBinOpAbsorber(Opcode, C2->getType(),
+ /*AllowLHSConstant*/ false))
+ return C2;
+
switch (Opcode) {
- case Instruction::Mul:
- if (CI2->isZero())
- return C2; // X * 0 == 0
- break;
case Instruction::UDiv:
case Instruction::SDiv:
if (CI2->isZero())
@@ -749,9 +749,7 @@ Constant *llvm::ConstantFoldBinaryInstruction(unsigned Opcode, Constant *C1,
return PoisonValue::get(CI2->getType()); // X % 0 == poison
break;
case Instruction::And:
- if (CI2->isZero())
- return C2; // X & 0 == 0
-
+ assert(!CI2->isZero() && "And zero handled above");
if (ConstantExpr *CE1 = dyn_cast<ConstantExpr>(C1)) {
// If and'ing the address of a global with a constant, fold it.
if (CE1->getOpcode() == Instruction::PtrToInt &&
@@ -791,10 +789,6 @@ Constant *llvm::ConstantFoldBinaryInstruction(unsigned Opcode, Constant *C1,
}
}
break;
- case Instruction::Or:
- if (CI2->isMinusOne())
- return C2; // X | -1 == -1
- break;
}
} else if (isa<ConstantInt>(C1)) {
// If C1 is a ConstantInt and C2 is not, swap the operands.
@@ -854,19 +848,9 @@ Constant *llvm::ConstantFoldBinaryInstruction(unsigned Opcode, Constant *C1,
}
}
- switch (Opcode) {
- case Instruction::SDiv:
- case Instruction::UDiv:
- case Instruction::URem:
- case Instruction::SRem:
- case Instruction::LShr:
- case Instruction::AShr:
- case Instruction::Shl:
- if (CI1->isZero()) return C1;
- break;
- default:
- break;
- }
+ if (C1 == ConstantExpr::getBinOpAbsorber(Opcode, C1->getType(),
+ /*AllowLHSConstant*/ true))
+ return C1;
} else if (ConstantFP *CFP1 = dyn_cast<ConstantFP>(C1)) {
if (ConstantFP *CFP2 = dyn_cast<ConstantFP>(C2)) {
const APFloat &C1V = CFP1->getValueAPF();