[llvm] r326513 - [InstCombine] allow fmul fold with less than 'fast'
Sanjay Patel via llvm-commits
llvm-commits at lists.llvm.org
Thu Mar 1 16:14:51 PST 2018
Author: spatel
Date: Thu Mar 1 16:14:51 2018
New Revision: 326513
URL: http://llvm.org/viewvc/llvm-project?rev=326513&view=rev
Log:
[InstCombine] allow fmul fold with less than 'fast'
This is a retry of r326502 with updates to the reassociate
test file that I missed the first time.
@test15_reassoc in the supposed -reassociate test file
(except that it tests 2 other passes too...) shows that
there's no clear responsiblity for reassociation transforms.
Instcombine now gets that case, but only because the
constant values are identical. Otherwise, it would still
miss that pattern.
Reassociate doesn't get that case because it hasn't been
updated to use less than 'fast' FMF.
Modified:
llvm/trunk/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
llvm/trunk/test/Transforms/InstCombine/fmul.ll
llvm/trunk/test/Transforms/Reassociate/fast-basictest.ll
Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp?rev=326513&r1=326512&r2=326513&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp Thu Mar 1 16:14:51 2018
@@ -676,7 +676,7 @@ Instruction *InstCombiner::visitFMul(Bin
// latency of the instruction Y is amortized by the expression of X*X,
// and therefore Y is in a "less critical" position compared to what it
// was before the transformation.
- if (I.isFast()) {
+ if (I.hasAllowReassoc()) {
if (match(Op0, m_OneUse(m_c_FMul(m_Specific(Op1), m_Value(Y)))) &&
Op1 != Y) {
Value *XX = Builder.CreateFMulFMF(Op1, Op1, &I);
Modified: llvm/trunk/test/Transforms/InstCombine/fmul.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/fmul.ll?rev=326513&r1=326512&r2=326513&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/fmul.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/fmul.ll Thu Mar 1 16:14:51 2018
@@ -228,15 +228,17 @@ define float @fabs_x_fabs(float %x, floa
}
; (X*Y) * X => (X*X) * Y
+; The transform only requires 'reassoc', but test other FMF in
+; the commuted variants to make sure FMF propagates as expected.
define float @reassoc_common_operand1(float %x, float %y) {
; CHECK-LABEL: @reassoc_common_operand1(
-; CHECK-NEXT: [[TMP1:%.*]] = fmul fast float [[X:%.*]], [[X]]
-; CHECK-NEXT: [[MUL2:%.*]] = fmul fast float [[TMP1]], [[Y:%.*]]
+; CHECK-NEXT: [[TMP1:%.*]] = fmul reassoc float [[X:%.*]], [[X]]
+; CHECK-NEXT: [[MUL2:%.*]] = fmul reassoc float [[TMP1]], [[Y:%.*]]
; CHECK-NEXT: ret float [[MUL2]]
;
%mul1 = fmul float %x, %y
- %mul2 = fmul fast float %mul1, %x
+ %mul2 = fmul reassoc float %mul1, %x
ret float %mul2
}
@@ -258,13 +260,13 @@ define float @reassoc_common_operand2(fl
define float @reassoc_common_operand3(float %x1, float %y) {
; CHECK-LABEL: @reassoc_common_operand3(
; CHECK-NEXT: [[X:%.*]] = fdiv float [[X1:%.*]], 3.000000e+00
-; CHECK-NEXT: [[TMP1:%.*]] = fmul fast float [[X]], [[X]]
-; CHECK-NEXT: [[MUL2:%.*]] = fmul fast float [[TMP1]], [[Y:%.*]]
+; CHECK-NEXT: [[TMP1:%.*]] = fmul reassoc nnan float [[X]], [[X]]
+; CHECK-NEXT: [[MUL2:%.*]] = fmul reassoc nnan float [[TMP1]], [[Y:%.*]]
; CHECK-NEXT: ret float [[MUL2]]
;
%x = fdiv float %x1, 3.0 ; thwart complexity-based canonicalization
%mul1 = fmul float %x, %y
- %mul2 = fmul fast float %x, %mul1
+ %mul2 = fmul reassoc nnan float %x, %mul1
ret float %mul2
}
@@ -273,13 +275,13 @@ define float @reassoc_common_operand3(fl
define float @reassoc_common_operand4(float %x1, float %y) {
; CHECK-LABEL: @reassoc_common_operand4(
; CHECK-NEXT: [[X:%.*]] = fdiv float [[X1:%.*]], 3.000000e+00
-; CHECK-NEXT: [[TMP1:%.*]] = fmul fast float [[X]], [[X]]
-; CHECK-NEXT: [[MUL2:%.*]] = fmul fast float [[TMP1]], [[Y:%.*]]
+; CHECK-NEXT: [[TMP1:%.*]] = fmul reassoc ninf float [[X]], [[X]]
+; CHECK-NEXT: [[MUL2:%.*]] = fmul reassoc ninf float [[TMP1]], [[Y:%.*]]
; CHECK-NEXT: ret float [[MUL2]]
;
%x = fdiv float %x1, 3.0 ; thwart complexity-based canonicalization
%mul1 = fmul float %y, %x
- %mul2 = fmul fast float %x, %mul1
+ %mul2 = fmul reassoc ninf float %x, %mul1
ret float %mul2
}
Modified: llvm/trunk/test/Transforms/Reassociate/fast-basictest.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/Reassociate/fast-basictest.ll?rev=326513&r1=326512&r2=326513&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/Reassociate/fast-basictest.ll (original)
+++ llvm/trunk/test/Transforms/Reassociate/fast-basictest.ll Thu Mar 1 16:14:51 2018
@@ -160,8 +160,8 @@ define float @test7_reassoc(float %A, fl
; CHECK-LABEL: @test7_reassoc(
; CHECK-NEXT: [[AA:%.*]] = fmul reassoc float [[A:%.*]], [[A]]
; CHECK-NEXT: [[AAB:%.*]] = fmul reassoc float [[AA]], [[B:%.*]]
-; CHECK-NEXT: [[AC:%.*]] = fmul reassoc float [[A]], [[C:%.*]]
-; CHECK-NEXT: [[AAC:%.*]] = fmul reassoc float [[AC]], [[A]]
+; CHECK-NEXT: [[TMP1:%.*]] = fmul reassoc float [[A]], [[A]]
+; CHECK-NEXT: [[AAC:%.*]] = fmul reassoc float [[TMP1]], [[C:%.*]]
; CHECK-NEXT: [[R:%.*]] = fadd reassoc float [[AAB]], [[AAC]]
; CHECK-NEXT: ret float [[R]]
;
@@ -362,8 +362,7 @@ define float @test15(float %arg) {
define float @test15_reassoc(float %arg) {
; CHECK-LABEL: @test15_reassoc(
-; CHECK-NEXT: [[T1:%.*]] = fmul reassoc float [[ARG:%.*]], 1.200000e+01
-; CHECK-NEXT: [[T2:%.*]] = fmul reassoc float [[T1]], 1.200000e+01
+; CHECK-NEXT: [[T2:%.*]] = fmul reassoc float [[ARG:%.*]], 1.440000e+02
; CHECK-NEXT: ret float [[T2]]
;
%t1 = fmul reassoc float 1.200000e+01, %arg
More information about the llvm-commits
mailing list