[llvm] r295353 - InstCombine: Canonicalize fast fmuladd to fmul + fadd
Philip Reames via llvm-commits
llvm-commits at lists.llvm.org
Thu Feb 16 17:31:01 PST 2017
Can you explain this one a bit? On the surface this seems a bit strange.
Philip
On 02/16/2017 10:46 AM, Matt Arsenault via llvm-commits wrote:
> Author: arsenm
> Date: Thu Feb 16 12:46:24 2017
> New Revision: 295353
>
> URL: http://llvm.org/viewvc/llvm-project?rev=295353&view=rev
> Log:
> InstCombine: Canonicalize fast fmuladd to fmul + fadd
>
> Modified:
> llvm/trunk/lib/Transforms/InstCombine/InstCombineCalls.cpp
> llvm/trunk/test/Transforms/InstCombine/fma.ll
>
> Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombineCalls.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineCalls.cpp?rev=295353&r1=295352&r2=295353&view=diff
> ==============================================================================
> --- llvm/trunk/lib/Transforms/InstCombine/InstCombineCalls.cpp (original)
> +++ llvm/trunk/lib/Transforms/InstCombine/InstCombineCalls.cpp Thu Feb 16 12:46:24 2017
> @@ -2044,8 +2044,21 @@ Instruction *InstCombiner::visitCallInst
> return replaceInstUsesWith(*II, V);
> break;
> }
> - case Intrinsic::fma:
> case Intrinsic::fmuladd: {
> + // Canonicalize fast fmuladd to the separate fmul + fadd.
> + if (II->hasUnsafeAlgebra()) {
> + BuilderTy::FastMathFlagGuard Guard(*Builder);
> + Builder->setFastMathFlags(II->getFastMathFlags());
> + Value *Mul = Builder->CreateFMul(II->getArgOperand(0),
> + II->getArgOperand(1));
> + Value *Add = Builder->CreateFAdd(Mul, II->getArgOperand(2));
> + Add->takeName(II);
> + return replaceInstUsesWith(*II, Add);
> + }
> +
> + LLVM_FALLTHROUGH;
> + }
> + case Intrinsic::fma: {
> Value *Src0 = II->getArgOperand(0);
> Value *Src1 = II->getArgOperand(1);
>
>
> Modified: llvm/trunk/test/Transforms/InstCombine/fma.ll
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/fma.ll?rev=295353&r1=295352&r2=295353&view=diff
> ==============================================================================
> --- llvm/trunk/test/Transforms/InstCombine/fma.ll (original)
> +++ llvm/trunk/test/Transforms/InstCombine/fma.ll Thu Feb 16 12:46:24 2017
> @@ -78,7 +78,8 @@ define float @fmuladd_fneg_x_fneg_y(floa
> }
>
> ; CHECK-LABEL: @fmuladd_fneg_x_fneg_y_fast(
> -; CHECK: %fmuladd = call fast float @llvm.fmuladd.f32(float %x, float %y, float %z)
> +; CHECK-NEXT: %1 = fmul fast float %x, %y
> +; CHECK-NEXT: %fmuladd = fadd fast float %1, %z
> define float @fmuladd_fneg_x_fneg_y_fast(float %x, float %y, float %z) {
> %x.fneg = fsub float -0.0, %x
> %y.fneg = fsub float -0.0, %y
> @@ -122,7 +123,8 @@ define float @fmuladd_fabs_x_fabs_x(floa
> }
>
> ; CHECK-LABEL: @fmuladd_fabs_x_fabs_x_fast(
> -; CHECK: %fmuladd = call fast float @llvm.fmuladd.f32(float %x, float %x, float %z)
> +; CHECK-NEXT: %1 = fmul fast float %x, %x
> +; CHECK-NEXT: %fmuladd = fadd fast float %1, %z
> define float @fmuladd_fabs_x_fabs_x_fast(float %x, float %z) {
> %x.fabs = call float @llvm.fabs.f32(float %x)
> %fmuladd = call fast float @llvm.fmuladd.f32(float %x.fabs, float %x.fabs, float %z)
> @@ -144,7 +146,8 @@ define float @fma_k_y_z_fast(float %y, f
> }
>
> ; CHECK-LABEL: @fmuladd_k_y_z_fast(
> -; CHECK: %fmuladd = call fast float @llvm.fmuladd.f32(float %y, float 4.000000e+00, float %z)
> +; CHECK: %1 = fmul fast float %y, 4.000000e+00
> +; CHECK-NEXT: %fmuladd = fadd fast float %1, %z
> define float @fmuladd_k_y_z_fast(float %y, float %z) {
> %fmuladd = call fast float @llvm.fmuladd.f32(float 4.0, float %y, float %z)
> ret float %fmuladd
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
More information about the llvm-commits
mailing list