[llvm] r263994 - [InstCombine] Ensure all undef operands are handled before binary instruction constant folding
Simon Pilgrim via llvm-commits
llvm-commits at lists.llvm.org
Mon Mar 21 15:15:50 PDT 2016
Author: rksimon
Date: Mon Mar 21 17:15:50 2016
New Revision: 263994
URL: http://llvm.org/viewvc/llvm-project?rev=263994&view=rev
Log:
[InstCombine] Ensure all undef operands are handled before binary instruction constant folding
As noted in PR18355, this patch makes it clear that all cases with undef operands have been handled before further constant folding is attempted.
Differential Revision: http://reviews.llvm.org/D18305
Modified:
llvm/trunk/lib/IR/ConstantFold.cpp
Modified: llvm/trunk/lib/IR/ConstantFold.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/ConstantFold.cpp?rev=263994&r1=263993&r2=263994&view=diff
==============================================================================
--- llvm/trunk/lib/IR/ConstantFold.cpp (original)
+++ llvm/trunk/lib/IR/ConstantFold.cpp Mon Mar 21 17:15:50 2016
@@ -916,9 +916,11 @@ Constant *llvm::ConstantFoldInsertValueI
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::ConstantFoldBinaryInstru
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::ConstantFoldBinaryInstru
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();
More information about the llvm-commits
mailing list