summaryrefslogtreecommitdiffstats
path: root/llvm/lib
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/lib')
-rw-r--r--llvm/lib/IR/ConstantFold.cpp18
1 files changed, 16 insertions, 2 deletions
diff --git a/llvm/lib/IR/ConstantFold.cpp b/llvm/lib/IR/ConstantFold.cpp
index f675fc136bd..62a7f2e40b6 100644
--- a/llvm/lib/IR/ConstantFold.cpp
+++ b/llvm/lib/IR/ConstantFold.cpp
@@ -916,9 +916,11 @@ Constant *llvm::ConstantFoldInsertValueInstruction(Constant *Agg,
Constant *llvm::ConstantFoldBinaryInstruction(unsigned Opcode,
Constant *C1, Constant *C2) {
+ assert(Instruction::isBinaryOp(Opcode) && "Non-binary instruction detected");
+
// Handle UndefValue up front.
if (isa<UndefValue>(C1) || isa<UndefValue>(C2)) {
- switch (Opcode) {
+ switch (static_cast<Instruction::BinaryOps>(Opcode)) {
case Instruction::Xor:
if (isa<UndefValue>(C1) && isa<UndefValue>(C2))
// Handle undef ^ undef -> 0 special case. This is a common
@@ -998,9 +1000,22 @@ Constant *llvm::ConstantFoldBinaryInstruction(unsigned Opcode,
return C1;
// undef << X -> 0
return Constant::getNullValue(C1->getType());
+ case Instruction::FAdd:
+ case Instruction::FSub:
+ case Instruction::FMul:
+ case Instruction::FDiv:
+ case Instruction::FRem:
+ // TODO: UNDEF handling for binary float instructions.
+ return nullptr;
+ case Instruction::BinaryOpsEnd:
+ llvm_unreachable("Invalid BinaryOp");
}
}
+ // At this point neither constant should be an UndefValue.
+ assert(!isa<UndefValue>(C1) && !isa<UndefValue>(C2) &&
+ "Unexpected UndefValue");
+
// Handle simplifications when the RHS is a constant int.
if (ConstantInt *CI2 = dyn_cast<ConstantInt>(C2)) {
switch (Opcode) {
@@ -1102,7 +1117,6 @@ Constant *llvm::ConstantFoldBinaryInstruction(unsigned Opcode,
return ConstantExpr::get(Opcode, C2, C1);
}
- // At this point we know neither constant is an UndefValue.
if (ConstantInt *CI1 = dyn_cast<ConstantInt>(C1)) {
if (ConstantInt *CI2 = dyn_cast<ConstantInt>(C2)) {
const APInt &C1V = CI1->getValue();
OpenPOWER on IntegriCloud