Justin Lebar | 1c9692a | 2017-01-31 05:58:22 +0000 | [diff] [blame] | 1 | ; RUN: llc < %s -march=nvptx -mcpu=sm_20 -nvptx-prec-divf32=0 -nvptx-prec-sqrtf32=0 \ |
| 2 | ; RUN: | FileCheck %s |
| 3 | |
| 4 | target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v16:16:16-v32:32:32-v64:64:64-v128:128:128-n16:32:64" |
| 5 | |
| 6 | declare float @llvm.sqrt.f32(float) |
| 7 | declare double @llvm.sqrt.f64(double) |
| 8 | |
| 9 | ; -- reciprocal sqrt -- |
| 10 | |
| 11 | ; CHECK-LABEL test_rsqrt32 |
| 12 | define float @test_rsqrt32(float %a) #0 { |
| 13 | ; CHECK: rsqrt.approx.f32 |
| 14 | %val = tail call float @llvm.sqrt.f32(float %a) |
| 15 | %ret = fdiv float 1.0, %val |
| 16 | ret float %ret |
| 17 | } |
| 18 | |
| 19 | ; CHECK-LABEL test_rsqrt_ftz |
| 20 | define float @test_rsqrt_ftz(float %a) #0 #1 { |
| 21 | ; CHECK: rsqrt.approx.ftz.f32 |
| 22 | %val = tail call float @llvm.sqrt.f32(float %a) |
| 23 | %ret = fdiv float 1.0, %val |
| 24 | ret float %ret |
| 25 | } |
| 26 | |
| 27 | ; CHECK-LABEL test_rsqrt64 |
| 28 | define double @test_rsqrt64(double %a) #0 { |
| 29 | ; CHECK: rsqrt.approx.f64 |
| 30 | %val = tail call double @llvm.sqrt.f64(double %a) |
| 31 | %ret = fdiv double 1.0, %val |
| 32 | ret double %ret |
| 33 | } |
| 34 | |
| 35 | ; CHECK-LABEL test_rsqrt64_ftz |
| 36 | define double @test_rsqrt64_ftz(double %a) #0 #1 { |
| 37 | ; There's no rsqrt.approx.ftz.f64 instruction; we just use the non-ftz version. |
| 38 | ; CHECK: rsqrt.approx.f64 |
| 39 | %val = tail call double @llvm.sqrt.f64(double %a) |
| 40 | %ret = fdiv double 1.0, %val |
| 41 | ret double %ret |
| 42 | } |
| 43 | |
| 44 | ; -- sqrt -- |
| 45 | |
| 46 | ; CHECK-LABEL test_sqrt32 |
| 47 | define float @test_sqrt32(float %a) #0 { |
| 48 | ; CHECK: sqrt.approx.f32 |
| 49 | %ret = tail call float @llvm.sqrt.f32(float %a) |
| 50 | ret float %ret |
| 51 | } |
| 52 | |
| 53 | ; CHECK-LABEL test_sqrt_ftz |
| 54 | define float @test_sqrt_ftz(float %a) #0 #1 { |
| 55 | ; CHECK: sqrt.approx.ftz.f32 |
| 56 | %ret = tail call float @llvm.sqrt.f32(float %a) |
| 57 | ret float %ret |
| 58 | } |
| 59 | |
| 60 | ; CHECK-LABEL test_sqrt64 |
| 61 | define double @test_sqrt64(double %a) #0 { |
| 62 | ; There's no sqrt.approx.f64 instruction; we emit x * rsqrt.approx.f64(x). |
| 63 | ; CHECK: rsqrt.approx.f64 |
| 64 | ; CHECK: mul.f64 |
| 65 | %ret = tail call double @llvm.sqrt.f64(double %a) |
| 66 | ret double %ret |
| 67 | } |
| 68 | |
| 69 | ; CHECK-LABEL test_sqrt64_ftz |
| 70 | define double @test_sqrt64_ftz(double %a) #0 #1 { |
| 71 | ; There's no sqrt.approx.ftz.f64 instruction; we just use the non-ftz version. |
| 72 | ; CHECK: rsqrt.approx.f64 |
| 73 | ; CHECK: mul.f64 |
| 74 | %ret = tail call double @llvm.sqrt.f64(double %a) |
| 75 | ret double %ret |
| 76 | } |
| 77 | |
| 78 | ; -- refined sqrt and rsqrt -- |
| 79 | ; |
| 80 | ; The sqrt and rsqrt refinement algorithms both emit an rsqrt.approx, followed |
| 81 | ; by some math. |
| 82 | |
| 83 | ; CHECK-LABEL: test_rsqrt32_refined |
| 84 | define float @test_rsqrt32_refined(float %a) #0 #2 { |
| 85 | ; CHECK: rsqrt.approx.f32 |
| 86 | %val = tail call float @llvm.sqrt.f32(float %a) |
| 87 | %ret = fdiv float 1.0, %val |
| 88 | ret float %ret |
| 89 | } |
| 90 | |
| 91 | ; CHECK-LABEL: test_sqrt32_refined |
| 92 | define float @test_sqrt32_refined(float %a) #0 #2 { |
| 93 | ; CHECK: rsqrt.approx.f32 |
| 94 | %ret = tail call float @llvm.sqrt.f32(float %a) |
| 95 | ret float %ret |
| 96 | } |
| 97 | |
| 98 | ; CHECK-LABEL: test_rsqrt64_refined |
| 99 | define double @test_rsqrt64_refined(double %a) #0 #2 { |
| 100 | ; CHECK: rsqrt.approx.f64 |
| 101 | %val = tail call double @llvm.sqrt.f64(double %a) |
| 102 | %ret = fdiv double 1.0, %val |
| 103 | ret double %ret |
| 104 | } |
| 105 | |
| 106 | ; CHECK-LABEL: test_sqrt64_refined |
| 107 | define double @test_sqrt64_refined(double %a) #0 #2 { |
| 108 | ; CHECK: rsqrt.approx.f64 |
| 109 | %ret = tail call double @llvm.sqrt.f64(double %a) |
| 110 | ret double %ret |
| 111 | } |
| 112 | |
| 113 | ; -- refined sqrt and rsqrt with ftz enabled -- |
| 114 | |
| 115 | ; CHECK-LABEL: test_rsqrt32_refined_ftz |
| 116 | define float @test_rsqrt32_refined_ftz(float %a) #0 #1 #2 { |
| 117 | ; CHECK: rsqrt.approx.ftz.f32 |
| 118 | %val = tail call float @llvm.sqrt.f32(float %a) |
| 119 | %ret = fdiv float 1.0, %val |
| 120 | ret float %ret |
| 121 | } |
| 122 | |
| 123 | ; CHECK-LABEL: test_sqrt32_refined_ftz |
| 124 | define float @test_sqrt32_refined_ftz(float %a) #0 #1 #2 { |
| 125 | ; CHECK: rsqrt.approx.ftz.f32 |
| 126 | %ret = tail call float @llvm.sqrt.f32(float %a) |
| 127 | ret float %ret |
| 128 | } |
| 129 | |
| 130 | ; CHECK-LABEL: test_rsqrt64_refined_ftz |
| 131 | define double @test_rsqrt64_refined_ftz(double %a) #0 #1 #2 { |
| 132 | ; There's no rsqrt.approx.ftz.f64, so we just use the non-ftz version. |
| 133 | ; CHECK: rsqrt.approx.f64 |
| 134 | %val = tail call double @llvm.sqrt.f64(double %a) |
| 135 | %ret = fdiv double 1.0, %val |
| 136 | ret double %ret |
| 137 | } |
| 138 | |
| 139 | ; CHECK-LABEL: test_sqrt64_refined_ftz |
| 140 | define double @test_sqrt64_refined_ftz(double %a) #0 #1 #2 { |
| 141 | ; CHECK: rsqrt.approx.f64 |
| 142 | %ret = tail call double @llvm.sqrt.f64(double %a) |
| 143 | ret double %ret |
| 144 | } |
| 145 | |
| 146 | attributes #0 = { "unsafe-fp-math" = "true" } |
| 147 | attributes #1 = { "nvptx-f32ftz" = "true" } |
| 148 | attributes #2 = { "reciprocal-estimates" = "rsqrtf:1,rsqrtd:1,sqrtf:1,sqrtd:1" } |