|
| 1 | +; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5 |
| 2 | +; RUN: opt -passes=instcombine -S < %s | FileCheck %s |
| 3 | + |
| 4 | +declare { float, i32 } @llvm.frexp.f32.i32(float) |
| 5 | +declare void @use(float) |
| 6 | + |
| 7 | +; Basic test case - constant in true position |
| 8 | +define float @test_select_frexp_basic(float %x, i1 %cond) { |
| 9 | +; CHECK-LABEL: define float @test_select_frexp_basic( |
| 10 | +; CHECK-SAME: float [[X:%.*]], i1 [[COND:%.*]]) { |
| 11 | +; CHECK-NEXT: [[FREXP:%.*]] = call { float, i32 } @llvm.frexp.f32.i32(float [[X]]) |
| 12 | +; CHECK-NEXT: [[FREXP_0:%.*]] = extractvalue { float, i32 } [[FREXP]], 0 |
| 13 | +; CHECK-NEXT: [[SELECT_FREXP:%.*]] = select i1 [[COND]], float 5.000000e-01, float [[FREXP_0]] |
| 14 | +; CHECK-NEXT: ret float [[SELECT_FREXP]] |
| 15 | +; |
| 16 | + %sel = select i1 %cond, float 1.000000e+00, float %x |
| 17 | + %frexp = call { float, i32 } @llvm.frexp.f32.i32(float %sel) |
| 18 | + %frexp.0 = extractvalue { float, i32 } %frexp, 0 |
| 19 | + ret float %frexp.0 |
| 20 | +} |
| 21 | + |
| 22 | +; Test with constant in false position |
| 23 | +define float @test_select_frexp_const_false(float %x, i1 %cond) { |
| 24 | +; CHECK-LABEL: define float @test_select_frexp_const_false( |
| 25 | +; CHECK-SAME: float [[X:%.*]], i1 [[COND:%.*]]) { |
| 26 | +; CHECK-NEXT: [[FREXP:%.*]] = call { float, i32 } @llvm.frexp.f32.i32(float [[X]]) |
| 27 | +; CHECK-NEXT: [[FREXP_0:%.*]] = extractvalue { float, i32 } [[FREXP]], 0 |
| 28 | +; CHECK-NEXT: [[SELECT_FREXP:%.*]] = select i1 [[COND]], float [[FREXP_0]], float 5.000000e-01 |
| 29 | +; CHECK-NEXT: ret float [[SELECT_FREXP]] |
| 30 | +; |
| 31 | + %sel = select i1 %cond, float %x, float 1.000000e+00 |
| 32 | + %frexp = call { float, i32 } @llvm.frexp.f32.i32(float %sel) |
| 33 | + %frexp.0 = extractvalue { float, i32 } %frexp, 0 |
| 34 | + ret float %frexp.0 |
| 35 | +} |
| 36 | + |
| 37 | +; Multi-use test |
| 38 | +define float @test_select_frexp_multi_use(float %x, i1 %cond) { |
| 39 | +; CHECK-LABEL: define float @test_select_frexp_multi_use( |
| 40 | +; CHECK-SAME: float [[X:%.*]], i1 [[COND:%.*]]) { |
| 41 | +; CHECK-NEXT: [[SEL:%.*]] = select i1 [[COND]], float 1.000000e+00, float [[X]] |
| 42 | +; CHECK-NEXT: call void @use(float [[SEL]]) |
| 43 | +; CHECK-NEXT: [[FREXP:%.*]] = call { float, i32 } @llvm.frexp.f32.i32(float [[SEL]]) |
| 44 | +; CHECK-NEXT: [[FREXP_0:%.*]] = extractvalue { float, i32 } [[FREXP]], 0 |
| 45 | +; CHECK-NEXT: ret float [[FREXP_0]] |
| 46 | +; |
| 47 | + %sel = select i1 %cond, float 1.000000e+00, float %x |
| 48 | + call void @use(float %sel) |
| 49 | + %frexp = call { float, i32 } @llvm.frexp.f32.i32(float %sel) |
| 50 | + %frexp.0 = extractvalue { float, i32 } %frexp, 0 |
| 51 | + ret float %frexp.0 |
| 52 | +} |
| 53 | + |
| 54 | +; Vector test - splat constant |
| 55 | +define <2 x float> @test_select_frexp_vec_splat(<2 x float> %x, <2 x i1> %cond) { |
| 56 | +; CHECK-LABEL: define <2 x float> @test_select_frexp_vec_splat( |
| 57 | +; CHECK-SAME: <2 x float> [[X:%.*]], <2 x i1> [[COND:%.*]]) { |
| 58 | +; CHECK-NEXT: [[FREXP:%.*]] = call { <2 x float>, <2 x i32> } @llvm.frexp.v2f32.v2i32(<2 x float> [[X]]) |
| 59 | +; CHECK-NEXT: [[FREXP_0:%.*]] = extractvalue { <2 x float>, <2 x i32> } [[FREXP]], 0 |
| 60 | +; CHECK-NEXT: [[SELECT_FREXP:%.*]] = select <2 x i1> [[COND]], <2 x float> splat (float 5.000000e-01), <2 x float> [[FREXP_0]] |
| 61 | +; CHECK-NEXT: ret <2 x float> [[SELECT_FREXP]] |
| 62 | +; |
| 63 | + %sel = select <2 x i1> %cond, <2 x float> <float 1.000000e+00, float 1.000000e+00>, <2 x float> %x |
| 64 | + %frexp = call { <2 x float>, <2 x i32> } @llvm.frexp.v2f32.v2i32(<2 x float> %sel) |
| 65 | + %frexp.0 = extractvalue { <2 x float>, <2 x i32> } %frexp, 0 |
| 66 | + ret <2 x float> %frexp.0 |
| 67 | +} |
| 68 | + |
| 69 | +; Vector test with poison |
| 70 | +define <2 x float> @test_select_frexp_vec_poison(<2 x float> %x, <2 x i1> %cond) { |
| 71 | +; CHECK-LABEL: define <2 x float> @test_select_frexp_vec_poison( |
| 72 | +; CHECK-SAME: <2 x float> [[X:%.*]], <2 x i1> [[COND:%.*]]) { |
| 73 | +; CHECK-NEXT: [[SEL:%.*]] = select <2 x i1> [[COND]], <2 x float> <float 1.000000e+00, float poison>, <2 x float> [[X]] |
| 74 | +; CHECK-NEXT: [[FREXP:%.*]] = call { <2 x float>, <2 x i32> } @llvm.frexp.v2f32.v2i32(<2 x float> [[SEL]]) |
| 75 | +; CHECK-NEXT: [[FREXP_0:%.*]] = extractvalue { <2 x float>, <2 x i32> } [[FREXP]], 0 |
| 76 | +; CHECK-NEXT: ret <2 x float> [[FREXP_0]] |
| 77 | +; |
| 78 | + %sel = select <2 x i1> %cond, <2 x float> <float 1.000000e+00, float poison>, <2 x float> %x |
| 79 | + %frexp = call { <2 x float>, <2 x i32> } @llvm.frexp.v2f32.v2i32(<2 x float> %sel) |
| 80 | + %frexp.0 = extractvalue { <2 x float>, <2 x i32> } %frexp, 0 |
| 81 | + ret <2 x float> %frexp.0 |
| 82 | +} |
| 83 | + |
| 84 | +; Vector test - non-splat (should not fold) |
| 85 | +define <2 x float> @test_select_frexp_vec_nonsplat(<2 x float> %x, <2 x i1> %cond) { |
| 86 | +; CHECK-LABEL: define <2 x float> @test_select_frexp_vec_nonsplat( |
| 87 | +; CHECK-SAME: <2 x float> [[X:%.*]], <2 x i1> [[COND:%.*]]) { |
| 88 | +; CHECK-NEXT: [[SEL:%.*]] = select <2 x i1> [[COND]], <2 x float> <float 1.000000e+00, float 2.000000e+00>, <2 x float> [[X]] |
| 89 | +; CHECK-NEXT: [[FREXP:%.*]] = call { <2 x float>, <2 x i32> } @llvm.frexp.v2f32.v2i32(<2 x float> [[SEL]]) |
| 90 | +; CHECK-NEXT: [[FREXP_0:%.*]] = extractvalue { <2 x float>, <2 x i32> } [[FREXP]], 0 |
| 91 | +; CHECK-NEXT: ret <2 x float> [[FREXP_0]] |
| 92 | +; |
| 93 | + %sel = select <2 x i1> %cond, <2 x float> <float 1.000000e+00, float 2.000000e+00>, <2 x float> %x |
| 94 | + %frexp = call { <2 x float>, <2 x i32> } @llvm.frexp.v2f32.v2i32(<2 x float> %sel) |
| 95 | + %frexp.0 = extractvalue { <2 x float>, <2 x i32> } %frexp, 0 |
| 96 | + ret <2 x float> %frexp.0 |
| 97 | +} |
| 98 | + |
| 99 | +; Negative test - both operands non-constant |
| 100 | +define float @test_select_frexp_no_const(float %x, float %y, i1 %cond) { |
| 101 | +; CHECK-LABEL: define float @test_select_frexp_no_const( |
| 102 | +; CHECK-SAME: float [[X:%.*]], float [[Y:%.*]], i1 [[COND:%.*]]) { |
| 103 | +; CHECK-NEXT: [[SEL:%.*]] = select i1 [[COND]], float [[X]], float [[Y]] |
| 104 | +; CHECK-NEXT: [[FREXP:%.*]] = call { float, i32 } @llvm.frexp.f32.i32(float [[SEL]]) |
| 105 | +; CHECK-NEXT: [[FREXP_0:%.*]] = extractvalue { float, i32 } [[FREXP]], 0 |
| 106 | +; CHECK-NEXT: ret float [[FREXP_0]] |
| 107 | +; |
| 108 | + %sel = select i1 %cond, float %x, float %y |
| 109 | + %frexp = call { float, i32 } @llvm.frexp.f32.i32(float %sel) |
| 110 | + %frexp.0 = extractvalue { float, i32 } %frexp, 0 |
| 111 | + ret float %frexp.0 |
| 112 | +} |
| 113 | + |
| 114 | +; Negative test - extracting exp instead of mantissa |
| 115 | +define i32 @test_select_frexp_extract_exp(float %x, i1 %cond) { |
| 116 | +; CHECK-LABEL: define i32 @test_select_frexp_extract_exp( |
| 117 | +; CHECK-SAME: float [[X:%.*]], i1 [[COND:%.*]]) { |
| 118 | +; CHECK-NEXT: [[SEL:%.*]] = select i1 [[COND]], float 1.000000e+00, float [[X]] |
| 119 | +; CHECK-NEXT: [[FREXP:%.*]] = call { float, i32 } @llvm.frexp.f32.i32(float [[SEL]]) |
| 120 | +; CHECK-NEXT: [[FREXP_1:%.*]] = extractvalue { float, i32 } [[FREXP]], 1 |
| 121 | +; CHECK-NEXT: ret i32 [[FREXP_1]] |
| 122 | +; |
| 123 | + %sel = select i1 %cond, float 1.000000e+00, float %x |
| 124 | + %frexp = call { float, i32 } @llvm.frexp.f32.i32(float %sel) |
| 125 | + %frexp.1 = extractvalue { float, i32 } %frexp, 1 |
| 126 | + ret i32 %frexp.1 |
| 127 | +} |
| 128 | + |
| 129 | +; Test with fast math flags |
| 130 | +define float @test_select_frexp_fast_math_select(float %x, i1 %cond) { |
| 131 | +; CHECK-LABEL: define float @test_select_frexp_fast_math_select( |
| 132 | +; CHECK-SAME: float [[X:%.*]], i1 [[COND:%.*]]) { |
| 133 | +; CHECK-NEXT: [[FREXP1:%.*]] = call { float, i32 } @llvm.frexp.f32.i32(float [[X]]) |
| 134 | +; CHECK-NEXT: [[MANTISSA:%.*]] = extractvalue { float, i32 } [[FREXP1]], 0 |
| 135 | +; CHECK-NEXT: [[SELECT_FREXP:%.*]] = select nnan ninf nsz i1 [[COND]], float 5.000000e-01, float [[MANTISSA]] |
| 136 | +; CHECK-NEXT: ret float [[SELECT_FREXP]] |
| 137 | +; |
| 138 | + %sel = select nnan ninf nsz i1 %cond, float 1.000000e+00, float %x |
| 139 | + %frexp = call { float, i32 } @llvm.frexp.f32.i32(float %sel) |
| 140 | + %frexp.0 = extractvalue { float, i32 } %frexp, 0 |
| 141 | + ret float %frexp.0 |
| 142 | +} |
| 143 | + |
| 144 | + |
| 145 | +; Test vector case with fast math flags |
| 146 | +define <2 x float> @test_select_frexp_vec_fast_math(<2 x float> %x, <2 x i1> %cond) { |
| 147 | +; CHECK-LABEL: define <2 x float> @test_select_frexp_vec_fast_math( |
| 148 | +; CHECK-SAME: <2 x float> [[X:%.*]], <2 x i1> [[COND:%.*]]) { |
| 149 | +; CHECK-NEXT: [[FREXP1:%.*]] = call { <2 x float>, <2 x i32> } @llvm.frexp.v2f32.v2i32(<2 x float> [[X]]) |
| 150 | +; CHECK-NEXT: [[MANTISSA:%.*]] = extractvalue { <2 x float>, <2 x i32> } [[FREXP1]], 0 |
| 151 | +; CHECK-NEXT: [[SELECT_FREXP:%.*]] = select nnan ninf nsz <2 x i1> [[COND]], <2 x float> splat (float 5.000000e-01), <2 x float> [[MANTISSA]] |
| 152 | +; CHECK-NEXT: ret <2 x float> [[SELECT_FREXP]] |
| 153 | +; |
| 154 | + %sel = select nnan ninf nsz <2 x i1> %cond, <2 x float> <float 1.000000e+00, float 1.000000e+00>, <2 x float> %x |
| 155 | + %frexp = call { <2 x float>, <2 x i32> } @llvm.frexp.v2f32.v2i32(<2 x float> %sel) |
| 156 | + %frexp.0 = extractvalue { <2 x float>, <2 x i32> } %frexp, 0 |
| 157 | + ret <2 x float> %frexp.0 |
| 158 | +} |
| 159 | + |
| 160 | +; Test with scalable vectors with constant at True Position |
| 161 | +define <vscale x 2 x float> @test_select_frexp_scalable_vec0(<vscale x 2 x float> %x, <vscale x 2 x i1> %cond) { |
| 162 | +; CHECK-LABEL: define <vscale x 2 x float> @test_select_frexp_scalable_vec0( |
| 163 | +; CHECK-SAME: <vscale x 2 x float> [[X:%.*]], <vscale x 2 x i1> [[COND:%.*]]) { |
| 164 | +; CHECK-NEXT: [[FREXP1:%.*]] = call { <vscale x 2 x float>, <vscale x 2 x i32> } @llvm.frexp.nxv2f32.nxv2i32(<vscale x 2 x float> [[X]]) |
| 165 | +; CHECK-NEXT: [[MANTISSA:%.*]] = extractvalue { <vscale x 2 x float>, <vscale x 2 x i32> } [[FREXP1]], 0 |
| 166 | +; CHECK-NEXT: [[SELECT_FREXP:%.*]] = select <vscale x 2 x i1> [[COND]], <vscale x 2 x float> splat (float 5.000000e-01), <vscale x 2 x float> [[MANTISSA]] |
| 167 | +; CHECK-NEXT: ret <vscale x 2 x float> [[SELECT_FREXP]] |
| 168 | +; |
| 169 | + %sel = select <vscale x 2 x i1> %cond, <vscale x 2 x float> splat (float 1.000000e+00), <vscale x 2 x float> %x |
| 170 | + %frexp = call { <vscale x 2 x float>, <vscale x 2 x i32> } @llvm.frexp.nxv2f32.nxv2i32(<vscale x 2 x float> %sel) |
| 171 | + %frexp.0 = extractvalue { <vscale x 2 x float>, <vscale x 2 x i32> } %frexp, 0 |
| 172 | + ret <vscale x 2 x float> %frexp.0 |
| 173 | +} |
| 174 | + |
| 175 | +; Test with scalable vectors with constant at False Position |
| 176 | +define <vscale x 2 x float> @test_select_frexp_scalable_vec1(<vscale x 2 x float> %x, <vscale x 2 x i1> %cond) { |
| 177 | +; CHECK-LABEL: define <vscale x 2 x float> @test_select_frexp_scalable_vec1( |
| 178 | +; CHECK-SAME: <vscale x 2 x float> [[X:%.*]], <vscale x 2 x i1> [[COND:%.*]]) { |
| 179 | +; CHECK-NEXT: [[FREXP1:%.*]] = call { <vscale x 2 x float>, <vscale x 2 x i32> } @llvm.frexp.nxv2f32.nxv2i32(<vscale x 2 x float> [[X]]) |
| 180 | +; CHECK-NEXT: [[MANTISSA:%.*]] = extractvalue { <vscale x 2 x float>, <vscale x 2 x i32> } [[FREXP1]], 0 |
| 181 | +; CHECK-NEXT: [[SELECT_FREXP:%.*]] = select <vscale x 2 x i1> [[COND]], <vscale x 2 x float> [[MANTISSA]], <vscale x 2 x float> splat (float 5.000000e-01) |
| 182 | +; CHECK-NEXT: ret <vscale x 2 x float> [[SELECT_FREXP]] |
| 183 | +; |
| 184 | + %sel = select <vscale x 2 x i1> %cond, <vscale x 2 x float> %x, <vscale x 2 x float> splat (float 1.000000e+00) |
| 185 | + %frexp = call { <vscale x 2 x float>, <vscale x 2 x i32> } @llvm.frexp.nxv2f32.nxv2i32(<vscale x 2 x float> %sel) |
| 186 | + %frexp.0 = extractvalue { <vscale x 2 x float>, <vscale x 2 x i32> } %frexp, 0 |
| 187 | + ret <vscale x 2 x float> %frexp.0 |
| 188 | +} |
| 189 | + |
| 190 | +declare { <2 x float>, <2 x i32> } @llvm.frexp.v2f32.v2i32(<2 x float>) |
| 191 | +declare { <vscale x 2 x float>, <vscale x 2 x i32> } @llvm.frexp.nxv2f32.nxv2i32(<vscale x 2 x float>) |
0 commit comments