|
| 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: [[SEL:%.*]] = select i1 [[COND]], float 1.000000e+00, float [[X]] |
| 12 | +; CHECK-NEXT: [[FREXP:%.*]] = call { float, i32 } @llvm.frexp.f32.i32(float [[SEL]]) |
| 13 | +; CHECK-NEXT: [[FREXP_0:%.*]] = extractvalue { float, i32 } [[FREXP]], 0 |
| 14 | +; CHECK-NEXT: ret float [[FREXP_0]] |
| 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: [[SEL:%.*]] = select i1 [[COND]], float [[X]], float 1.000000e+00 |
| 27 | +; CHECK-NEXT: [[FREXP:%.*]] = call { float, i32 } @llvm.frexp.f32.i32(float [[SEL]]) |
| 28 | +; CHECK-NEXT: [[FREXP_0:%.*]] = extractvalue { float, i32 } [[FREXP]], 0 |
| 29 | +; CHECK-NEXT: ret float [[FREXP_0]] |
| 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: [[SEL:%.*]] = select <2 x i1> [[COND]], <2 x float> splat (float 1.000000e+00), <2 x float> [[X]] |
| 59 | +; CHECK-NEXT: [[FREXP:%.*]] = call { <2 x float>, <2 x i32> } @llvm.frexp.v2f32.v2i32(<2 x float> [[SEL]]) |
| 60 | +; CHECK-NEXT: [[FREXP_0:%.*]] = extractvalue { <2 x float>, <2 x i32> } [[FREXP]], 0 |
| 61 | +; CHECK-NEXT: ret <2 x float> [[FREXP_0]] |
| 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 | +declare { <2 x float>, <2 x i32> } @llvm.frexp.v2f32.v2i32(<2 x float>) |
0 commit comments