llvm.org GIT mirror llvm / 49894f8
[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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@326513 91177308-0d34-0410-b5e6-96231b3b80d8 Sanjay Patel 2 years ago
3 changed file(s) with 15 addition(s) and 14 deletion(s). Raw diff Collapse all Expand all
675675 // latency of the instruction Y is amortized by the expression of X*X,
676676 // and therefore Y is in a "less critical" position compared to what it
677677 // was before the transformation.
678 if (I.isFast()) {
678 if (I.hasAllowReassoc()) {
679679 if (match(Op0, m_OneUse(m_c_FMul(m_Specific(Op1), m_Value(Y)))) &&
680680 Op1 != Y) {
681681 Value *XX = Builder.CreateFMulFMF(Op1, Op1, &I);
227227 }
228228
229229 ; (X*Y) * X => (X*X) * Y
230 ; The transform only requires 'reassoc', but test other FMF in
231 ; the commuted variants to make sure FMF propagates as expected.
230232
231233 define float @reassoc_common_operand1(float %x, float %y) {
232234 ; CHECK-LABEL: @reassoc_common_operand1(
233 ; CHECK-NEXT: [[TMP1:%.*]] = fmul fast float [[X:%.*]], [[X]]
234 ; CHECK-NEXT: [[MUL2:%.*]] = fmul fast float [[TMP1]], [[Y:%.*]]
235 ; CHECK-NEXT: [[TMP1:%.*]] = fmul reassoc float [[X:%.*]], [[X]]
236 ; CHECK-NEXT: [[MUL2:%.*]] = fmul reassoc float [[TMP1]], [[Y:%.*]]
235237 ; CHECK-NEXT: ret float [[MUL2]]
236238 ;
237239 %mul1 = fmul float %x, %y
238 %mul2 = fmul fast float %mul1, %x
240 %mul2 = fmul reassoc float %mul1, %x
239241 ret float %mul2
240242 }
241243
257259 define float @reassoc_common_operand3(float %x1, float %y) {
258260 ; CHECK-LABEL: @reassoc_common_operand3(
259261 ; CHECK-NEXT: [[X:%.*]] = fdiv float [[X1:%.*]], 3.000000e+00
260 ; CHECK-NEXT: [[TMP1:%.*]] = fmul fast float [[X]], [[X]]
261 ; CHECK-NEXT: [[MUL2:%.*]] = fmul fast float [[TMP1]], [[Y:%.*]]
262 ; CHECK-NEXT: [[TMP1:%.*]] = fmul reassoc nnan float [[X]], [[X]]
263 ; CHECK-NEXT: [[MUL2:%.*]] = fmul reassoc nnan float [[TMP1]], [[Y:%.*]]
262264 ; CHECK-NEXT: ret float [[MUL2]]
263265 ;
264266 %x = fdiv float %x1, 3.0 ; thwart complexity-based canonicalization
265267 %mul1 = fmul float %x, %y
266 %mul2 = fmul fast float %x, %mul1
268 %mul2 = fmul reassoc nnan float %x, %mul1
267269 ret float %mul2
268270 }
269271
272274 define float @reassoc_common_operand4(float %x1, float %y) {
273275 ; CHECK-LABEL: @reassoc_common_operand4(
274276 ; CHECK-NEXT: [[X:%.*]] = fdiv float [[X1:%.*]], 3.000000e+00
275 ; CHECK-NEXT: [[TMP1:%.*]] = fmul fast float [[X]], [[X]]
276 ; CHECK-NEXT: [[MUL2:%.*]] = fmul fast float [[TMP1]], [[Y:%.*]]
277 ; CHECK-NEXT: [[TMP1:%.*]] = fmul reassoc ninf float [[X]], [[X]]
278 ; CHECK-NEXT: [[MUL2:%.*]] = fmul reassoc ninf float [[TMP1]], [[Y:%.*]]
277279 ; CHECK-NEXT: ret float [[MUL2]]
278280 ;
279281 %x = fdiv float %x1, 3.0 ; thwart complexity-based canonicalization
280282 %mul1 = fmul float %y, %x
281 %mul2 = fmul fast float %x, %mul1
283 %mul2 = fmul reassoc ninf float %x, %mul1
282284 ret float %mul2
283285 }
284286
159159 ; CHECK-LABEL: @test7_reassoc(
160160 ; CHECK-NEXT: [[AA:%.*]] = fmul reassoc float [[A:%.*]], [[A]]
161161 ; CHECK-NEXT: [[AAB:%.*]] = fmul reassoc float [[AA]], [[B:%.*]]
162 ; CHECK-NEXT: [[AC:%.*]] = fmul reassoc float [[A]], [[C:%.*]]
163 ; CHECK-NEXT: [[AAC:%.*]] = fmul reassoc float [[AC]], [[A]]
162 ; CHECK-NEXT: [[TMP1:%.*]] = fmul reassoc float [[A]], [[A]]
163 ; CHECK-NEXT: [[AAC:%.*]] = fmul reassoc float [[TMP1]], [[C:%.*]]
164164 ; CHECK-NEXT: [[R:%.*]] = fadd reassoc float [[AAB]], [[AAC]]
165165 ; CHECK-NEXT: ret float [[R]]
166166 ;
361361
362362 define float @test15_reassoc(float %arg) {
363363 ; CHECK-LABEL: @test15_reassoc(
364 ; CHECK-NEXT: [[T1:%.*]] = fmul reassoc float [[ARG:%.*]], 1.200000e+01
365 ; CHECK-NEXT: [[T2:%.*]] = fmul reassoc float [[T1]], 1.200000e+01
364 ; CHECK-NEXT: [[T2:%.*]] = fmul reassoc float [[ARG:%.*]], 1.440000e+02
366365 ; CHECK-NEXT: ret float [[T2]]
367366 ;
368367 %t1 = fmul reassoc float 1.200000e+01, %arg