[llvm] r191674 - InstCombine: Replace manual fast math flag copying with the new IRBuilder RAII helper.
Michael Ilseman
milseman at apple.com
Tue Oct 1 10:45:55 PDT 2013
Cool, thanks!
On Sep 30, 2013, at 8:39 AM, Benjamin Kramer <benny.kra at googlemail.com> wrote:
> Author: d0k
> Date: Mon Sep 30 10:39:59 2013
> New Revision: 191674
>
> URL: http://llvm.org/viewvc/llvm-project?rev=191674&view=rev
> Log:
> 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.
>
> Modified:
> llvm/trunk/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
>
> Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp?rev=191674&r1=191673&r2=191674&view=diff
> ==============================================================================
> --- llvm/trunk/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp (original)
> +++ llvm/trunk/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp Mon Sep 30 10:39:59 2013
> @@ -463,10 +463,9 @@ Instruction *InstCombiner::visitFMul(Bin
> 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(Bin
> }
> // 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(Bin
> 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(Bin
> 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(Bin
> Y = Opnd0_0;
>
> if (Y) {
> - Instruction *T = cast<Instruction>(Builder->CreateFMul(Opnd1, Opnd1));
> - T->copyFastMathFlags(&I);
> - T->setDebugLoc(I.getDebugLoc());
> -
> - Instruction *R = BinaryOperator::CreateFMul(T, Y);
> - R->copyFastMathFlags(&I);
> - return R;
> + BuilderTy::FastMathFlagGuard Guard(*Builder);
> + Builder->SetFastMathFlags(I.getFastMathFlags());
> + Value *T = Builder->CreateFMul(Opnd1, Opnd1);
> +
> + Value *R = Builder->CreateFMul(T, Y);
> + R->takeName(&I);
> + return ReplaceInstUsesWith(I, R);
> }
> }
> }
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
More information about the llvm-commits
mailing list