brintos

brintos / llvm-project-archived public Read only

0
0
Text · 5.3 KiB · e1d39fd Raw
143 lines · plain
1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py2; RUN: opt < %s -passes=instcombine -S | FileCheck %s3 4define double @x(i32 %a, i32 %b) {5; CHECK-LABEL: @x(6; CHECK-NEXT:    [[M:%.*]] = lshr i32 [[A:%.*]], 247; CHECK-NEXT:    [[N:%.*]] = and i32 [[M]], [[B:%.*]]8; CHECK-NEXT:    [[TMP1:%.*]] = add nuw nsw i32 [[N]], 19; CHECK-NEXT:    [[P:%.*]] = uitofp nneg i32 [[TMP1]] to double10; CHECK-NEXT:    ret double [[P]]11;12  %m = lshr i32 %a, 2413  %n = and i32 %m, %b14  %o = sitofp i32 %n to double15  %p = fadd double %o, 1.016  ret double %p17}18 19define double @test(i32 %a) {20; CHECK-LABEL: @test(21; CHECK-NEXT:    [[A_AND:%.*]] = and i32 [[A:%.*]], 107374182322; CHECK-NEXT:    [[TMP1:%.*]] = add nuw nsw i32 [[A_AND]], 123; CHECK-NEXT:    [[RES:%.*]] = uitofp nneg i32 [[TMP1]] to double24; CHECK-NEXT:    ret double [[RES]]25;26  ; Drop two highest bits to guarantee that %a + 1 doesn't overflow27  %a_and = and i32 %a, 107374182328  %a_and_fp = sitofp i32 %a_and to double29  %res = fadd double %a_and_fp, 1.030  ret double %res31}32 33define float @test_neg(i32 %a) {34; CHECK-LABEL: @test_neg(35; CHECK-NEXT:    [[A_AND:%.*]] = and i32 [[A:%.*]], 107374182336; CHECK-NEXT:    [[A_AND_FP:%.*]] = uitofp nneg i32 [[A_AND]] to float37; CHECK-NEXT:    [[RES:%.*]] = fadd float [[A_AND_FP]], 1.000000e+0038; CHECK-NEXT:    ret float [[RES]]39;40  ; Drop two highest bits to guarantee that %a + 1 doesn't overflow41  %a_and = and i32 %a, 107374182342  %a_and_fp = sitofp i32 %a_and to float43  %res = fadd float %a_and_fp, 1.044  ret float %res45}46 47define double @test_2(i32 %a, i32 %b) {48; CHECK-LABEL: @test_2(49; CHECK-NEXT:    [[A_AND:%.*]] = and i32 [[A:%.*]], 107374182350; CHECK-NEXT:    [[B_AND:%.*]] = and i32 [[B:%.*]], 107374182351; CHECK-NEXT:    [[TMP1:%.*]] = add nuw nsw i32 [[A_AND]], [[B_AND]]52; CHECK-NEXT:    [[RES:%.*]] = uitofp nneg i32 [[TMP1]] to double53; CHECK-NEXT:    ret double [[RES]]54;55  ; Drop two highest bits to guarantee that %a + %b doesn't overflow56  %a_and = and i32 %a, 107374182357  %b_and = and i32 %b, 107374182358 59  %a_and_fp = sitofp i32 %a_and to double60  %b_and_fp = sitofp i32 %b_and to double61 62  %res = fadd double %a_and_fp, %b_and_fp63  ret double %res64}65 66define float @test_2_neg(i32 %a, i32 %b) {67; CHECK-LABEL: @test_2_neg(68; CHECK-NEXT:    [[A_AND:%.*]] = and i32 [[A:%.*]], 107374182369; CHECK-NEXT:    [[B_AND:%.*]] = and i32 [[B:%.*]], 107374182370; CHECK-NEXT:    [[A_AND_FP:%.*]] = uitofp nneg i32 [[A_AND]] to float71; CHECK-NEXT:    [[B_AND_FP:%.*]] = uitofp nneg i32 [[B_AND]] to float72; CHECK-NEXT:    [[RES:%.*]] = fadd float [[A_AND_FP]], [[B_AND_FP]]73; CHECK-NEXT:    ret float [[RES]]74;75  ; Drop two highest bits to guarantee that %a + %b doesn't overflow76  %a_and = and i32 %a, 107374182377  %b_and = and i32 %b, 107374182378 79  %a_and_fp = sitofp i32 %a_and to float80  %b_and_fp = sitofp i32 %b_and to float81 82  %res = fadd float %a_and_fp, %b_and_fp83  ret float %res84}85 86; can be represented in float.87define float @test_3(i32 %a, i32 %b) {88; CHECK-LABEL: @test_3(89; CHECK-NEXT:    [[M:%.*]] = lshr i32 [[A:%.*]], 2490; CHECK-NEXT:    [[N:%.*]] = and i32 [[M]], [[B:%.*]]91; CHECK-NEXT:    [[TMP1:%.*]] = add nuw nsw i32 [[N]], 192; CHECK-NEXT:    [[P:%.*]] = uitofp nneg i32 [[TMP1]] to float93; CHECK-NEXT:    ret float [[P]]94;95  %m = lshr i32 %a, 2496  %n = and i32 %m, %b97  %o = sitofp i32 %n to float98  %p = fadd float %o, 1.099  ret float %p100}101 102; Don't perform the fold on vector operations, as the integer op may be103; much more expensive than the float op in that case.104define <4 x double> @test_4(<4 x i32> %a, <4 x i32> %b) {105; CHECK-LABEL: @test_4(106; CHECK-NEXT:    [[A_AND:%.*]] = and <4 x i32> [[A:%.*]], splat (i32 1073741823)107; CHECK-NEXT:    [[B_AND:%.*]] = and <4 x i32> [[B:%.*]], splat (i32 1073741823)108; CHECK-NEXT:    [[A_AND_FP:%.*]] = uitofp nneg <4 x i32> [[A_AND]] to <4 x double>109; CHECK-NEXT:    [[B_AND_FP:%.*]] = uitofp nneg <4 x i32> [[B_AND]] to <4 x double>110; CHECK-NEXT:    [[RES:%.*]] = fadd <4 x double> [[A_AND_FP]], [[B_AND_FP]]111; CHECK-NEXT:    ret <4 x double> [[RES]]112;113  ; Drop two highest bits to guarantee that %a + %b doesn't overflow114  %a_and = and <4 x i32> %a, <i32 1073741823, i32 1073741823, i32 1073741823, i32 1073741823>115  %b_and = and <4 x i32> %b, <i32 1073741823, i32 1073741823, i32 1073741823, i32 1073741823>116 117  %a_and_fp = sitofp <4 x i32> %a_and to <4 x double>118  %b_and_fp = sitofp <4 x i32> %b_and to <4 x double>119 120  %res = fadd <4 x double> %a_and_fp, %b_and_fp121  ret <4 x double> %res122}123 124define <4 x float> @test_4_neg(<4 x i32> %a, <4 x i32> %b) {125; CHECK-LABEL: @test_4_neg(126; CHECK-NEXT:    [[A_AND:%.*]] = and <4 x i32> [[A:%.*]], splat (i32 1073741823)127; CHECK-NEXT:    [[B_AND:%.*]] = and <4 x i32> [[B:%.*]], splat (i32 1073741823)128; CHECK-NEXT:    [[A_AND_FP:%.*]] = uitofp nneg <4 x i32> [[A_AND]] to <4 x float>129; CHECK-NEXT:    [[B_AND_FP:%.*]] = uitofp nneg <4 x i32> [[B_AND]] to <4 x float>130; CHECK-NEXT:    [[RES:%.*]] = fadd <4 x float> [[A_AND_FP]], [[B_AND_FP]]131; CHECK-NEXT:    ret <4 x float> [[RES]]132;133  ; Drop two highest bits to guarantee that %a + %b doesn't overflow134  %a_and = and <4 x i32> %a, <i32 1073741823, i32 1073741823, i32 1073741823, i32 1073741823>135  %b_and = and <4 x i32> %b, <i32 1073741823, i32 1073741823, i32 1073741823, i32 1073741823>136 137  %a_and_fp = sitofp <4 x i32> %a_and to <4 x float>138  %b_and_fp = sitofp <4 x i32> %b_and to <4 x float>139 140  %res = fadd <4 x float> %a_and_fp, %b_and_fp141  ret <4 x float> %res142}143