brintos

brintos / llvm-project-archived public Read only

0
0
Text · 10.4 KiB · ccfcca1 Raw
192 lines · plain
1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 52; RUN: opt -passes=instcombine -S < %s | FileCheck %s3 4declare { float, i32 } @llvm.frexp.f32.i32(float)5declare void @use(float)6 7; Basic test case - constant in true position8define 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]], 013; 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 %x17  %frexp = call { float, i32 } @llvm.frexp.f32.i32(float %sel)18  %frexp.0 = extractvalue { float, i32 } %frexp, 019  ret float %frexp.020}21 22; Test with constant in false position23define 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]], 028; CHECK-NEXT:    [[SELECT_FREXP:%.*]] = select i1 [[COND]], float [[FREXP_0]], float 5.000000e-0129; CHECK-NEXT:    ret float [[SELECT_FREXP]]30;31  %sel = select i1 %cond, float %x, float 1.000000e+0032  %frexp = call { float, i32 } @llvm.frexp.f32.i32(float %sel)33  %frexp.0 = extractvalue { float, i32 } %frexp, 034  ret float %frexp.035}36 37; Multi-use test38define 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]], 045; CHECK-NEXT:    ret float [[FREXP_0]]46;47  %sel = select i1 %cond, float 1.000000e+00, float %x48  call void @use(float %sel)49  %frexp = call { float, i32 } @llvm.frexp.f32.i32(float %sel)50  %frexp.0 = extractvalue { float, i32 } %frexp, 051  ret float %frexp.052}53 54; Vector test - splat constant55define <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]], 060; 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> %x64  %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, 066  ret <2 x float> %frexp.067}68 69; Vector test with poison70define <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]], 076; 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> %x79  %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, 081  ret <2 x float> %frexp.082}83 84; Vector test - non-splat (should not fold)85define <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]], 091; 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> %x94  %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, 096  ret <2 x float> %frexp.097}98 99; Negative test - both operands non-constant100define 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]], 0106; CHECK-NEXT:    ret float [[FREXP_0]]107;108  %sel = select i1 %cond, float %x, float %y109  %frexp = call { float, i32 } @llvm.frexp.f32.i32(float %sel)110  %frexp.0 = extractvalue { float, i32 } %frexp, 0111  ret float %frexp.0112}113 114; Negative test - extracting exp instead of mantissa115define 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:    [[FREXP:%.*]] = call { float, i32 } @llvm.frexp.f32.i32(float [[X]])119; CHECK-NEXT:    [[FREXP_1:%.*]] = extractvalue { float, i32 } [[FREXP]], 1120; CHECK-NEXT:    [[FREXP_2:%.*]] = select i1 [[COND]], i32 1, i32 [[FREXP_1]]121; CHECK-NEXT:    ret i32 [[FREXP_2]]122;123  %sel = select i1 %cond, float 1.000000e+00, float %x124  %frexp = call { float, i32 } @llvm.frexp.f32.i32(float %sel)125  %frexp.1 = extractvalue { float, i32 } %frexp, 1126  ret i32 %frexp.1127}128 129; Test with fast math flags130define 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]], 0135; CHECK-NEXT:    [[SELECT_FREXP:%.*]] = select 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 %x139  %frexp = call { float, i32 } @llvm.frexp.f32.i32(float %sel)140  %frexp.0 = extractvalue { float, i32 } %frexp, 0141  ret float %frexp.0142}143 144 145; Test vector case with fast math flags146define <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]], 0151; 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> %x155  %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, 0157  ret <2 x float> %frexp.0158}159 160; Test with scalable vectors with constant at True Position161define <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]], 0166; 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> %x170  %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, 0172  ret <vscale x 2 x float> %frexp.0173}174 175; Test with scalable vectors with constant at False Position176define <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]], 0181; 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, 0187  ret <vscale x 2 x float> %frexp.0188}189 190declare { <2 x float>, <2 x i32> } @llvm.frexp.v2f32.v2i32(<2 x float>)191declare { <vscale x 2 x float>, <vscale x 2 x i32> } @llvm.frexp.nxv2f32.nxv2i32(<vscale x 2 x float>)192