Skip to content
This repository was archived by the owner on Mar 28, 2020. It is now read-only.

Commit 6d9b2bf

Browse files
committed
[InstCombine] move/add tests for fmul reassociation; NFC
This transform may be out-of-scope for instcombine, but this is only documenting the current behavior. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@326442 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 196ad9c commit 6d9b2bf

File tree

2 files changed

+72
-12
lines changed

2 files changed

+72
-12
lines changed

test/Transforms/InstCombine/fast-math.ll

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -361,18 +361,6 @@ define float @fmul5(float %f1, float %f2) {
361361
ret float %t3
362362
}
363363

364-
; (X*Y) * X => (X*X) * Y
365-
define float @fmul6(float %f1, float %f2) {
366-
; CHECK-LABEL: @fmul6(
367-
; CHECK-NEXT: [[TMP1:%.*]] = fmul fast float [[F1:%.*]], [[F1]]
368-
; CHECK-NEXT: [[MUL1:%.*]] = fmul fast float [[TMP1]], [[F2:%.*]]
369-
; CHECK-NEXT: ret float [[MUL1]]
370-
;
371-
%mul = fmul float %f1, %f2
372-
%mul1 = fmul fast float %mul, %f1
373-
ret float %mul1
374-
}
375-
376364
; "(X*Y) * X => (X*X) * Y" is disabled if "X*Y" has multiple uses
377365
define float @fmul7(float %f1, float %f2) {
378366
; CHECK-LABEL: @fmul7(

test/Transforms/InstCombine/fmul.ll

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,3 +226,75 @@ define float @fabs_x_fabs(float %x, float %y) {
226226
%mul = fmul float %x.fabs, %y.fabs
227227
ret float %mul
228228
}
229+
230+
; (X*Y) * X => (X*X) * Y
231+
232+
define float @reassoc_common_operand1(float %x, float %y) {
233+
; CHECK-LABEL: @reassoc_common_operand1(
234+
; CHECK-NEXT: [[TMP1:%.*]] = fmul fast float [[X:%.*]], [[X]]
235+
; CHECK-NEXT: [[MUL2:%.*]] = fmul fast float [[TMP1]], [[Y:%.*]]
236+
; CHECK-NEXT: ret float [[MUL2]]
237+
;
238+
%mul1 = fmul float %x, %y
239+
%mul2 = fmul fast float %mul1, %x
240+
ret float %mul2
241+
}
242+
243+
; (Y*X) * X => (X*X) * Y
244+
245+
define float @reassoc_common_operand2(float %x, float %y) {
246+
; CHECK-LABEL: @reassoc_common_operand2(
247+
; CHECK-NEXT: [[TMP1:%.*]] = fmul fast float [[X:%.*]], [[X]]
248+
; CHECK-NEXT: [[MUL2:%.*]] = fmul fast float [[TMP1]], [[Y:%.*]]
249+
; CHECK-NEXT: ret float [[MUL2]]
250+
;
251+
%mul1 = fmul float %y, %x
252+
%mul2 = fmul fast float %mul1, %x
253+
ret float %mul2
254+
}
255+
256+
; X * (X*Y) => (X*X) * Y
257+
258+
define float @reassoc_common_operand3(float %x1, float %y) {
259+
; CHECK-LABEL: @reassoc_common_operand3(
260+
; CHECK-NEXT: [[X:%.*]] = fdiv float [[X1:%.*]], 3.000000e+00
261+
; CHECK-NEXT: [[TMP1:%.*]] = fmul fast float [[X]], [[X]]
262+
; CHECK-NEXT: [[MUL2:%.*]] = fmul fast float [[TMP1]], [[Y:%.*]]
263+
; CHECK-NEXT: ret float [[MUL2]]
264+
;
265+
%x = fdiv float %x1, 3.0 ; thwart complexity-based canonicalization
266+
%mul1 = fmul float %x, %y
267+
%mul2 = fmul fast float %x, %mul1
268+
ret float %mul2
269+
}
270+
271+
; X * (Y*X) => (X*X) * Y
272+
273+
define float @reassoc_common_operand4(float %x1, float %y) {
274+
; CHECK-LABEL: @reassoc_common_operand4(
275+
; CHECK-NEXT: [[X:%.*]] = fdiv float [[X1:%.*]], 3.000000e+00
276+
; CHECK-NEXT: [[TMP1:%.*]] = fmul fast float [[X]], [[X]]
277+
; CHECK-NEXT: [[MUL2:%.*]] = fmul fast float [[TMP1]], [[Y:%.*]]
278+
; CHECK-NEXT: ret float [[MUL2]]
279+
;
280+
%x = fdiv float %x1, 3.0 ; thwart complexity-based canonicalization
281+
%mul1 = fmul float %y, %x
282+
%mul2 = fmul fast float %x, %mul1
283+
ret float %mul2
284+
}
285+
286+
; No change if the first fmul has another use.
287+
288+
define float @reassoc_common_operand_multi_use(float %x, float %y) {
289+
; CHECK-LABEL: @reassoc_common_operand_multi_use(
290+
; CHECK-NEXT: [[MUL1:%.*]] = fmul float [[X:%.*]], [[Y:%.*]]
291+
; CHECK-NEXT: [[MUL2:%.*]] = fmul fast float [[MUL1]], [[X]]
292+
; CHECK-NEXT: call void @use_f32(float [[MUL1]])
293+
; CHECK-NEXT: ret float [[MUL2]]
294+
;
295+
%mul1 = fmul float %x, %y
296+
%mul2 = fmul fast float %mul1, %x
297+
call void @use_f32(float %mul1)
298+
ret float %mul2
299+
}
300+

0 commit comments

Comments
 (0)