1 ; RUN: llc -mtriple=aarch64 %s -o - | FileCheck %s
2 ; RUN: llc -mtriple=aarch64 -global-isel=true -global-isel-abort=2 %s -o - | FileCheck %s
5 ; Div whose result is unused should be removed unless we have strict exceptions
7 ; CHECK-LABEL: unused_div:
10 define void @unused_div(float %x, float %y) {
12 %add = fdiv float %x, %y
16 ; CHECK-LABEL: unused_div_fpexcept_strict:
17 ; CHECK: fdiv s0, s0, s1
19 define void @unused_div_fpexcept_strict(float %x, float %y) #0 {
21 %add = call float @llvm.experimental.constrained.fdiv.f32(float %x, float %y, metadata !"round.tonearest", metadata !"fpexcept.strict") #0
25 ; CHECK-LABEL: unused_div_round_dynamic:
28 define void @unused_div_round_dynamic(float %x, float %y) #0 {
30 %add = call float @llvm.experimental.constrained.fdiv.f32(float %x, float %y, metadata !"round.dynamic", metadata !"fpexcept.ignore") #0
35 ; Machine CSE should eliminate the second add unless we have strict exceptions
37 ; CHECK-LABEL: add_twice:
38 ; CHECK: fadd [[ADD:s[0-9]+]], s0, s1
39 ; CHECK-NEXT: cmp w0, #0
40 ; CHECK-NEXT: fmul [[MUL:s[0-9]+]], [[ADD]], [[ADD]]
41 ; CHECK-NEXT: fcsel s0, [[ADD]], [[MUL]], eq
43 define float @add_twice(float %x, float %y, i32 %n) {
45 %add = fadd float %x, %y
46 %tobool.not = icmp eq i32 %n, 0
47 br i1 %tobool.not, label %if.end, label %if.then
50 %add1 = fadd float %x, %y
51 %mul = fmul float %add, %add1
55 %a.0 = phi float [ %mul, %if.then ], [ %add, %entry ]
59 ; CHECK-LABEL: add_twice_fpexcept_strict:
60 ; CHECK: fmov [[X:s[0-9]+]], s0
61 ; CHECK-NEXT: fadd s0, s0, s1
62 ; CHECK-NEXT: cbz w0, [[LABEL:.LBB[0-9_]+]]
63 ; CHECK: fadd [[ADD:s[0-9]+]], [[X]], s1
64 ; CHECK-NEXT: fmul s0, s0, [[ADD]]
67 define float @add_twice_fpexcept_strict(float %x, float %y, i32 %n) #0 {
69 %add = call float @llvm.experimental.constrained.fadd.f32(float %x, float %y, metadata !"round.tonearest", metadata !"fpexcept.strict") #0
70 %tobool.not = icmp eq i32 %n, 0
71 br i1 %tobool.not, label %if.end, label %if.then
74 %add1 = call float @llvm.experimental.constrained.fadd.f32(float %x, float %y, metadata !"round.tonearest", metadata !"fpexcept.strict") #0
75 %mul = call float @llvm.experimental.constrained.fmul.f32(float %add, float %add1, metadata !"round.tonearest", metadata !"fpexcept.strict") #0
79 %a.0 = phi float [ %mul, %if.then ], [ %add, %entry ]
83 ; CHECK-LABEL: add_twice_round_dynamic:
84 ; CHECK: fadd s0, s0, s1
85 ; CHECK-NEXT: cbz w0, [[LABEL:.LBB[0-9_]+]]
87 ; CHECK: fmul s0, s0, s0
90 define float @add_twice_round_dynamic(float %x, float %y, i32 %n) #0 {
92 %add = call float @llvm.experimental.constrained.fadd.f32(float %x, float %y, metadata !"round.dynamic", metadata !"fpexcept.ignore") #0
93 %tobool.not = icmp eq i32 %n, 0
94 br i1 %tobool.not, label %if.end, label %if.then
97 %add1 = call float @llvm.experimental.constrained.fadd.f32(float %x, float %y, metadata !"round.dynamic", metadata !"fpexcept.ignore") #0
98 %mul = call float @llvm.experimental.constrained.fmul.f32(float %add, float %add1, metadata !"round.dynamic", metadata !"fpexcept.ignore") #0
102 %a.0 = phi float [ %mul, %if.then ], [ %add, %entry ]
107 ; Two adds separated by llvm.set.rounding should be preserved when rounding is
108 ; dynamic (as they may give different results) or when we have strict exceptions
109 ; (the llvm.set.rounding is irrelevant, but both could trap).
111 ; CHECK-LABEL: set_rounding:
112 ; CHECK-DAG: fadd [[SREG:s[0-9]+]], s0, s1
113 ; CHECK-DAG: mrs [[XREG1:x[0-9]+]], FPCR
114 ; CHECK-DAG: orr [[XREG2:x[0-9]+]], [[XREG1]], #0xc00000
115 ; CHECK: msr FPCR, [[XREG2]]
116 ; CHECK-NEXT: mrs [[XREG3:x[0-9]+]], FPCR
117 ; CHECK-NEXT: and [[XREG4:x[0-9]+]], [[XREG3]], #0xffffffffff3fffff
118 ; CHECK-NEXT: msr FPCR, [[XREG4]]
119 ; CHECK-NEXT: fsub s0, [[SREG]], [[SREG]]
121 define float @set_rounding(float %x, float %y) {
123 %add1 = fadd float %x, %y
124 call void @llvm.set.rounding(i32 0)
125 %add2 = fadd float %x, %y
126 call void @llvm.set.rounding(i32 1)
127 %sub = fsub float %add1, %add2
131 ; CHECK-LABEL: set_rounding_fpexcept_strict:
132 ; CHECK-DAG: fadd [[SREG1:s[0-9]+]], s0, s1
133 ; CHECK-DAG: mrs [[XREG1:x[0-9]+]], FPCR
134 ; CHECK-DAG: orr [[XREG2:x[0-9]+]], [[XREG1]], #0xc00000
135 ; CHECK: msr FPCR, [[XREG2]]
136 ; CHECK-DAG: fadd [[SREG2:s[0-9]+]], s0, s1
137 ; CHECK-DAG: mrs [[XREG3:x[0-9]+]], FPCR
138 ; CHECK-DAG: and [[XREG4:x[0-9]+]], [[XREG3]], #0xffffffffff3fffff
139 ; CHECK-NEXT: msr FPCR, [[XREG4]]
140 ; CHECK-NEXT: fsub s0, [[SREG1]], [[SREG2]]
142 define float @set_rounding_fpexcept_strict(float %x, float %y) #0 {
144 %add1 = call float @llvm.experimental.constrained.fadd.f32(float %x, float %y, metadata !"round.tonearest", metadata !"fpexcept.strict") #0
145 call void @llvm.set.rounding(i32 0) #0
146 %add2 = call float @llvm.experimental.constrained.fadd.f32(float %x, float %y, metadata !"round.tonearest", metadata !"fpexcept.strict") #0
147 call void @llvm.set.rounding(i32 1) #0
148 %sub = call float @llvm.experimental.constrained.fsub.f32(float %add1, float %add2, metadata !"round.tonearest", metadata !"fpexcept.strict") #0
152 ; CHECK-LABEL: set_rounding_round_dynamic:
153 ; CHECK-DAG: fadd [[SREG1:s[0-9]+]], s0, s1
154 ; CHECK-DAG: mrs [[XREG1:x[0-9]+]], FPCR
155 ; CHECK-DAG: orr [[XREG2:x[0-9]+]], [[XREG1]], #0xc00000
156 ; CHECK: msr FPCR, [[XREG2]]
157 ; CHECK-DAG: fadd [[SREG2:s[0-9]+]], s0, s1
158 ; CHECK-DAG: mrs [[XREG3:x[0-9]+]], FPCR
159 ; CHECK-DAG: and [[XREG4:x[0-9]+]], [[XREG3]], #0xffffffffff3fffff
160 ; CHECK-NEXT: msr FPCR, [[XREG4]]
161 ; CHECK-NEXT: fsub s0, [[SREG1]], [[SREG2]]
163 define float @set_rounding_round_dynamic(float %x, float %y) #0 {
165 %add1 = call float @llvm.experimental.constrained.fadd.f32(float %x, float %y, metadata !"round.dynamic", metadata !"fpexcept.ignore") #0
166 call void @llvm.set.rounding(i32 0) #0
167 %add2 = call float @llvm.experimental.constrained.fadd.f32(float %x, float %y, metadata !"round.dynamic", metadata !"fpexcept.ignore") #0
168 call void @llvm.set.rounding(i32 1) #0
169 %sub = call float @llvm.experimental.constrained.fsub.f32(float %add1, float %add2, metadata !"round.dynamic", metadata !"fpexcept.ignore") #0
173 declare float @llvm.experimental.constrained.fadd.f32(float, float, metadata, metadata)
174 declare float @llvm.experimental.constrained.fsub.f32(float, float, metadata, metadata)
175 declare float @llvm.experimental.constrained.fmul.f32(float, float, metadata, metadata)
176 declare float @llvm.experimental.constrained.fdiv.f32(float, float, metadata, metadata)
177 declare i32 @llvm.get.rounding()
178 declare void @llvm.set.rounding(i32)
180 attributes #0 = { strictfp }