[llvm] r287147 - [InstCombine] replace unreachable with assert and remove unreachable code; NFCI
Sanjay Patel via llvm-commits
llvm-commits at lists.llvm.org
Wed Nov 16 12:40:02 PST 2016
Author: spatel
Date: Wed Nov 16 14:40:02 2016
New Revision: 287147
URL: http://llvm.org/viewvc/llvm-project?rev=287147&view=rev
Log:
[InstCombine] replace unreachable with assert and remove unreachable code; NFCI
Modified:
llvm/trunk/lib/Transforms/InstCombine/InstructionCombining.cpp
Modified: llvm/trunk/lib/Transforms/InstCombine/InstructionCombining.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstructionCombining.cpp?rev=287147&r1=287146&r2=287147&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstructionCombining.cpp (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstructionCombining.cpp Wed Nov 16 14:40:02 2016
@@ -746,6 +746,8 @@ static Value *foldOperationIntoSelectOpe
if (auto *Cast = dyn_cast<CastInst>(&I))
return IC->Builder->CreateCast(Cast->getOpcode(), SO, I.getType());
+ assert(I.isBinaryOp() && "Unexpected opcode for select folding");
+
// Figure out if the constant is the left or the right argument.
bool ConstIsRHS = isa<Constant>(I.getOperand(1));
Constant *ConstOperand = cast<Constant>(I.getOperand(ConstIsRHS));
@@ -760,26 +762,13 @@ static Value *foldOperationIntoSelectOpe
if (!ConstIsRHS)
std::swap(Op0, Op1);
- if (auto *BO = dyn_cast<BinaryOperator>(&I)) {
- Value *RI = IC->Builder->CreateBinOp(BO->getOpcode(), Op0, Op1,
- SO->getName() + ".op");
- Instruction *FPInst = dyn_cast<Instruction>(RI);
- if (FPInst && isa<FPMathOperator>(FPInst))
- FPInst->copyFastMathFlags(BO);
- return RI;
- }
- if (ICmpInst *CI = dyn_cast<ICmpInst>(&I))
- return IC->Builder->CreateICmp(CI->getPredicate(), Op0, Op1,
- SO->getName() + ".cmp");
- // FIXME: This must already be unreachable - we would assert trying to create
- // an ICmp from an FCmp predicate. It's likely that the ICmp check above this
- // is also unreachable.
- if (FCmpInst *CI = dyn_cast<FCmpInst>(&I))
- return IC->Builder->CreateICmp(CI->getPredicate(), Op0, Op1,
- SO->getName() + ".cmp");
-
- // FIXME: Change this to an assert above.
- llvm_unreachable("Unknown binary instruction type!");
+ auto *BO = cast<BinaryOperator>(&I);
+ Value *RI = IC->Builder->CreateBinOp(BO->getOpcode(), Op0, Op1,
+ SO->getName() + ".op");
+ auto *FPInst = dyn_cast<Instruction>(RI);
+ if (FPInst && isa<FPMathOperator>(FPInst))
+ FPInst->copyFastMathFlags(BO);
+ return RI;
}
/// Given an instruction with a select as one operand and a constant as the
More information about the llvm-commits
mailing list