1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -reassociate -constprop -instcombine -S | FileCheck %s
4 define float @test1(float %A, float %B) {
6 ; CHECK-NEXT: [[W:%.*]] = fadd float [[B:%.*]], 5.000000e+00
7 ; CHECK-NEXT: [[X:%.*]] = fadd float [[A:%.*]], -7.000000e+00
8 ; CHECK-NEXT: [[Y:%.*]] = fsub float [[X]], [[W]]
9 ; CHECK-NEXT: [[Z:%.*]] = fadd float [[Y]], 1.200000e+01
10 ; CHECK-NEXT: ret float [[Z]]
12 %W = fadd float 5.0, %B
13 %X = fadd float -7.0, %A
14 %Y = fsub float %X, %W
15 %Z = fadd float %Y, 12.0
19 ; With sub reassociation, constant folding can eliminate all of the constants.
20 define float @test2(float %A, float %B) {
21 ; CHECK-LABEL: @test2(
22 ; CHECK-NEXT: [[Z:%.*]] = fsub fast float [[A:%.*]], [[B:%.*]]
23 ; CHECK-NEXT: ret float [[Z]]
25 %W = fadd fast float %B, 5.000000e+00
26 %X = fadd fast float %A, -7.000000e+00
27 %Y = fsub fast float %X, %W
28 %Z = fadd fast float %Y, 1.200000e+01
32 ; Check again using minimal subset of FMF.
33 ; Both 'reassoc' and 'nsz' are required.
34 define float @test2_minimal(float %A, float %B) {
35 ; CHECK-LABEL: @test2_minimal(
36 ; CHECK-NEXT: [[TMP1:%.*]] = fsub reassoc nsz float [[A:%.*]], [[B:%.*]]
37 ; CHECK-NEXT: ret float [[TMP1]]
39 %W = fadd reassoc nsz float %B, 5.000000e+00
40 %X = fadd reassoc nsz float %A, -7.000000e+00
41 %Y = fsub reassoc nsz float %X, %W
42 %Z = fadd reassoc nsz float %Y, 1.200000e+01
46 ; Verify the fold is not done with only 'reassoc' ('nsz' is required).
47 define float @test2_reassoc(float %A, float %B) {
48 ; CHECK-LABEL: @test2_reassoc(
49 ; CHECK-NEXT: [[W:%.*]] = fadd reassoc float [[B:%.*]], 5.000000e+00
50 ; CHECK-NEXT: [[X:%.*]] = fadd reassoc float [[A:%.*]], -7.000000e+00
51 ; CHECK-NEXT: [[Y:%.*]] = fsub reassoc float [[X]], [[W]]
52 ; CHECK-NEXT: [[Z:%.*]] = fadd reassoc float [[Y]], 1.200000e+01
53 ; CHECK-NEXT: ret float [[Z]]
55 %W = fadd reassoc float %B, 5.000000e+00
56 %X = fadd reassoc float %A, -7.000000e+00
57 %Y = fsub reassoc float %X, %W
58 %Z = fadd reassoc float %Y, 1.200000e+01
62 define float @test3(float %A, float %B, float %C, float %D) {
63 ; CHECK-LABEL: @test3(
64 ; CHECK-NEXT: [[M:%.*]] = fadd float [[A:%.*]], 1.200000e+01
65 ; CHECK-NEXT: [[N:%.*]] = fadd float [[M]], [[B:%.*]]
66 ; CHECK-NEXT: [[O:%.*]] = fadd float [[N]], [[C:%.*]]
67 ; CHECK-NEXT: [[P:%.*]] = fsub float [[D:%.*]], [[O]]
68 ; CHECK-NEXT: [[Q:%.*]] = fadd float [[P]], 1.200000e+01
69 ; CHECK-NEXT: ret float [[Q]]
71 %M = fadd float %A, 1.200000e+01
72 %N = fadd float %M, %B
73 %O = fadd float %N, %C
74 %P = fsub float %D, %O
75 %Q = fadd float %P, 1.200000e+01
79 ; With sub reassociation, constant folding can eliminate the two 12 constants.
81 define float @test4(float %A, float %B, float %C, float %D) {
82 ; FIXME: InstCombine should be able to get us to the following:
83 ; %sum = fadd fast float %B, %A
84 ; %sum1 = fadd fast float %sum, %C
85 ; %Q = fsub fast float %D, %sum1
87 ; CHECK-LABEL: @test4(
88 ; CHECK-NEXT: [[B_NEG:%.*]] = fsub fast float -0.000000e+00, [[B:%.*]]
89 ; CHECK-NEXT: [[O_NEG:%.*]] = fsub fast float [[B_NEG]], [[A:%.*]]
90 ; CHECK-NEXT: [[P:%.*]] = fsub fast float [[O_NEG]], [[C:%.*]]
91 ; CHECK-NEXT: [[Q:%.*]] = fadd fast float [[P]], [[D:%.*]]
92 ; CHECK-NEXT: ret float [[Q]]
94 %M = fadd fast float 1.200000e+01, %A
95 %N = fadd fast float %M, %B
96 %O = fadd fast float %N, %C
97 %P = fsub fast float %D, %O
98 %Q = fadd fast float 1.200000e+01, %P
102 ; Check again using minimal subset of FMF.
104 define float @test4_reassoc(float %A, float %B, float %C, float %D) {
105 ; CHECK-LABEL: @test4_reassoc(
106 ; CHECK-NEXT: [[M:%.*]] = fadd reassoc float [[A:%.*]], 1.200000e+01
107 ; CHECK-NEXT: [[N:%.*]] = fadd reassoc float [[M]], [[B:%.*]]
108 ; CHECK-NEXT: [[O:%.*]] = fadd reassoc float [[N]], [[C:%.*]]
109 ; CHECK-NEXT: [[P:%.*]] = fsub reassoc float [[D:%.*]], [[O]]
110 ; CHECK-NEXT: [[Q:%.*]] = fadd reassoc float [[P]], 1.200000e+01
111 ; CHECK-NEXT: ret float [[Q]]
113 %M = fadd reassoc float 1.200000e+01, %A
114 %N = fadd reassoc float %M, %B
115 %O = fadd reassoc float %N, %C
116 %P = fsub reassoc float %D, %O
117 %Q = fadd reassoc float 1.200000e+01, %P