diff options
-rw-r--r-- | lib/Transforms/Scalar/InstructionCombining.cpp | 39 |
1 files changed, 17 insertions, 22 deletions
diff --git a/lib/Transforms/Scalar/InstructionCombining.cpp b/lib/Transforms/Scalar/InstructionCombining.cpp index 7b01531fb2..b98228c092 100644 --- a/lib/Transforms/Scalar/InstructionCombining.cpp +++ b/lib/Transforms/Scalar/InstructionCombining.cpp @@ -5074,30 +5074,25 @@ Instruction *InstCombiner::visitSelectInst(SelectInst &SI) { } if (OtherAddOp) { - // So at this point we know we have: - // select C, (add X, Y), (sub X, ?) - // We can do the transform profitably if either 'Y' = '?' or '?' is - // a constant. - if (SubOp->getOperand(1) == AddOp || - isa<Constant>(SubOp->getOperand(1))) { - Value *NegVal; - if (Constant *C = dyn_cast<Constant>(SubOp->getOperand(1))) { - NegVal = ConstantExpr::getNeg(C); - } else { - NegVal = InsertNewInstBefore( - BinaryOperator::createNeg(SubOp->getOperand(1)), SI); - } + // So at this point we know we have (Y -> OtherAddOp): + // select C, (add X, Y), (sub X, Z) + Value *NegVal; // Compute -Z + if (Constant *C = dyn_cast<Constant>(SubOp->getOperand(1))) { + NegVal = ConstantExpr::getNeg(C); + } else { + NegVal = InsertNewInstBefore( + BinaryOperator::createNeg(SubOp->getOperand(1), "tmp"), SI); + } - Value *NewTrueOp = OtherAddOp; - Value *NewFalseOp = NegVal; - if (AddOp != TI) - std::swap(NewTrueOp, NewFalseOp); - Instruction *NewSel = - new SelectInst(CondVal, NewTrueOp,NewFalseOp,SI.getName()+".p"); + Value *NewTrueOp = OtherAddOp; + Value *NewFalseOp = NegVal; + if (AddOp != TI) + std::swap(NewTrueOp, NewFalseOp); + Instruction *NewSel = + new SelectInst(CondVal, NewTrueOp,NewFalseOp,SI.getName()+".p"); - NewSel = InsertNewInstBefore(NewSel, SI); - return BinaryOperator::createAdd(SubOp->getOperand(0), NewSel); - } + NewSel = InsertNewInstBefore(NewSel, SI); + return BinaryOperator::createAdd(SubOp->getOperand(0), NewSel); } } } |