Skip to content

Commit e7a02eb

Browse files
committed
InstCombine: Add baseline test for #64697 fmul reassociation
Currently fmul is not reassociated unless it has nsz, although this should be unnecessary.
1 parent 4bff9fd commit e7a02eb

File tree

1 file changed

+117
-0
lines changed

1 file changed

+117
-0
lines changed
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 6
2+
; RUN: opt -S -passes=instcombine < %s | FileCheck %s
3+
4+
; Show that unlike fadd, fmul does not require nsz to be reassociated.
5+
6+
; Can't reassociate anyway
7+
define float @fmul(float %x) {
8+
; CHECK-LABEL: define float @fmul(
9+
; CHECK-SAME: float [[X:%.*]]) {
10+
; CHECK-NEXT: [[FMUL0:%.*]] = fmul float [[X]], 2.000000e+00
11+
; CHECK-NEXT: [[FMUL1:%.*]] = fmul float [[FMUL0]], 4.000000e+00
12+
; CHECK-NEXT: ret float [[FMUL1]]
13+
;
14+
%fmul0 = fmul float %x, 2.0
15+
%fmul1 = fmul float %fmul0, 4.0
16+
ret float %fmul1
17+
}
18+
19+
; Should be able to reassociate without nsz
20+
; (+0 * 2) * 4 = +0
21+
; (-0 * 2) * 4 = -0
22+
23+
; (+0 * 8) = +0
24+
; (-0 * 8) = -0
25+
define float @fmul_reassoc(float %x) {
26+
; CHECK-LABEL: define float @fmul_reassoc(
27+
; CHECK-SAME: float [[X:%.*]]) {
28+
; CHECK-NEXT: [[FMUL0:%.*]] = fmul reassoc float [[X]], 2.000000e+00
29+
; CHECK-NEXT: [[FMUL1:%.*]] = fmul reassoc float [[FMUL0]], 4.000000e+00
30+
; CHECK-NEXT: ret float [[FMUL1]]
31+
;
32+
%fmul0 = fmul reassoc float %x, 2.0
33+
%fmul1 = fmul reassoc float %fmul0, 4.0
34+
ret float %fmul1
35+
}
36+
37+
define <2 x float> @fmul_reassoc_v2(<2 x float> %x) {
38+
; CHECK-LABEL: define <2 x float> @fmul_reassoc_v2(
39+
; CHECK-SAME: <2 x float> [[X:%.*]]) {
40+
; CHECK-NEXT: [[FMUL0:%.*]] = fmul reassoc <2 x float> [[X]], splat (float 2.000000e+00)
41+
; CHECK-NEXT: [[FMUL1:%.*]] = fmul reassoc <2 x float> [[FMUL0]], splat (float 4.000000e+00)
42+
; CHECK-NEXT: ret <2 x float> [[FMUL1]]
43+
;
44+
%fmul0 = fmul reassoc <2 x float> %x, splat (float 2.0)
45+
%fmul1 = fmul reassoc <2 x float> %fmul0, splat (float 4.0)
46+
ret <2 x float> %fmul1
47+
}
48+
49+
; (+0 * 2) * -4 = -0
50+
; (-0 * 2) * -4 = +0
51+
52+
; (+0 * -8) = -0
53+
; (-0 * -8) = +0
54+
define float @fmul_reassoc_negative_0(float %x) {
55+
; CHECK-LABEL: define float @fmul_reassoc_negative_0(
56+
; CHECK-SAME: float [[X:%.*]]) {
57+
; CHECK-NEXT: [[FMUL0:%.*]] = fmul reassoc float [[X]], 2.000000e+00
58+
; CHECK-NEXT: [[FMUL1:%.*]] = fmul reassoc float [[FMUL0]], -4.000000e+00
59+
; CHECK-NEXT: ret float [[FMUL1]]
60+
;
61+
%fmul0 = fmul reassoc float %x, 2.0
62+
%fmul1 = fmul reassoc float %fmul0, -4.0
63+
ret float %fmul1
64+
}
65+
66+
; (+0 * -2) * 4 = -0
67+
; (-0 * -2) * 4 = +0
68+
69+
; (+0 * -8) = -0
70+
; (-0 * -8) = +0
71+
define float @fmul_reassoc_negative_1(float %x) {
72+
; CHECK-LABEL: define float @fmul_reassoc_negative_1(
73+
; CHECK-SAME: float [[X:%.*]]) {
74+
; CHECK-NEXT: [[FMUL0:%.*]] = fmul reassoc float [[X]], -2.000000e+00
75+
; CHECK-NEXT: [[FMUL1:%.*]] = fmul reassoc float [[FMUL0]], 4.000000e+00
76+
; CHECK-NEXT: ret float [[FMUL1]]
77+
;
78+
%fmul0 = fmul reassoc float %x, -2.0
79+
%fmul1 = fmul reassoc float %fmul0, 4.0
80+
ret float %fmul1
81+
}
82+
83+
; Does reassociate already, unnecessarily requires nsz on both multiplies.
84+
define float @fmul_reassoc_nsz(float %x) {
85+
; CHECK-LABEL: define float @fmul_reassoc_nsz(
86+
; CHECK-SAME: float [[X:%.*]]) {
87+
; CHECK-NEXT: [[FMUL1:%.*]] = fmul reassoc nsz float [[X]], 8.000000e+00
88+
; CHECK-NEXT: ret float [[FMUL1]]
89+
;
90+
%fmul0 = fmul nsz reassoc float %x, 2.0
91+
%fmul1 = fmul nsz reassoc float %fmul0, 4.0
92+
ret float %fmul1
93+
}
94+
95+
define float @fmul_reassoc_posk_neg0(float %x) {
96+
; CHECK-LABEL: define float @fmul_reassoc_posk_neg0(
97+
; CHECK-SAME: float [[X:%.*]]) {
98+
; CHECK-NEXT: [[FMUL0:%.*]] = fmul reassoc float [[X]], 4.000000e+00
99+
; CHECK-NEXT: [[FMUL1:%.*]] = fmul reassoc float [[FMUL0]], -0.000000e+00
100+
; CHECK-NEXT: ret float [[FMUL1]]
101+
;
102+
%fmul0 = fmul reassoc float %x, 4.0
103+
%fmul1 = fmul reassoc float %fmul0, -0.0
104+
ret float %fmul1
105+
}
106+
107+
define float @fmul_reassoc_neg0_posk(float %x) {
108+
; CHECK-LABEL: define float @fmul_reassoc_neg0_posk(
109+
; CHECK-SAME: float [[X:%.*]]) {
110+
; CHECK-NEXT: [[FMUL0:%.*]] = fmul reassoc float [[X]], -0.000000e+00
111+
; CHECK-NEXT: [[FMUL1:%.*]] = fmul reassoc float [[FMUL0]], 4.000000e+00
112+
; CHECK-NEXT: ret float [[FMUL1]]
113+
;
114+
%fmul0 = fmul reassoc float %x, -0.0
115+
%fmul1 = fmul reassoc float %fmul0, 4.0
116+
ret float %fmul1
117+
}

0 commit comments

Comments
 (0)