brintos

brintos / llvm-project-archived public Read only

0
0
Text · 8.1 KiB · 19de1ad Raw
278 lines · plain
1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py2; RUN: opt < %s -passes=instcombine -S | FileCheck %s3 4target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"5 6; %a is negative, %b is positive7define i16 @oppositesign(i16 %x, i16 %y) {8; CHECK-LABEL: @oppositesign(9; CHECK-NEXT:    [[A:%.*]] = or i16 [[X:%.*]], -3276810; CHECK-NEXT:    [[B:%.*]] = and i16 [[Y:%.*]], 3276711; CHECK-NEXT:    [[C:%.*]] = add nsw i16 [[A]], [[B]]12; CHECK-NEXT:    ret i16 [[C]]13;14  %a = or i16 %x, 3276815  %b = and i16 %y, 3276716  %c = add i16 %a, %b17  ret i16 %c18}19 20define i16 @zero_sign_bit(i16 %a) {21; CHECK-LABEL: @zero_sign_bit(22; CHECK-NEXT:    [[TMP1:%.*]] = and i16 [[A:%.*]], 3276723; CHECK-NEXT:    [[TMP2:%.*]] = add nuw i16 [[TMP1]], 51224; CHECK-NEXT:    ret i16 [[TMP2]]25;26  %1 = and i16 %a, 3276727  %2 = add i16 %1, 51228  ret i16 %229}30 31define i16 @zero_sign_bit2(i16 %a, i16 %b) {32; CHECK-LABEL: @zero_sign_bit2(33; CHECK-NEXT:    [[TMP1:%.*]] = and i16 [[A:%.*]], 3276734; CHECK-NEXT:    [[TMP2:%.*]] = and i16 [[B:%.*]], 3276735; CHECK-NEXT:    [[TMP3:%.*]] = add nuw i16 [[TMP1]], [[TMP2]]36; CHECK-NEXT:    ret i16 [[TMP3]]37;38  %1 = and i16 %a, 3276739  %2 = and i16 %b, 3276740  %3 = add i16 %1, %241  ret i16 %342}43 44declare i16 @bounded(i16 %input);45declare i32 @__gxx_personality_v0(...);46!0 = !{i16 0, i16 32768} ; [0, 32767]47!1 = !{i16 0, i16 32769} ; [0, 32768]48 49define i16 @add_bounded_values(i16 %a, i16 %b) personality ptr @__gxx_personality_v0 {50; CHECK-LABEL: @add_bounded_values(51; CHECK-NEXT:  entry:52; CHECK-NEXT:    [[C:%.*]] = call i16 @bounded(i16 [[A:%.*]]), !range [[RNG0:![0-9]+]]53; CHECK-NEXT:    [[D:%.*]] = invoke i16 @bounded(i16 [[B:%.*]])54; CHECK-NEXT:    to label [[CONT:%.*]] unwind label [[LPAD:%.*]], !range [[RNG0]]55; CHECK:       cont:56; CHECK-NEXT:    [[E:%.*]] = add nuw i16 [[C]], [[D]]57; CHECK-NEXT:    ret i16 [[E]]58; CHECK:       lpad:59; CHECK-NEXT:    [[TMP0:%.*]] = landingpad { ptr, i32 }60; CHECK-NEXT:    filter [0 x ptr] zeroinitializer61; CHECK-NEXT:    ret i16 4262;63entry:64  %c = call i16 @bounded(i16 %a), !range !065  %d = invoke i16 @bounded(i16 %b) to label %cont unwind label %lpad, !range !066cont:67; %c and %d are in [0, 32767]. Therefore, %c + %d doesn't unsigned overflow.68  %e = add i16 %c, %d69  ret i16 %e70lpad:71  %0 = landingpad { ptr, i32 }72  filter [0 x ptr] zeroinitializer73  ret i16 4274}75 76define i16 @add_bounded_values_2(i16 %a, i16 %b) personality ptr @__gxx_personality_v0 {77; CHECK-LABEL: @add_bounded_values_2(78; CHECK-NEXT:  entry:79; CHECK-NEXT:    [[C:%.*]] = call i16 @bounded(i16 [[A:%.*]]), !range [[RNG1:![0-9]+]]80; CHECK-NEXT:    [[D:%.*]] = invoke i16 @bounded(i16 [[B:%.*]])81; CHECK-NEXT:    to label [[CONT:%.*]] unwind label [[LPAD:%.*]], !range [[RNG1]]82; CHECK:       cont:83; CHECK-NEXT:    [[E:%.*]] = add i16 [[C]], [[D]]84; CHECK-NEXT:    ret i16 [[E]]85; CHECK:       lpad:86; CHECK-NEXT:    [[TMP0:%.*]] = landingpad { ptr, i32 }87; CHECK-NEXT:    filter [0 x ptr] zeroinitializer88; CHECK-NEXT:    ret i16 4289;90entry:91  %c = call i16 @bounded(i16 %a), !range !192  %d = invoke i16 @bounded(i16 %b) to label %cont unwind label %lpad, !range !193cont:94; Similar to add_bounded_values, but %c and %d are in [0, 32768]. Therefore,95; %c + %d may unsigned overflow and we cannot add NUW.96  %e = add i16 %c, %d97  ret i16 %e98lpad:99  %0 = landingpad { ptr, i32 }100  filter [0 x ptr] zeroinitializer101  ret i16 42102}103 104; %a has at most one bit set105; %b has a 0 bit other than the sign bit106define i16 @ripple_nsw1(i16 %x, i16 %y) {107; CHECK-LABEL: @ripple_nsw1(108; CHECK-NEXT:    [[A:%.*]] = and i16 [[Y:%.*]], 1109; CHECK-NEXT:    [[B:%.*]] = and i16 [[X:%.*]], -16385110; CHECK-NEXT:    [[C:%.*]] = add nuw nsw i16 [[A]], [[B]]111; CHECK-NEXT:    ret i16 [[C]]112;113  %a = and i16 %y, 1114  %b = and i16 %x, 49151115  %c = add i16 %a, %b116  ret i16 %c117}118 119; Like the previous test, but flip %a and %b120define i16 @ripple_nsw2(i16 %x, i16 %y) {121; CHECK-LABEL: @ripple_nsw2(122; CHECK-NEXT:    [[A:%.*]] = and i16 [[Y:%.*]], 1123; CHECK-NEXT:    [[B:%.*]] = and i16 [[X:%.*]], -16385124; CHECK-NEXT:    [[C:%.*]] = add nuw nsw i16 [[B]], [[A]]125; CHECK-NEXT:    ret i16 [[C]]126;127  %a = and i16 %y, 1128  %b = and i16 %x, 49151129  %c = add i16 %b, %a130  ret i16 %c131}132 133define i16 @ripple_nsw3(i16 %x, i16 %y) {134; CHECK-LABEL: @ripple_nsw3(135; CHECK-NEXT:    [[A:%.*]] = and i16 [[Y:%.*]], -21845136; CHECK-NEXT:    [[B:%.*]] = and i16 [[X:%.*]], 21843137; CHECK-NEXT:    [[C:%.*]] = add nuw nsw i16 [[A]], [[B]]138; CHECK-NEXT:    ret i16 [[C]]139;140  %a = and i16 %y, 43691141  %b = and i16 %x, 21843142  %c = add i16 %a, %b143  ret i16 %c144}145 146; Like the previous test, but flip %a and %b147define i16 @ripple_nsw4(i16 %x, i16 %y) {148; CHECK-LABEL: @ripple_nsw4(149; CHECK-NEXT:    [[A:%.*]] = and i16 [[Y:%.*]], -21845150; CHECK-NEXT:    [[B:%.*]] = and i16 [[X:%.*]], 21843151; CHECK-NEXT:    [[C:%.*]] = add nuw nsw i16 [[B]], [[A]]152; CHECK-NEXT:    ret i16 [[C]]153;154  %a = and i16 %y, 43691155  %b = and i16 %x, 21843156  %c = add i16 %b, %a157  ret i16 %c158}159 160define i16 @ripple_nsw5(i16 %x, i16 %y) {161; CHECK-LABEL: @ripple_nsw5(162; CHECK-NEXT:    [[A:%.*]] = or i16 [[Y:%.*]], -21845163; CHECK-NEXT:    [[B:%.*]] = or i16 [[X:%.*]], -10923164; CHECK-NEXT:    [[C:%.*]] = add nsw i16 [[A]], [[B]]165; CHECK-NEXT:    ret i16 [[C]]166;167  %a = or i16 %y, 43691168  %b = or i16 %x, 54613169  %c = add i16 %a, %b170  ret i16 %c171}172 173; Like the previous test, but flip %a and %b174define i16 @ripple_nsw6(i16 %x, i16 %y) {175; CHECK-LABEL: @ripple_nsw6(176; CHECK-NEXT:    [[A:%.*]] = or i16 [[Y:%.*]], -21845177; CHECK-NEXT:    [[B:%.*]] = or i16 [[X:%.*]], -10923178; CHECK-NEXT:    [[C:%.*]] = add nsw i16 [[B]], [[A]]179; CHECK-NEXT:    ret i16 [[C]]180;181  %a = or i16 %y, 43691182  %b = or i16 %x, 54613183  %c = add i16 %b, %a184  ret i16 %c185}186 187; We know nothing about %x188define i32 @ripple_no_nsw1(i32 %x, i32 %y) {189; CHECK-LABEL: @ripple_no_nsw1(190; CHECK-NEXT:    [[A:%.*]] = and i32 [[Y:%.*]], 1191; CHECK-NEXT:    [[B:%.*]] = add i32 [[A]], [[X:%.*]]192; CHECK-NEXT:    ret i32 [[B]]193;194  %a = and i32 %y, 1195  %b = add i32 %a, %x196  ret i32 %b197}198 199; %a has at most one bit set200; %b has a 0 bit, but it is the sign bit201define i16 @ripple_no_nsw2(i16 %x, i16 %y) {202; CHECK-LABEL: @ripple_no_nsw2(203; CHECK-NEXT:    [[A:%.*]] = and i16 [[Y:%.*]], 1204; CHECK-NEXT:    [[B:%.*]] = and i16 [[X:%.*]], 32767205; CHECK-NEXT:    [[C:%.*]] = add nuw i16 [[A]], [[B]]206; CHECK-NEXT:    ret i16 [[C]]207;208  %a = and i16 %y, 1209  %b = and i16 %x, 32767210  %c = add i16 %a, %b211  ret i16 %c212}213 214define i16 @ripple_no_nsw3(i16 %x, i16 %y) {215; CHECK-LABEL: @ripple_no_nsw3(216; CHECK-NEXT:    [[A:%.*]] = and i16 [[Y:%.*]], -21845217; CHECK-NEXT:    [[B:%.*]] = and i16 [[X:%.*]], 21845218; CHECK-NEXT:    [[C:%.*]] = add i16 [[A]], [[B]]219; CHECK-NEXT:    ret i16 [[C]]220;221  %a = and i16 %y, 43691222  %b = and i16 %x, 21845223  %c = add i16 %a, %b224  ret i16 %c225}226 227; Like the previous test, but flip %a and %b228define i16 @ripple_no_nsw4(i16 %x, i16 %y) {229; CHECK-LABEL: @ripple_no_nsw4(230; CHECK-NEXT:    [[A:%.*]] = and i16 [[Y:%.*]], -21845231; CHECK-NEXT:    [[B:%.*]] = and i16 [[X:%.*]], 21845232; CHECK-NEXT:    [[C:%.*]] = add i16 [[B]], [[A]]233; CHECK-NEXT:    ret i16 [[C]]234;235  %a = and i16 %y, 43691236  %b = and i16 %x, 21845237  %c = add i16 %b, %a238  ret i16 %c239}240 241define i16 @ripple_no_nsw5(i16 %x, i16 %y) {242; CHECK-LABEL: @ripple_no_nsw5(243; CHECK-NEXT:    [[A:%.*]] = or i16 [[Y:%.*]], -21847244; CHECK-NEXT:    [[B:%.*]] = or i16 [[X:%.*]], -10923245; CHECK-NEXT:    [[C:%.*]] = add i16 [[A]], [[B]]246; CHECK-NEXT:    ret i16 [[C]]247;248  %a = or i16 %y, 43689249  %b = or i16 %x, 54613250  %c = add i16 %a, %b251  ret i16 %c252}253 254; Like the previous test, but flip %a and %b255define i16 @ripple_no_nsw6(i16 %x, i16 %y) {256; CHECK-LABEL: @ripple_no_nsw6(257; CHECK-NEXT:    [[A:%.*]] = or i16 [[Y:%.*]], -21847258; CHECK-NEXT:    [[B:%.*]] = or i16 [[X:%.*]], -10923259; CHECK-NEXT:    [[C:%.*]] = add i16 [[B]], [[A]]260; CHECK-NEXT:    ret i16 [[C]]261;262  %a = or i16 %y, 43689263  %b = or i16 %x, 54613264  %c = add i16 %b, %a265  ret i16 %c266}267 268define i8 @PR38021(i8 %x) {269; CHECK-LABEL: @PR38021(270; CHECK-NEXT:    [[CLEAR_TOP_3_BITS:%.*]] = lshr i8 [[X:%.*]], 3271; CHECK-NEXT:    [[ADD:%.*]] = add nuw nsw i8 [[CLEAR_TOP_3_BITS]], -63272; CHECK-NEXT:    ret i8 [[ADD]]273;274  %clear_top_3_bits = lshr i8 %x, 3275  %add = add i8 %clear_top_3_bits, 193 ; 0b11000001276  ret i8 %add277}278