1 ; RUN: llc < %s | FileCheck %s 2 target triple = "nvptx64-nvidia-cuda" 3 4 ; Checks that llvm intrinsics for math functions are correctly lowered to PTX. 5 6 declare float @llvm.ceil.f32(float) #0 7 declare double @llvm.ceil.f64(double) #0 8 declare float @llvm.floor.f32(float) #0 9 declare double @llvm.floor.f64(double) #0 10 declare float @llvm.round.f32(float) #0 11 declare double @llvm.round.f64(double) #0 12 declare float @llvm.nearbyint.f32(float) #0 13 declare double @llvm.nearbyint.f64(double) #0 14 declare float @llvm.rint.f32(float) #0 15 declare double @llvm.rint.f64(double) #0 16 declare float @llvm.trunc.f32(float) #0 17 declare double @llvm.trunc.f64(double) #0 18 declare float @llvm.fabs.f32(float) #0 19 declare double @llvm.fabs.f64(double) #0 20 declare float @llvm.minnum.f32(float, float) #0 21 declare double @llvm.minnum.f64(double, double) #0 22 declare float @llvm.maxnum.f32(float, float) #0 23 declare double @llvm.maxnum.f64(double, double) #0 24 declare float @llvm.fma.f32(float, float, float) #0 25 declare double @llvm.fma.f64(double, double, double) #0 26 27 ; ---- ceil ---- 28 29 ; CHECK-LABEL: ceil_float 30 define float @ceil_float(float %a) { 31 ; CHECK: cvt.rpi.f32.f32 32 %b = call float @llvm.ceil.f32(float %a) 33 ret float %b 34 } 35 36 ; CHECK-LABEL: ceil_float_ftz 37 define float @ceil_float_ftz(float %a) #1 { 38 ; CHECK: cvt.rpi.ftz.f32.f32 39 %b = call float @llvm.ceil.f32(float %a) 40 ret float %b 41 } 42 43 ; CHECK-LABEL: ceil_double 44 define double @ceil_double(double %a) { 45 ; CHECK: cvt.rpi.f64.f64 46 %b = call double @llvm.ceil.f64(double %a) 47 ret double %b 48 } 49 50 ; ---- floor ---- 51 52 ; CHECK-LABEL: floor_float 53 define float @floor_float(float %a) { 54 ; CHECK: cvt.rmi.f32.f32 55 %b = call float @llvm.floor.f32(float %a) 56 ret float %b 57 } 58 59 ; CHECK-LABEL: floor_float_ftz 60 define float @floor_float_ftz(float %a) #1 { 61 ; CHECK: cvt.rmi.ftz.f32.f32 62 %b = call float @llvm.floor.f32(float %a) 63 ret float %b 64 } 65 66 ; CHECK-LABEL: floor_double 67 define double @floor_double(double %a) { 68 ; CHECK: cvt.rmi.f64.f64 69 %b = call double @llvm.floor.f64(double %a) 70 ret double %b 71 } 72 73 ; ---- round ---- 74 75 ; CHECK-LABEL: round_float 76 define float @round_float(float %a) { 77 ; CHECK: cvt.rni.f32.f32 78 %b = call float @llvm.round.f32(float %a) 79 ret float %b 80 } 81 82 ; CHECK-LABEL: round_float_ftz 83 define float @round_float_ftz(float %a) #1 { 84 ; CHECK: cvt.rni.ftz.f32.f32 85 %b = call float @llvm.round.f32(float %a) 86 ret float %b 87 } 88 89 ; CHECK-LABEL: round_double 90 define double @round_double(double %a) { 91 ; CHECK: cvt.rni.f64.f64 92 %b = call double @llvm.round.f64(double %a) 93 ret double %b 94 } 95 96 ; ---- nearbyint ---- 97 98 ; CHECK-LABEL: nearbyint_float 99 define float @nearbyint_float(float %a) { 100 ; CHECK: cvt.rni.f32.f32 101 %b = call float @llvm.nearbyint.f32(float %a) 102 ret float %b 103 } 104 105 ; CHECK-LABEL: nearbyint_float_ftz 106 define float @nearbyint_float_ftz(float %a) #1 { 107 ; CHECK: cvt.rni.ftz.f32.f32 108 %b = call float @llvm.nearbyint.f32(float %a) 109 ret float %b 110 } 111 112 ; CHECK-LABEL: nearbyint_double 113 define double @nearbyint_double(double %a) { 114 ; CHECK: cvt.rni.f64.f64 115 %b = call double @llvm.nearbyint.f64(double %a) 116 ret double %b 117 } 118 119 ; ---- rint ---- 120 121 ; CHECK-LABEL: rint_float 122 define float @rint_float(float %a) { 123 ; CHECK: cvt.rni.f32.f32 124 %b = call float @llvm.rint.f32(float %a) 125 ret float %b 126 } 127 128 ; CHECK-LABEL: rint_float_ftz 129 define float @rint_float_ftz(float %a) #1 { 130 ; CHECK: cvt.rni.ftz.f32.f32 131 %b = call float @llvm.rint.f32(float %a) 132 ret float %b 133 } 134 135 ; CHECK-LABEL: rint_double 136 define double @rint_double(double %a) { 137 ; CHECK: cvt.rni.f64.f64 138 %b = call double @llvm.rint.f64(double %a) 139 ret double %b 140 } 141 142 ; ---- trunc ---- 143 144 ; CHECK-LABEL: trunc_float 145 define float @trunc_float(float %a) { 146 ; CHECK: cvt.rzi.f32.f32 147 %b = call float @llvm.trunc.f32(float %a) 148 ret float %b 149 } 150 151 ; CHECK-LABEL: trunc_float_ftz 152 define float @trunc_float_ftz(float %a) #1 { 153 ; CHECK: cvt.rzi.ftz.f32.f32 154 %b = call float @llvm.trunc.f32(float %a) 155 ret float %b 156 } 157 158 ; CHECK-LABEL: trunc_double 159 define double @trunc_double(double %a) { 160 ; CHECK: cvt.rzi.f64.f64 161 %b = call double @llvm.trunc.f64(double %a) 162 ret double %b 163 } 164 165 ; ---- abs ---- 166 167 ; CHECK-LABEL: abs_float 168 define float @abs_float(float %a) { 169 ; CHECK: abs.f32 170 %b = call float @llvm.fabs.f32(float %a) 171 ret float %b 172 } 173 174 ; CHECK-LABEL: abs_float_ftz 175 define float @abs_float_ftz(float %a) #1 { 176 ; CHECK: abs.ftz.f32 177 %b = call float @llvm.fabs.f32(float %a) 178 ret float %b 179 } 180 181 ; CHECK-LABEL: abs_double 182 define double @abs_double(double %a) { 183 ; CHECK: abs.f64 184 %b = call double @llvm.fabs.f64(double %a) 185 ret double %b 186 } 187 188 ; ---- min ---- 189 190 ; CHECK-LABEL: min_float 191 define float @min_float(float %a, float %b) { 192 ; CHECK: min.f32 193 %x = call float @llvm.minnum.f32(float %a, float %b) 194 ret float %x 195 } 196 197 ; CHECK-LABEL: min_imm1 198 define float @min_imm1(float %a) { 199 ; CHECK: min.f32 200 %x = call float @llvm.minnum.f32(float %a, float 0.0) 201 ret float %x 202 } 203 204 ; CHECK-LABEL: min_imm2 205 define float @min_imm2(float %a) { 206 ; CHECK: min.f32 207 %x = call float @llvm.minnum.f32(float 0.0, float %a) 208 ret float %x 209 } 210 211 ; CHECK-LABEL: min_float_ftz 212 define float @min_float_ftz(float %a, float %b) #1 { 213 ; CHECK: min.ftz.f32 214 %x = call float @llvm.minnum.f32(float %a, float %b) 215 ret float %x 216 } 217 218 ; CHECK-LABEL: min_double 219 define double @min_double(double %a, double %b) { 220 ; CHECK: min.f64 221 %x = call double @llvm.minnum.f64(double %a, double %b) 222 ret double %x 223 } 224 225 ; ---- max ---- 226 227 ; CHECK-LABEL: max_imm1 228 define float @max_imm1(float %a) { 229 ; CHECK: max.f32 230 %x = call float @llvm.maxnum.f32(float %a, float 0.0) 231 ret float %x 232 } 233 234 ; CHECK-LABEL: max_imm2 235 define float @max_imm2(float %a) { 236 ; CHECK: max.f32 237 %x = call float @llvm.maxnum.f32(float 0.0, float %a) 238 ret float %x 239 } 240 241 ; CHECK-LABEL: max_float 242 define float @max_float(float %a, float %b) { 243 ; CHECK: max.f32 244 %x = call float @llvm.maxnum.f32(float %a, float %b) 245 ret float %x 246 } 247 248 ; CHECK-LABEL: max_float_ftz 249 define float @max_float_ftz(float %a, float %b) #1 { 250 ; CHECK: max.ftz.f32 251 %x = call float @llvm.maxnum.f32(float %a, float %b) 252 ret float %x 253 } 254 255 ; CHECK-LABEL: max_double 256 define double @max_double(double %a, double %b) { 257 ; CHECK: max.f64 258 %x = call double @llvm.maxnum.f64(double %a, double %b) 259 ret double %x 260 } 261 262 ; ---- fma ---- 263 264 ; CHECK-LABEL: @fma_float 265 define float @fma_float(float %a, float %b, float %c) { 266 ; CHECK: fma.rn.f32 267 %x = call float @llvm.fma.f32(float %a, float %b, float %c) 268 ret float %x 269 } 270 271 ; CHECK-LABEL: @fma_float_ftz 272 define float @fma_float_ftz(float %a, float %b, float %c) #1 { 273 ; CHECK: fma.rn.ftz.f32 274 %x = call float @llvm.fma.f32(float %a, float %b, float %c) 275 ret float %x 276 } 277 278 ; CHECK-LABEL: @fma_double 279 define double @fma_double(double %a, double %b, double %c) { 280 ; CHECK: fma.rn.f64 281 %x = call double @llvm.fma.f64(double %a, double %b, double %c) 282 ret double %x 283 } 284 285 attributes #0 = { nounwind readnone } 286 attributes #1 = { "nvptx-f32ftz" = "true" } 287