diff options
-rw-r--r-- | llvm/lib/Transforms/InstCombine/InstructionCombining.cpp | 26 |
1 files changed, 15 insertions, 11 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp index 43b4eb5302a..a7d49875d96 100644 --- a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp +++ b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp @@ -741,17 +741,16 @@ Value *InstCombiner::dyn_castFNegVal(Value *V, bool IgnoreZeroSign) const { return nullptr; } -static Value *FoldOperationIntoSelectOperand(Instruction &I, Value *SO, +static Value *foldOperationIntoSelectOperand(Instruction &I, Value *SO, InstCombiner *IC) { - if (CastInst *CI = dyn_cast<CastInst>(&I)) { - return IC->Builder->CreateCast(CI->getOpcode(), SO, I.getType()); - } + if (auto *Cast = dyn_cast<CastInst>(&I)) + return IC->Builder->CreateCast(Cast->getOpcode(), SO, I.getType()); // 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)); - if (Constant *SOC = dyn_cast<Constant>(SO)) { + if (auto *SOC = dyn_cast<Constant>(SO)) { if (ConstIsRHS) return ConstantExpr::get(I.getOpcode(), SOC, ConstOperand); return ConstantExpr::get(I.getOpcode(), ConstOperand, SOC); @@ -761,9 +760,9 @@ static Value *FoldOperationIntoSelectOperand(Instruction &I, Value *SO, if (!ConstIsRHS) std::swap(Op0, Op1); - if (BinaryOperator *BO = dyn_cast<BinaryOperator>(&I)) { + if (auto *BO = dyn_cast<BinaryOperator>(&I)) { Value *RI = IC->Builder->CreateBinOp(BO->getOpcode(), Op0, Op1, - SO->getName()+".op"); + SO->getName() + ".op"); Instruction *FPInst = dyn_cast<Instruction>(RI); if (FPInst && isa<FPMathOperator>(FPInst)) FPInst->copyFastMathFlags(BO); @@ -771,10 +770,15 @@ static Value *FoldOperationIntoSelectOperand(Instruction &I, Value *SO, } if (ICmpInst *CI = dyn_cast<ICmpInst>(&I)) return IC->Builder->CreateICmp(CI->getPredicate(), Op0, Op1, - SO->getName()+".cmp"); + 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"); + SO->getName() + ".cmp"); + + // FIXME: Change this to an assert above. llvm_unreachable("Unknown binary instruction type!"); } @@ -827,8 +831,8 @@ Instruction *InstCombiner::FoldOpIntoSelect(Instruction &Op, SelectInst *SI) { } } - Value *SelectTVal = FoldOperationIntoSelectOperand(Op, TV, this); - Value *SelectFVal = FoldOperationIntoSelectOperand(Op, FV, this); + Value *SelectTVal = foldOperationIntoSelectOperand(Op, TV, this); + Value *SelectFVal = foldOperationIntoSelectOperand(Op, FV, this); return SelectInst::Create(SI->getCondition(), SelectTVal, SelectFVal); } |