Skip to content

Commit

Permalink
[InstCombine] fix formatting and add FIXMEs to foldOperationIntoSelec…
Browse files Browse the repository at this point in the history
…tOperand(); NFC

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@287145 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
rotateright committed Nov 16, 2016
1 parent 42fcf0e commit 1c3c35e
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions lib/Transforms/InstCombine/InstructionCombining.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -761,20 +760,25 @@ 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);
return RI;
}
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!");
}

Expand Down Expand Up @@ -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);
}

Expand Down

0 comments on commit 1c3c35e

Please sign in to comment.