Sanjay Patel | e7532d2 | 2018-05-03 17:41:37 +0000 | [diff] [blame] | 1 | ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py |
| 2 | ; REQUIRES: asserts |
Sanjay Patel | 5215188 | 2018-05-03 18:49:35 +0000 | [diff] [blame] | 3 | ; RUN: llc < %s -mtriple=powerpc64le -debug-only=isel -o /dev/null 2>&1 | FileCheck %s --check-prefix=FMFDEBUG |
| 4 | ; RUN: llc < %s -mtriple=powerpc64le | FileCheck %s --check-prefix=FMF |
Sanjay Patel | 4c8a67a | 2018-05-14 21:17:49 +0000 | [diff] [blame] | 5 | ; RUN: llc < %s -mtriple=powerpc64le -debug-only=isel -o /dev/null 2>&1 -enable-unsafe-fp-math -enable-no-nans-fp-math | FileCheck %s --check-prefix=GLOBALDEBUG |
| 6 | ; RUN: llc < %s -mtriple=powerpc64le -enable-unsafe-fp-math -enable-no-nans-fp-math | FileCheck %s --check-prefix=GLOBAL |
Sanjay Patel | e7532d2 | 2018-05-03 17:41:37 +0000 | [diff] [blame] | 7 | |
| 8 | ; Test FP transforms using instruction/node-level fast-math-flags. |
| 9 | ; We're also checking debug output to verify that FMF is propagated to the newly created nodes. |
| 10 | ; The run with the global unsafe param tests the pre-FMF behavior using regular instructions/nodes. |
| 11 | |
| 12 | declare float @llvm.fma.f32(float, float, float) |
| 13 | declare float @llvm.sqrt.f32(float) |
| 14 | |
| 15 | ; X * Y + Z --> fma(X, Y, Z) |
| 16 | |
| 17 | ; FMFDEBUG-LABEL: Optimized lowered selection DAG: %bb.0 'fmul_fadd_contract1:' |
Michael Berg | 8e570c3 | 2018-06-16 00:03:06 +0000 | [diff] [blame] | 18 | ; FMFDEBUG: fma contract {{t[0-9]+}}, {{t[0-9]+}}, {{t[0-9]+}} |
Sanjay Patel | e7532d2 | 2018-05-03 17:41:37 +0000 | [diff] [blame] | 19 | ; FMFDEBUG: Type-legalized selection DAG: %bb.0 'fmul_fadd_contract1:' |
| 20 | |
| 21 | define float @fmul_fadd_contract1(float %x, float %y, float %z) { |
| 22 | ; FMF-LABEL: fmul_fadd_contract1: |
| 23 | ; FMF: # %bb.0: |
Michael Berg | 8e570c3 | 2018-06-16 00:03:06 +0000 | [diff] [blame] | 24 | ; FMF-NEXT: xsmaddasp 3, 1, 2 |
| 25 | ; FMF-NEXT: fmr 1, 3 |
Sanjay Patel | e7532d2 | 2018-05-03 17:41:37 +0000 | [diff] [blame] | 26 | ; FMF-NEXT: blr |
| 27 | ; |
| 28 | ; GLOBAL-LABEL: fmul_fadd_contract1: |
| 29 | ; GLOBAL: # %bb.0: |
| 30 | ; GLOBAL-NEXT: xsmaddasp 3, 1, 2 |
| 31 | ; GLOBAL-NEXT: fmr 1, 3 |
| 32 | ; GLOBAL-NEXT: blr |
| 33 | %mul = fmul float %x, %y |
| 34 | %add = fadd contract float %mul, %z |
| 35 | ret float %add |
| 36 | } |
| 37 | |
| 38 | ; This shouldn't change anything - the intermediate fmul result is now also flagged. |
| 39 | |
| 40 | ; FMFDEBUG-LABEL: Optimized lowered selection DAG: %bb.0 'fmul_fadd_contract2:' |
Michael Berg | 77b5be7 | 2018-06-07 22:49:09 +0000 | [diff] [blame] | 41 | ; FMFDEBUG: fma contract {{t[0-9]+}}, {{t[0-9]+}}, {{t[0-9]+}} |
Sanjay Patel | e7532d2 | 2018-05-03 17:41:37 +0000 | [diff] [blame] | 42 | ; FMFDEBUG: Type-legalized selection DAG: %bb.0 'fmul_fadd_contract2:' |
| 43 | |
| 44 | define float @fmul_fadd_contract2(float %x, float %y, float %z) { |
| 45 | ; FMF-LABEL: fmul_fadd_contract2: |
| 46 | ; FMF: # %bb.0: |
| 47 | ; FMF-NEXT: xsmaddasp 3, 1, 2 |
| 48 | ; FMF-NEXT: fmr 1, 3 |
| 49 | ; FMF-NEXT: blr |
| 50 | ; |
| 51 | ; GLOBAL-LABEL: fmul_fadd_contract2: |
| 52 | ; GLOBAL: # %bb.0: |
| 53 | ; GLOBAL-NEXT: xsmaddasp 3, 1, 2 |
| 54 | ; GLOBAL-NEXT: fmr 1, 3 |
| 55 | ; GLOBAL-NEXT: blr |
| 56 | %mul = fmul contract float %x, %y |
| 57 | %add = fadd contract float %mul, %z |
| 58 | ret float %add |
| 59 | } |
| 60 | |
| 61 | ; Reassociation implies that FMA contraction is allowed. |
| 62 | |
| 63 | ; FMFDEBUG-LABEL: Optimized lowered selection DAG: %bb.0 'fmul_fadd_reassoc1:' |
Michael Berg | 8e570c3 | 2018-06-16 00:03:06 +0000 | [diff] [blame] | 64 | ; FMFDEBUG: fma reassoc {{t[0-9]+}}, {{t[0-9]+}}, {{t[0-9]+}} |
Sanjay Patel | e7532d2 | 2018-05-03 17:41:37 +0000 | [diff] [blame] | 65 | ; FMFDEBUG: Type-legalized selection DAG: %bb.0 'fmul_fadd_reassoc1:' |
| 66 | |
| 67 | define float @fmul_fadd_reassoc1(float %x, float %y, float %z) { |
| 68 | ; FMF-LABEL: fmul_fadd_reassoc1: |
| 69 | ; FMF: # %bb.0: |
Michael Berg | 8e570c3 | 2018-06-16 00:03:06 +0000 | [diff] [blame] | 70 | ; FMF-NEXT: xsmaddasp 3, 1, 2 |
| 71 | ; FMF-NEXT: fmr 1, 3 |
Sanjay Patel | e7532d2 | 2018-05-03 17:41:37 +0000 | [diff] [blame] | 72 | ; FMF-NEXT: blr |
| 73 | ; |
| 74 | ; GLOBAL-LABEL: fmul_fadd_reassoc1: |
| 75 | ; GLOBAL: # %bb.0: |
| 76 | ; GLOBAL-NEXT: xsmaddasp 3, 1, 2 |
| 77 | ; GLOBAL-NEXT: fmr 1, 3 |
| 78 | ; GLOBAL-NEXT: blr |
| 79 | %mul = fmul float %x, %y |
| 80 | %add = fadd reassoc float %mul, %z |
| 81 | ret float %add |
| 82 | } |
| 83 | |
| 84 | ; This shouldn't change anything - the intermediate fmul result is now also flagged. |
| 85 | |
| 86 | ; FMFDEBUG-LABEL: Optimized lowered selection DAG: %bb.0 'fmul_fadd_reassoc2:' |
Michael Berg | 77b5be7 | 2018-06-07 22:49:09 +0000 | [diff] [blame] | 87 | ; FMFDEBUG: fma reassoc {{t[0-9]+}}, {{t[0-9]+}} |
Sanjay Patel | e7532d2 | 2018-05-03 17:41:37 +0000 | [diff] [blame] | 88 | ; FMFDEBUG: Type-legalized selection DAG: %bb.0 'fmul_fadd_reassoc2:' |
| 89 | |
| 90 | define float @fmul_fadd_reassoc2(float %x, float %y, float %z) { |
| 91 | ; FMF-LABEL: fmul_fadd_reassoc2: |
| 92 | ; FMF: # %bb.0: |
Michael Berg | 7acc81b | 2018-05-04 18:48:20 +0000 | [diff] [blame] | 93 | ; FMF-NEXT: xsmaddasp 3, 1, 2 |
| 94 | ; FMF-NEXT: fmr 1, 3 |
Sanjay Patel | e7532d2 | 2018-05-03 17:41:37 +0000 | [diff] [blame] | 95 | ; FMF-NEXT: blr |
| 96 | ; |
| 97 | ; GLOBAL-LABEL: fmul_fadd_reassoc2: |
| 98 | ; GLOBAL: # %bb.0: |
| 99 | ; GLOBAL-NEXT: xsmaddasp 3, 1, 2 |
| 100 | ; GLOBAL-NEXT: fmr 1, 3 |
| 101 | ; GLOBAL-NEXT: blr |
| 102 | %mul = fmul reassoc float %x, %y |
| 103 | %add = fadd reassoc float %mul, %z |
| 104 | ret float %add |
| 105 | } |
| 106 | |
| 107 | ; The fadd is now fully 'fast'. This implies that contraction is allowed. |
| 108 | |
| 109 | ; FMFDEBUG-LABEL: Optimized lowered selection DAG: %bb.0 'fmul_fadd_fast1:' |
Michael Berg | 77b5be7 | 2018-06-07 22:49:09 +0000 | [diff] [blame] | 110 | ; FMFDEBUG: fma nnan ninf nsz arcp contract afn reassoc {{t[0-9]+}}, {{t[0-9]+}}, {{t[0-9]+}} |
Sanjay Patel | e7532d2 | 2018-05-03 17:41:37 +0000 | [diff] [blame] | 111 | ; FMFDEBUG: Type-legalized selection DAG: %bb.0 'fmul_fadd_fast1:' |
| 112 | |
| 113 | define float @fmul_fadd_fast1(float %x, float %y, float %z) { |
| 114 | ; FMF-LABEL: fmul_fadd_fast1: |
| 115 | ; FMF: # %bb.0: |
| 116 | ; FMF-NEXT: xsmaddasp 3, 1, 2 |
| 117 | ; FMF-NEXT: fmr 1, 3 |
| 118 | ; FMF-NEXT: blr |
| 119 | ; |
| 120 | ; GLOBAL-LABEL: fmul_fadd_fast1: |
| 121 | ; GLOBAL: # %bb.0: |
| 122 | ; GLOBAL-NEXT: xsmaddasp 3, 1, 2 |
| 123 | ; GLOBAL-NEXT: fmr 1, 3 |
| 124 | ; GLOBAL-NEXT: blr |
| 125 | %mul = fmul fast float %x, %y |
| 126 | %add = fadd fast float %mul, %z |
| 127 | ret float %add |
| 128 | } |
| 129 | |
| 130 | ; This shouldn't change anything - the intermediate fmul result is now also flagged. |
| 131 | |
| 132 | ; FMFDEBUG-LABEL: Optimized lowered selection DAG: %bb.0 'fmul_fadd_fast2:' |
Michael Berg | 77b5be7 | 2018-06-07 22:49:09 +0000 | [diff] [blame] | 133 | ; FMFDEBUG: fma nnan ninf nsz arcp contract afn reassoc {{t[0-9]+}}, {{t[0-9]+}}, {{t[0-9]+}} |
Sanjay Patel | e7532d2 | 2018-05-03 17:41:37 +0000 | [diff] [blame] | 134 | ; FMFDEBUG: Type-legalized selection DAG: %bb.0 'fmul_fadd_fast2:' |
| 135 | |
| 136 | define float @fmul_fadd_fast2(float %x, float %y, float %z) { |
| 137 | ; FMF-LABEL: fmul_fadd_fast2: |
| 138 | ; FMF: # %bb.0: |
| 139 | ; FMF-NEXT: xsmaddasp 3, 1, 2 |
| 140 | ; FMF-NEXT: fmr 1, 3 |
| 141 | ; FMF-NEXT: blr |
| 142 | ; |
| 143 | ; GLOBAL-LABEL: fmul_fadd_fast2: |
| 144 | ; GLOBAL: # %bb.0: |
| 145 | ; GLOBAL-NEXT: xsmaddasp 3, 1, 2 |
| 146 | ; GLOBAL-NEXT: fmr 1, 3 |
| 147 | ; GLOBAL-NEXT: blr |
| 148 | %mul = fmul fast float %x, %y |
| 149 | %add = fadd fast float %mul, %z |
| 150 | ret float %add |
| 151 | } |
| 152 | |
| 153 | ; fma(X, 7.0, X * 42.0) --> X * 49.0 |
| 154 | ; This is the minimum FMF needed for this transform - the FMA allows reassociation. |
| 155 | |
| 156 | ; FMFDEBUG-LABEL: Optimized lowered selection DAG: %bb.0 'fmul_fma_reassoc1:' |
Stefan Pintilie | cb4f0c5 | 2018-07-04 18:54:25 +0000 | [diff] [blame] | 157 | ; FMFDEBUG: fmul reassoc {{t[0-9]+}}, |
Sanjay Patel | e7532d2 | 2018-05-03 17:41:37 +0000 | [diff] [blame] | 158 | ; FMFDEBUG: Type-legalized selection DAG: %bb.0 'fmul_fma_reassoc1:' |
| 159 | |
Sanjay Patel | 5215188 | 2018-05-03 18:49:35 +0000 | [diff] [blame] | 160 | ; GLOBALDEBUG-LABEL: Optimized lowered selection DAG: %bb.0 'fmul_fma_reassoc1:' |
Michael Berg | 7acc81b | 2018-05-04 18:48:20 +0000 | [diff] [blame] | 161 | ; GLOBALDEBUG: fmul reassoc {{t[0-9]+}} |
Sanjay Patel | 5215188 | 2018-05-03 18:49:35 +0000 | [diff] [blame] | 162 | ; GLOBALDEBUG: Type-legalized selection DAG: %bb.0 'fmul_fma_reassoc1:' |
| 163 | |
Sanjay Patel | e7532d2 | 2018-05-03 17:41:37 +0000 | [diff] [blame] | 164 | define float @fmul_fma_reassoc1(float %x) { |
| 165 | ; FMF-LABEL: fmul_fma_reassoc1: |
| 166 | ; FMF: # %bb.0: |
| 167 | ; FMF-NEXT: addis 3, 2, .LCPI6_0@toc@ha |
| 168 | ; FMF-NEXT: addi 3, 3, .LCPI6_0@toc@l |
| 169 | ; FMF-NEXT: lfsx 0, 0, 3 |
Michael Berg | 8e570c3 | 2018-06-16 00:03:06 +0000 | [diff] [blame] | 170 | ; FMF-NEXT: xsmulsp 1, 1, 0 |
Sanjay Patel | e7532d2 | 2018-05-03 17:41:37 +0000 | [diff] [blame] | 171 | ; FMF-NEXT: blr |
| 172 | ; |
| 173 | ; GLOBAL-LABEL: fmul_fma_reassoc1: |
| 174 | ; GLOBAL: # %bb.0: |
| 175 | ; GLOBAL-NEXT: addis 3, 2, .LCPI6_0@toc@ha |
| 176 | ; GLOBAL-NEXT: addi 3, 3, .LCPI6_0@toc@l |
| 177 | ; GLOBAL-NEXT: lfsx 0, 0, 3 |
| 178 | ; GLOBAL-NEXT: xsmulsp 1, 1, 0 |
| 179 | ; GLOBAL-NEXT: blr |
| 180 | %mul = fmul float %x, 42.0 |
| 181 | %fma = call reassoc float @llvm.fma.f32(float %x, float 7.0, float %mul) |
| 182 | ret float %fma |
| 183 | } |
| 184 | |
| 185 | ; This shouldn't change anything - the intermediate fmul result is now also flagged. |
| 186 | |
| 187 | ; FMFDEBUG-LABEL: Optimized lowered selection DAG: %bb.0 'fmul_fma_reassoc2:' |
Michael Berg | 77b5be7 | 2018-06-07 22:49:09 +0000 | [diff] [blame] | 188 | ; FMFDEBUG: fmul reassoc {{t[0-9]+}} |
Sanjay Patel | e7532d2 | 2018-05-03 17:41:37 +0000 | [diff] [blame] | 189 | ; FMFDEBUG: Type-legalized selection DAG: %bb.0 'fmul_fma_reassoc2:' |
| 190 | |
Sanjay Patel | 5215188 | 2018-05-03 18:49:35 +0000 | [diff] [blame] | 191 | ; GLOBALDEBUG-LABEL: Optimized lowered selection DAG: %bb.0 'fmul_fma_reassoc2:' |
Michael Berg | 7acc81b | 2018-05-04 18:48:20 +0000 | [diff] [blame] | 192 | ; GLOBALDEBUG: fmul reassoc {{t[0-9]+}} |
Sanjay Patel | 5215188 | 2018-05-03 18:49:35 +0000 | [diff] [blame] | 193 | ; GLOBALDEBUG: Type-legalized selection DAG: %bb.0 'fmul_fma_reassoc2:' |
| 194 | |
Sanjay Patel | e7532d2 | 2018-05-03 17:41:37 +0000 | [diff] [blame] | 195 | define float @fmul_fma_reassoc2(float %x) { |
| 196 | ; FMF-LABEL: fmul_fma_reassoc2: |
| 197 | ; FMF: # %bb.0: |
| 198 | ; FMF-NEXT: addis 3, 2, .LCPI7_0@toc@ha |
| 199 | ; FMF-NEXT: addi 3, 3, .LCPI7_0@toc@l |
| 200 | ; FMF-NEXT: lfsx 0, 0, 3 |
Michael Berg | 8e570c3 | 2018-06-16 00:03:06 +0000 | [diff] [blame] | 201 | ; FMF-NEXT: xsmulsp 1, 1, 0 |
Sanjay Patel | e7532d2 | 2018-05-03 17:41:37 +0000 | [diff] [blame] | 202 | ; FMF-NEXT: blr |
| 203 | ; |
| 204 | ; GLOBAL-LABEL: fmul_fma_reassoc2: |
| 205 | ; GLOBAL: # %bb.0: |
| 206 | ; GLOBAL-NEXT: addis 3, 2, .LCPI7_0@toc@ha |
| 207 | ; GLOBAL-NEXT: addi 3, 3, .LCPI7_0@toc@l |
| 208 | ; GLOBAL-NEXT: lfsx 0, 0, 3 |
| 209 | ; GLOBAL-NEXT: xsmulsp 1, 1, 0 |
| 210 | ; GLOBAL-NEXT: blr |
| 211 | %mul = fmul reassoc float %x, 42.0 |
| 212 | %fma = call reassoc float @llvm.fma.f32(float %x, float 7.0, float %mul) |
| 213 | ret float %fma |
| 214 | } |
| 215 | |
| 216 | ; The FMA is now fully 'fast'. This implies that reassociation is allowed. |
| 217 | |
| 218 | ; FMFDEBUG-LABEL: Optimized lowered selection DAG: %bb.0 'fmul_fma_fast1:' |
Michael Berg | 8e570c3 | 2018-06-16 00:03:06 +0000 | [diff] [blame] | 219 | ; FMFDEBUG: fmul nnan ninf nsz arcp contract afn reassoc {{t[0-9]+}} |
Sanjay Patel | e7532d2 | 2018-05-03 17:41:37 +0000 | [diff] [blame] | 220 | ; FMFDEBUG: Type-legalized selection DAG: %bb.0 'fmul_fma_fast1:' |
| 221 | |
Sanjay Patel | 5215188 | 2018-05-03 18:49:35 +0000 | [diff] [blame] | 222 | ; GLOBALDEBUG-LABEL: Optimized lowered selection DAG: %bb.0 'fmul_fma_fast1:' |
Michael Berg | 77b5be7 | 2018-06-07 22:49:09 +0000 | [diff] [blame] | 223 | ; GLOBALDEBUG: fmul nnan ninf nsz arcp contract afn reassoc {{t[0-9]+}} |
Sanjay Patel | 5215188 | 2018-05-03 18:49:35 +0000 | [diff] [blame] | 224 | ; GLOBALDEBUG: Type-legalized selection DAG: %bb.0 'fmul_fma_fast1:' |
| 225 | |
Sanjay Patel | e7532d2 | 2018-05-03 17:41:37 +0000 | [diff] [blame] | 226 | define float @fmul_fma_fast1(float %x) { |
| 227 | ; FMF-LABEL: fmul_fma_fast1: |
| 228 | ; FMF: # %bb.0: |
| 229 | ; FMF-NEXT: addis 3, 2, .LCPI8_0@toc@ha |
| 230 | ; FMF-NEXT: addi 3, 3, .LCPI8_0@toc@l |
| 231 | ; FMF-NEXT: lfsx 0, 0, 3 |
Michael Berg | 8e570c3 | 2018-06-16 00:03:06 +0000 | [diff] [blame] | 232 | ; FMF-NEXT: xsmulsp 1, 1, 0 |
Sanjay Patel | e7532d2 | 2018-05-03 17:41:37 +0000 | [diff] [blame] | 233 | ; FMF-NEXT: blr |
| 234 | ; |
| 235 | ; GLOBAL-LABEL: fmul_fma_fast1: |
| 236 | ; GLOBAL: # %bb.0: |
| 237 | ; GLOBAL-NEXT: addis 3, 2, .LCPI8_0@toc@ha |
| 238 | ; GLOBAL-NEXT: addi 3, 3, .LCPI8_0@toc@l |
| 239 | ; GLOBAL-NEXT: lfsx 0, 0, 3 |
| 240 | ; GLOBAL-NEXT: xsmulsp 1, 1, 0 |
| 241 | ; GLOBAL-NEXT: blr |
| 242 | %mul = fmul float %x, 42.0 |
| 243 | %fma = call fast float @llvm.fma.f32(float %x, float 7.0, float %mul) |
| 244 | ret float %fma |
| 245 | } |
| 246 | |
| 247 | ; This shouldn't change anything - the intermediate fmul result is now also flagged. |
| 248 | |
| 249 | ; FMFDEBUG-LABEL: Optimized lowered selection DAG: %bb.0 'fmul_fma_fast2:' |
Michael Berg | 77b5be7 | 2018-06-07 22:49:09 +0000 | [diff] [blame] | 250 | ; FMFDEBUG: fmul nnan ninf nsz arcp contract afn reassoc {{t[0-9]+}} |
Sanjay Patel | e7532d2 | 2018-05-03 17:41:37 +0000 | [diff] [blame] | 251 | ; FMFDEBUG: Type-legalized selection DAG: %bb.0 'fmul_fma_fast2:' |
| 252 | |
Sanjay Patel | 5215188 | 2018-05-03 18:49:35 +0000 | [diff] [blame] | 253 | ; GLOBALDEBUG-LABEL: Optimized lowered selection DAG: %bb.0 'fmul_fma_fast2:' |
Michael Berg | 77b5be7 | 2018-06-07 22:49:09 +0000 | [diff] [blame] | 254 | ; GLOBALDEBUG: fmul nnan ninf nsz arcp contract afn reassoc {{t[0-9]+}} |
Sanjay Patel | 5215188 | 2018-05-03 18:49:35 +0000 | [diff] [blame] | 255 | ; GLOBALDEBUG: Type-legalized selection DAG: %bb.0 'fmul_fma_fast2:' |
| 256 | |
Sanjay Patel | e7532d2 | 2018-05-03 17:41:37 +0000 | [diff] [blame] | 257 | define float @fmul_fma_fast2(float %x) { |
| 258 | ; FMF-LABEL: fmul_fma_fast2: |
| 259 | ; FMF: # %bb.0: |
| 260 | ; FMF-NEXT: addis 3, 2, .LCPI9_0@toc@ha |
| 261 | ; FMF-NEXT: addi 3, 3, .LCPI9_0@toc@l |
| 262 | ; FMF-NEXT: lfsx 0, 0, 3 |
Michael Berg | 8e570c3 | 2018-06-16 00:03:06 +0000 | [diff] [blame] | 263 | ; FMF-NEXT: xsmulsp 1, 1, 0 |
Sanjay Patel | e7532d2 | 2018-05-03 17:41:37 +0000 | [diff] [blame] | 264 | ; FMF-NEXT: blr |
| 265 | ; |
| 266 | ; GLOBAL-LABEL: fmul_fma_fast2: |
| 267 | ; GLOBAL: # %bb.0: |
| 268 | ; GLOBAL-NEXT: addis 3, 2, .LCPI9_0@toc@ha |
| 269 | ; GLOBAL-NEXT: addi 3, 3, .LCPI9_0@toc@l |
| 270 | ; GLOBAL-NEXT: lfsx 0, 0, 3 |
| 271 | ; GLOBAL-NEXT: xsmulsp 1, 1, 0 |
| 272 | ; GLOBAL-NEXT: blr |
| 273 | %mul = fmul fast float %x, 42.0 |
| 274 | %fma = call fast float @llvm.fma.f32(float %x, float 7.0, float %mul) |
| 275 | ret float %fma |
| 276 | } |
| 277 | |
| 278 | ; Reduced precision for sqrt is allowed - should use estimate and NR iterations. |
| 279 | |
| 280 | ; FMFDEBUG-LABEL: Optimized lowered selection DAG: %bb.0 'sqrt_afn:' |
Michael Berg | cc1c4b6 | 2018-06-06 18:47:55 +0000 | [diff] [blame] | 281 | ; FMFDEBUG: fmul afn {{t[0-9]+}} |
Sanjay Patel | e7532d2 | 2018-05-03 17:41:37 +0000 | [diff] [blame] | 282 | ; FMFDEBUG: Type-legalized selection DAG: %bb.0 'sqrt_afn:' |
| 283 | |
Sanjay Patel | 5215188 | 2018-05-03 18:49:35 +0000 | [diff] [blame] | 284 | ; GLOBALDEBUG-LABEL: Optimized lowered selection DAG: %bb.0 'sqrt_afn:' |
Michael Berg | cc1c4b6 | 2018-06-06 18:47:55 +0000 | [diff] [blame] | 285 | ; GLOBALDEBUG: fmul afn {{t[0-9]+}} |
Sanjay Patel | 5215188 | 2018-05-03 18:49:35 +0000 | [diff] [blame] | 286 | ; GLOBALDEBUG: Type-legalized selection DAG: %bb.0 'sqrt_afn:' |
| 287 | |
Sanjay Patel | e7532d2 | 2018-05-03 17:41:37 +0000 | [diff] [blame] | 288 | define float @sqrt_afn(float %x) { |
| 289 | ; FMF-LABEL: sqrt_afn: |
Stefan Pintilie | cb4f0c5 | 2018-07-04 18:54:25 +0000 | [diff] [blame] | 290 | ; FMF: # %bb.0: |
| 291 | ; FMF-NEXT: xxlxor 0, 0, 0 |
| 292 | ; FMF-NEXT: fcmpu 0, 1, 0 |
| 293 | ; FMF-NEXT: beq 0, .LBB10_2 |
| 294 | ; FMF-NEXT: # %bb.1: |
| 295 | ; FMF-NEXT: addis 3, 2, .LCPI10_0@toc@ha |
| 296 | ; FMF-NEXT: xsrsqrtesp 3, 1 |
| 297 | ; FMF-NEXT: addi 3, 3, .LCPI10_0@toc@l |
| 298 | ; FMF-NEXT: lfsx 0, 0, 3 |
| 299 | ; FMF-NEXT: xsmulsp 2, 1, 0 |
| 300 | ; FMF-NEXT: xsmulsp 4, 3, 3 |
| 301 | ; FMF-NEXT: xssubsp 2, 2, 1 |
| 302 | ; FMF-NEXT: xsmulsp 2, 2, 4 |
| 303 | ; FMF-NEXT: xssubsp 0, 0, 2 |
| 304 | ; FMF-NEXT: xsmulsp 0, 3, 0 |
| 305 | ; FMF-NEXT: xsmulsp 0, 0, 1 |
| 306 | ; FMF-NEXT: .LBB10_2: |
| 307 | ; FMF-NEXT: fmr 1, 0 |
| 308 | ; FMF-NEXT: blr |
Sanjay Patel | e7532d2 | 2018-05-03 17:41:37 +0000 | [diff] [blame] | 309 | ; |
| 310 | ; GLOBAL-LABEL: sqrt_afn: |
| 311 | ; GLOBAL: # %bb.0: |
| 312 | ; GLOBAL-NEXT: xxlxor 0, 0, 0 |
| 313 | ; GLOBAL-NEXT: fcmpu 0, 1, 0 |
| 314 | ; GLOBAL-NEXT: beq 0, .LBB10_2 |
| 315 | ; GLOBAL-NEXT: # %bb.1: |
| 316 | ; GLOBAL-NEXT: xsrsqrtesp 2, 1 |
Sanjay Patel | e7532d2 | 2018-05-03 17:41:37 +0000 | [diff] [blame] | 317 | ; GLOBAL-NEXT: fneg 0, 1 |
Stefan Pintilie | cb4f0c5 | 2018-07-04 18:54:25 +0000 | [diff] [blame] | 318 | ; GLOBAL-NEXT: addis 3, 2, .LCPI10_0@toc@ha |
Sanjay Patel | e7532d2 | 2018-05-03 17:41:37 +0000 | [diff] [blame] | 319 | ; GLOBAL-NEXT: fmr 4, 1 |
| 320 | ; GLOBAL-NEXT: addi 3, 3, .LCPI10_0@toc@l |
| 321 | ; GLOBAL-NEXT: lfsx 3, 0, 3 |
| 322 | ; GLOBAL-NEXT: xsmaddasp 4, 0, 3 |
| 323 | ; GLOBAL-NEXT: xsmulsp 0, 2, 2 |
| 324 | ; GLOBAL-NEXT: xsmaddasp 3, 4, 0 |
| 325 | ; GLOBAL-NEXT: xsmulsp 0, 2, 3 |
| 326 | ; GLOBAL-NEXT: xsmulsp 0, 0, 1 |
| 327 | ; GLOBAL-NEXT: .LBB10_2: |
| 328 | ; GLOBAL-NEXT: fmr 1, 0 |
| 329 | ; GLOBAL-NEXT: blr |
| 330 | %rt = call afn float @llvm.sqrt.f32(float %x) |
| 331 | ret float %rt |
| 332 | } |
| 333 | |
| 334 | ; The call is now fully 'fast'. This implies that approximation is allowed. |
| 335 | |
| 336 | ; FMFDEBUG-LABEL: Optimized lowered selection DAG: %bb.0 'sqrt_fast:' |
Michael Berg | cc1c4b6 | 2018-06-06 18:47:55 +0000 | [diff] [blame] | 337 | ; FMFDEBUG: fmul nnan ninf nsz arcp contract afn reassoc {{t[0-9]+}} |
Sanjay Patel | e7532d2 | 2018-05-03 17:41:37 +0000 | [diff] [blame] | 338 | ; FMFDEBUG: Type-legalized selection DAG: %bb.0 'sqrt_fast:' |
| 339 | |
Sanjay Patel | 5215188 | 2018-05-03 18:49:35 +0000 | [diff] [blame] | 340 | ; GLOBALDEBUG-LABEL: Optimized lowered selection DAG: %bb.0 'sqrt_fast:' |
Michael Berg | cc1c4b6 | 2018-06-06 18:47:55 +0000 | [diff] [blame] | 341 | ; GLOBALDEBUG: fmul nnan ninf nsz arcp contract afn reassoc {{t[0-9]+}} |
Sanjay Patel | 5215188 | 2018-05-03 18:49:35 +0000 | [diff] [blame] | 342 | ; GLOBALDEBUG: Type-legalized selection DAG: %bb.0 'sqrt_fast:' |
| 343 | |
Sanjay Patel | e7532d2 | 2018-05-03 17:41:37 +0000 | [diff] [blame] | 344 | define float @sqrt_fast(float %x) { |
| 345 | ; FMF-LABEL: sqrt_fast: |
Stefan Pintilie | cb4f0c5 | 2018-07-04 18:54:25 +0000 | [diff] [blame] | 346 | ; FMF: # %bb.0: |
| 347 | ; FMF-NEXT: xxlxor 0, 0, 0 |
| 348 | ; FMF-NEXT: fcmpu 0, 1, 0 |
| 349 | ; FMF-NEXT: beq 0, .LBB11_2 |
| 350 | ; FMF-NEXT: # %bb.1: |
| 351 | ; FMF-NEXT: xsrsqrtesp 2, 1 |
| 352 | ; FMF-NEXT: fneg 0, 1 |
| 353 | ; FMF-NEXT: addis 3, 2, .LCPI11_0@toc@ha |
| 354 | ; FMF-NEXT: fmr 4, 1 |
| 355 | ; FMF-NEXT: addi 3, 3, .LCPI11_0@toc@l |
| 356 | ; FMF-NEXT: lfsx 3, 0, 3 |
| 357 | ; FMF-NEXT: xsmaddasp 4, 0, 3 |
| 358 | ; FMF-NEXT: xsmulsp 0, 2, 2 |
| 359 | ; FMF-NEXT: xsmaddasp 3, 4, 0 |
| 360 | ; FMF-NEXT: xsmulsp 0, 2, 3 |
| 361 | ; FMF-NEXT: xsmulsp 0, 0, 1 |
| 362 | ; FMF-NEXT: .LBB11_2: |
| 363 | ; FMF-NEXT: fmr 1, 0 |
| 364 | ; FMF-NEXT: blr |
Sanjay Patel | e7532d2 | 2018-05-03 17:41:37 +0000 | [diff] [blame] | 365 | ; |
| 366 | ; GLOBAL-LABEL: sqrt_fast: |
| 367 | ; GLOBAL: # %bb.0: |
| 368 | ; GLOBAL-NEXT: xxlxor 0, 0, 0 |
| 369 | ; GLOBAL-NEXT: fcmpu 0, 1, 0 |
| 370 | ; GLOBAL-NEXT: beq 0, .LBB11_2 |
| 371 | ; GLOBAL-NEXT: # %bb.1: |
| 372 | ; GLOBAL-NEXT: xsrsqrtesp 2, 1 |
Sanjay Patel | e7532d2 | 2018-05-03 17:41:37 +0000 | [diff] [blame] | 373 | ; GLOBAL-NEXT: fneg 0, 1 |
Stefan Pintilie | cb4f0c5 | 2018-07-04 18:54:25 +0000 | [diff] [blame] | 374 | ; GLOBAL-NEXT: addis 3, 2, .LCPI11_0@toc@ha |
Sanjay Patel | e7532d2 | 2018-05-03 17:41:37 +0000 | [diff] [blame] | 375 | ; GLOBAL-NEXT: fmr 4, 1 |
| 376 | ; GLOBAL-NEXT: addi 3, 3, .LCPI11_0@toc@l |
| 377 | ; GLOBAL-NEXT: lfsx 3, 0, 3 |
| 378 | ; GLOBAL-NEXT: xsmaddasp 4, 0, 3 |
| 379 | ; GLOBAL-NEXT: xsmulsp 0, 2, 2 |
| 380 | ; GLOBAL-NEXT: xsmaddasp 3, 4, 0 |
| 381 | ; GLOBAL-NEXT: xsmulsp 0, 2, 3 |
| 382 | ; GLOBAL-NEXT: xsmulsp 0, 0, 1 |
| 383 | ; GLOBAL-NEXT: .LBB11_2: |
| 384 | ; GLOBAL-NEXT: fmr 1, 0 |
| 385 | ; GLOBAL-NEXT: blr |
| 386 | %rt = call fast float @llvm.sqrt.f32(float %x) |
| 387 | ret float %rt |
| 388 | } |
| 389 | |
Sanjay Patel | 4c8a67a | 2018-05-14 21:17:49 +0000 | [diff] [blame] | 390 | ; fcmp can have fast-math-flags. |
| 391 | |
| 392 | ; FMFDEBUG-LABEL: Optimized lowered selection DAG: %bb.0 'fcmp_nnan:' |
| 393 | ; FMFDEBUG: select_cc {{t[0-9]+}} |
| 394 | ; FMFDEBUG: Type-legalized selection DAG: %bb.0 'fcmp_nnan:' |
| 395 | |
| 396 | ; GLOBALDEBUG-LABEL: Optimized lowered selection DAG: %bb.0 'fcmp_nnan:' |
| 397 | ; GLOBALDEBUG: select_cc {{t[0-9]+}} |
| 398 | ; GLOBALDEBUG: Type-legalized selection DAG: %bb.0 'fcmp_nnan:' |
| 399 | |
| 400 | define double @fcmp_nnan(double %a, double %y, double %z) { |
| 401 | ; FMF-LABEL: fcmp_nnan: |
| 402 | ; FMF: # %bb.0: |
| 403 | ; FMF-NEXT: xxlxor 0, 0, 0 |
Sanjay Patel | 8652c53 | 2018-05-15 14:16:24 +0000 | [diff] [blame] | 404 | ; FMF-NEXT: xscmpudp 0, 1, 0 |
| 405 | ; FMF-NEXT: blt 0, .LBB12_2 |
Sanjay Patel | 4c8a67a | 2018-05-14 21:17:49 +0000 | [diff] [blame] | 406 | ; FMF-NEXT: # %bb.1: |
| 407 | ; FMF-NEXT: fmr 3, 2 |
| 408 | ; FMF-NEXT: .LBB12_2: |
| 409 | ; FMF-NEXT: fmr 1, 3 |
| 410 | ; FMF-NEXT: blr |
| 411 | ; |
| 412 | ; GLOBAL-LABEL: fcmp_nnan: |
| 413 | ; GLOBAL: # %bb.0: |
| 414 | ; GLOBAL-NEXT: xxlxor 0, 0, 0 |
| 415 | ; GLOBAL-NEXT: xscmpudp 0, 1, 0 |
| 416 | ; GLOBAL-NEXT: blt 0, .LBB12_2 |
| 417 | ; GLOBAL-NEXT: # %bb.1: |
| 418 | ; GLOBAL-NEXT: fmr 3, 2 |
| 419 | ; GLOBAL-NEXT: .LBB12_2: |
| 420 | ; GLOBAL-NEXT: fmr 1, 3 |
| 421 | ; GLOBAL-NEXT: blr |
| 422 | %cmp = fcmp nnan ult double %a, 0.0 |
| 423 | %z.y = select i1 %cmp, double %z, double %y |
| 424 | ret double %z.y |
| 425 | } |
| 426 | |
| 427 | ; FP library calls can have fast-math-flags. |
| 428 | |
| 429 | ; FMFDEBUG-LABEL: Optimized lowered selection DAG: %bb.0 'log2_approx:' |
| 430 | ; FMFDEBUG: ch,glue = PPCISD::CALL_NOP t11, TargetGlobalAddress:i64<double (double)* @log2> |
| 431 | ; FMFDEBUG: ch,glue = callseq_end t15, TargetConstant:i64<32>, TargetConstant:i64<0>, t15:1 |
Sanjay Patel | 8652c53 | 2018-05-15 14:16:24 +0000 | [diff] [blame] | 432 | ; FMFDEBUG: f64,ch,glue = CopyFromReg afn t16, Register:f64 $f1, t16:1 |
Sanjay Patel | 4c8a67a | 2018-05-14 21:17:49 +0000 | [diff] [blame] | 433 | ; FMFDEBUG: Type-legalized selection DAG: %bb.0 'log2_approx:' |
| 434 | |
| 435 | ; GLOBALDEBUG-LABEL: Optimized lowered selection DAG: %bb.0 'log2_approx:' |
| 436 | ; GLOBALDEBUG: ch,glue = PPCISD::CALL_NOP t11, TargetGlobalAddress:i64<double (double)* @log2> |
| 437 | ; GLOBALDEBUG: ch,glue = callseq_end t15, TargetConstant:i64<32>, TargetConstant:i64<0>, t15:1 |
Sanjay Patel | 8652c53 | 2018-05-15 14:16:24 +0000 | [diff] [blame] | 438 | ; GLOBALDEBUG: f64,ch,glue = CopyFromReg afn t16, Register:f64 $f1, t16:1 |
Sanjay Patel | 4c8a67a | 2018-05-14 21:17:49 +0000 | [diff] [blame] | 439 | ; GLOBALDEBUG: Type-legalized selection DAG: %bb.0 'log2_approx:' |
| 440 | |
| 441 | declare double @log2(double) |
| 442 | define double @log2_approx(double %x) nounwind { |
| 443 | ; FMF-LABEL: log2_approx: |
| 444 | ; FMF: # %bb.0: |
| 445 | ; FMF-NEXT: mflr 0 |
| 446 | ; FMF-NEXT: std 0, 16(1) |
| 447 | ; FMF-NEXT: stdu 1, -32(1) |
| 448 | ; FMF-NEXT: bl log2 |
| 449 | ; FMF-NEXT: nop |
| 450 | ; FMF-NEXT: addi 1, 1, 32 |
| 451 | ; FMF-NEXT: ld 0, 16(1) |
| 452 | ; FMF-NEXT: mtlr 0 |
| 453 | ; FMF-NEXT: blr |
| 454 | ; |
| 455 | ; GLOBAL-LABEL: log2_approx: |
| 456 | ; GLOBAL: # %bb.0: |
| 457 | ; GLOBAL-NEXT: mflr 0 |
| 458 | ; GLOBAL-NEXT: std 0, 16(1) |
| 459 | ; GLOBAL-NEXT: stdu 1, -32(1) |
| 460 | ; GLOBAL-NEXT: bl log2 |
| 461 | ; GLOBAL-NEXT: nop |
| 462 | ; GLOBAL-NEXT: addi 1, 1, 32 |
| 463 | ; GLOBAL-NEXT: ld 0, 16(1) |
| 464 | ; GLOBAL-NEXT: mtlr 0 |
| 465 | ; GLOBAL-NEXT: blr |
| 466 | %r = call afn double @log2(double %x) |
| 467 | ret double %r |
| 468 | } |
| 469 | |
Michael Berg | 8f6d6c8 | 2018-06-05 18:12:25 +0000 | [diff] [blame] | 470 | ; -(X - Y) --> (Y - X) |
| 471 | |
| 472 | ; FMFDEBUG-LABEL: Optimized lowered selection DAG: %bb.0 'fneg_fsub_nozeros_1:' |
Michael Berg | 96925fe | 2018-06-05 18:49:47 +0000 | [diff] [blame] | 473 | ; FMFDEBUG: fsub nsz {{t[0-9]+}}, {{t[0-9]+}} |
Michael Berg | 8f6d6c8 | 2018-06-05 18:12:25 +0000 | [diff] [blame] | 474 | ; FMFDEBUG: Type-legalized selection DAG: %bb.0 'fneg_fsub_nozeros_1:' |
| 475 | |
| 476 | ; GLOBALDEBUG-LABEL: Optimized lowered selection DAG: %bb.0 'fneg_fsub_nozeros_1:' |
Michael Berg | 96925fe | 2018-06-05 18:49:47 +0000 | [diff] [blame] | 477 | ; GLOBALDEBUG: fsub nsz {{t[0-9]+}}, {{t[0-9]+}} |
Michael Berg | 8f6d6c8 | 2018-06-05 18:12:25 +0000 | [diff] [blame] | 478 | ; GLOBALDEBUG: Type-legalized selection DAG: %bb.0 'fneg_fsub_nozeros_1:' |
| 479 | |
| 480 | define float @fneg_fsub_nozeros_1(float %x, float %y, float %z) { |
| 481 | ; FMF-LABEL: fneg_fsub_nozeros_1: |
| 482 | ; FMF: # %bb.0: |
Michael Berg | 96925fe | 2018-06-05 18:49:47 +0000 | [diff] [blame] | 483 | ; FMF-NEXT: xssubsp 1, 2, 1 |
Michael Berg | 8f6d6c8 | 2018-06-05 18:12:25 +0000 | [diff] [blame] | 484 | ; FMF-NEXT: blr |
| 485 | ; |
| 486 | ; GLOBAL-LABEL: fneg_fsub_nozeros_1: |
| 487 | ; GLOBAL: # %bb.0: |
Michael Berg | 96925fe | 2018-06-05 18:49:47 +0000 | [diff] [blame] | 488 | ; GLOBAL-NEXT: xssubsp 1, 2, 1 |
Michael Berg | 8f6d6c8 | 2018-06-05 18:12:25 +0000 | [diff] [blame] | 489 | ; GLOBAL-NEXT: blr |
| 490 | %neg = fsub float %x, %y |
Michael Berg | 96925fe | 2018-06-05 18:49:47 +0000 | [diff] [blame] | 491 | %add = fsub nsz float 0.0, %neg |
Michael Berg | 8f6d6c8 | 2018-06-05 18:12:25 +0000 | [diff] [blame] | 492 | ret float %add |
| 493 | } |
Michael Berg | 96925fe | 2018-06-05 18:49:47 +0000 | [diff] [blame] | 494 | |