1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-22 18:54:02 +01:00

InstCombine: Replace manual fast math flag copying with the new IRBuilder RAII helper.

Defines away the issue where cast<Instruction> would fail because constant
folding happened. Also slightly cleaner.

llvm-svn: 191674
This commit is contained in:
Benjamin Kramer 2013-09-30 15:39:59 +00:00
parent 33abdcddb3
commit ae9249f56f

View File

@ -463,10 +463,9 @@ Instruction *InstCombiner::visitFMul(BinaryOperator &I) {
if (Swap && FAddSub->getOpcode() == Instruction::FSub)
std::swap(M0, M1);
Value *R = (FAddSub->getOpcode() == Instruction::FAdd) ?
BinaryOperator::CreateFAdd(M0, M1) :
BinaryOperator::CreateFSub(M0, M1);
Instruction *RI = cast<Instruction>(R);
Instruction *RI = (FAddSub->getOpcode() == Instruction::FAdd)
? BinaryOperator::CreateFAdd(M0, M1)
: BinaryOperator::CreateFSub(M0, M1);
RI->copyFastMathFlags(&I);
return RI;
}
@ -493,13 +492,13 @@ Instruction *InstCombiner::visitFMul(BinaryOperator &I) {
}
// if pattern detected emit alternate sequence
if (OpX && OpY) {
BuilderTy::FastMathFlagGuard Guard(*Builder);
Builder->SetFastMathFlags(Log2->getFastMathFlags());
Log2->setArgOperand(0, OpY);
Value *FMulVal = Builder->CreateFMul(OpX, Log2);
Instruction *FMul = cast<Instruction>(FMulVal);
FMul->copyFastMathFlags(Log2);
Instruction *FSub = BinaryOperator::CreateFSub(FMulVal, OpX);
FSub->copyFastMathFlags(Log2);
return FSub;
Value *FSub = Builder->CreateFSub(FMulVal, OpX);
FSub->takeName(&I);
return ReplaceInstUsesWith(I, FSub);
}
}
@ -509,6 +508,9 @@ Instruction *InstCombiner::visitFMul(BinaryOperator &I) {
for (int i = 0; i < 2; i++) {
bool IgnoreZeroSign = I.hasNoSignedZeros();
if (BinaryOperator::isFNeg(Opnd0, IgnoreZeroSign)) {
BuilderTy::FastMathFlagGuard Guard(*Builder);
Builder->SetFastMathFlags(I.getFastMathFlags());
Value *N0 = dyn_castFNegVal(Opnd0, IgnoreZeroSign);
Value *N1 = dyn_castFNegVal(Opnd1, IgnoreZeroSign);
@ -519,13 +521,9 @@ Instruction *InstCombiner::visitFMul(BinaryOperator &I) {
if (Opnd0->hasOneUse()) {
// -X * Y => -(X*Y) (Promote negation as high as possible)
Value *T = Builder->CreateFMul(N0, Opnd1);
Instruction *Neg = BinaryOperator::CreateFNeg(T);
if (I.getFastMathFlags().any()) {
if (Instruction *TI = dyn_cast<Instruction>(T))
TI->copyFastMathFlags(&I);
Neg->copyFastMathFlags(&I);
}
return Neg;
Value *Neg = Builder->CreateFNeg(T);
Neg->takeName(&I);
return ReplaceInstUsesWith(I, Neg);
}
}
@ -548,13 +546,13 @@ Instruction *InstCombiner::visitFMul(BinaryOperator &I) {
Y = Opnd0_0;
if (Y) {
Instruction *T = cast<Instruction>(Builder->CreateFMul(Opnd1, Opnd1));
T->copyFastMathFlags(&I);
T->setDebugLoc(I.getDebugLoc());
BuilderTy::FastMathFlagGuard Guard(*Builder);
Builder->SetFastMathFlags(I.getFastMathFlags());
Value *T = Builder->CreateFMul(Opnd1, Opnd1);
Instruction *R = BinaryOperator::CreateFMul(T, Y);
R->copyFastMathFlags(&I);
return R;
Value *R = Builder->CreateFMul(T, Y);
R->takeName(&I);
return ReplaceInstUsesWith(I, R);
}
}
}