llvm.org GIT mirror llvm / 5bd1ce0
[InstCombine] allow fmul fold with less than 'fast' git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@326502 91177308-0d34-0410-b5e6-96231b3b80d8 Sanjay Patel 2 years ago
2 changed file(s) with 14 addition(s) and 12 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
287289 define float @reassoc_common_operand_multi_use(float %x, float %y) {
288290 ; CHECK-LABEL: @reassoc_common_operand_multi_use(
289291 ; CHECK-NEXT: [[MUL1:%.*]] = fmul float [[X:%.*]], [[Y:%.*]]
290 ; CHECK-NEXT: [[MUL2:%.*]] = fmul fast float [[MUL1]], [[X]]
292 ; CHECK-NEXT: [[MUL2:%.*]] = fmul reassoc float [[MUL1]], [[X]]
291293 ; CHECK-NEXT: call void @use_f32(float [[MUL1]])
292294 ; CHECK-NEXT: ret float [[MUL2]]
293295 ;
294296 %mul1 = fmul float %x, %y
295 %mul2 = fmul fast float %mul1, %x
297 %mul2 = fmul reassoc float %mul1, %x
296298 call void @use_f32(float %mul1)
297299 ret float %mul2
298300 }