brintos

brintos / llvm-project-archived public Read only

0
0
Text · 4.4 KiB · f463f27 Raw
168 lines · plain
1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py2; RUN: opt < %s -passes=instcombine -S | FileCheck %s3 4; Fold5;   x s/EXACT (1 << y)6; to7;   x a>>EXACT y8; iff 1<<y is non-negative9 10define i8 @t0(i8 %x) {11; CHECK-LABEL: @t0(12; CHECK-NEXT:    [[DIV:%.*]] = ashr exact i8 [[X:%.*]], 513; CHECK-NEXT:    ret i8 [[DIV]]14;15  %div = sdiv exact i8 %x, 3216  ret i8 %div17}18 19define i8 @n1(i8 %x) {20; CHECK-LABEL: @n1(21; CHECK-NEXT:    [[DIV:%.*]] = sdiv i8 [[X:%.*]], 3222; CHECK-NEXT:    ret i8 [[DIV]]23;24  %div = sdiv i8 %x, 32 ; not exact25  ret i8 %div26}27 28define i8 @n2(i8 %x) {29; CHECK-LABEL: @n2(30; CHECK-NEXT:    [[TMP1:%.*]] = icmp eq i8 [[X:%.*]], -12831; CHECK-NEXT:    [[DIV:%.*]] = zext i1 [[TMP1]] to i832; CHECK-NEXT:    ret i8 [[DIV]]33;34  %div = sdiv i8 %x, 128 ; negative divisor35  ret i8 %div36}37 38define <2 x i8> @t3_vec_splat(<2 x i8> %x) {39; CHECK-LABEL: @t3_vec_splat(40; CHECK-NEXT:    [[DIV:%.*]] = ashr exact <2 x i8> [[X:%.*]], splat (i8 5)41; CHECK-NEXT:    ret <2 x i8> [[DIV]]42;43  %div = sdiv exact <2 x i8> %x, <i8 32, i8 32>44  ret <2 x i8> %div45}46 47define <2 x i8> @t4_vec(<2 x i8> %x) {48; CHECK-LABEL: @t4_vec(49; CHECK-NEXT:    [[DIV:%.*]] = ashr exact <2 x i8> [[X:%.*]], <i8 5, i8 4>50; CHECK-NEXT:    ret <2 x i8> [[DIV]]51;52  %div = sdiv exact <2 x i8> %x, <i8 32, i8 16>53  ret <2 x i8> %div54}55 56define <2 x i8> @n5_vec_undef(<2 x i8> %x) {57; CHECK-LABEL: @n5_vec_undef(58; CHECK-NEXT:    ret <2 x i8> poison59;60  %div = sdiv exact <2 x i8> %x, <i8 32, i8 undef>61  ret <2 x i8> %div62}63 64define <2 x i8> @n6_vec_negative(<2 x i8> %x) {65; CHECK-LABEL: @n6_vec_negative(66; CHECK-NEXT:    [[DIV:%.*]] = sdiv exact <2 x i8> [[X:%.*]], <i8 32, i8 -128>67; CHECK-NEXT:    ret <2 x i8> [[DIV]]68;69  %div = sdiv exact <2 x i8> %x, <i8 32, i8 128> ; non-non-negative divisor70  ret <2 x i8> %div71}72 73; sdiv exact X, (1<<ShAmt) --> ashr exact X, ShAmt (if shl is non-negative)74 75define i8 @shl1_nsw(i8 %x, i8 %y) {76; CHECK-LABEL: @shl1_nsw(77; CHECK-NEXT:    [[DIV:%.*]] = ashr exact i8 [[X:%.*]], [[Y:%.*]]78; CHECK-NEXT:    ret i8 [[DIV]]79;80  %shl = shl nsw i8 1, %y81  %div = sdiv exact i8 %x, %shl82  ret i8 %div83}84 85; negative test - must have nsw86 87define i8 @shl1_nuw(i8 %x, i8 %y) {88; CHECK-LABEL: @shl1_nuw(89; CHECK-NEXT:    [[SHL:%.*]] = shl nuw i8 1, [[Y:%.*]]90; CHECK-NEXT:    [[DIV:%.*]] = sdiv exact i8 [[X:%.*]], [[SHL]]91; CHECK-NEXT:    ret i8 [[DIV]]92;93  %shl = shl nuw i8 1, %y94  %div = sdiv exact i8 %x, %shl95  ret i8 %div96}97 98; negative test - must have exact99 100define i8 @shl1_nsw_not_exact(i8 %x, i8 %y) {101; CHECK-LABEL: @shl1_nsw_not_exact(102; CHECK-NEXT:    [[SHL:%.*]] = shl nuw nsw i8 1, [[Y:%.*]]103; CHECK-NEXT:    [[DIV:%.*]] = sdiv i8 [[X:%.*]], [[SHL]]104; CHECK-NEXT:    ret i8 [[DIV]]105;106  %shl = shl nsw i8 1, %y107  %div = sdiv i8 %x, %shl108  ret i8 %div109}110 111define i8 @prove_exact_with_high_mask(i8 %x, i8 %y) {112; CHECK-LABEL: @prove_exact_with_high_mask(113; CHECK-NEXT:    [[A:%.*]] = ashr i8 [[X:%.*]], 2114; CHECK-NEXT:    [[D:%.*]] = and i8 [[A]], -2115; CHECK-NEXT:    ret i8 [[D]]116;117  %a = and i8 %x, -8118  %d = sdiv i8 %a, 4119  ret i8 %d120}121 122define i8 @prove_exact_with_high_mask_limit(i8 %x, i8 %y) {123; CHECK-LABEL: @prove_exact_with_high_mask_limit(124; CHECK-NEXT:    [[A:%.*]] = ashr i8 [[X:%.*]], 3125; CHECK-NEXT:    ret i8 [[A]]126;127  %a = and i8 %x, -8128  %d = sdiv i8 %a, 8129  ret i8 %d130}131 132; negative test - not enough low zeros in dividend133 134define i8 @not_prove_exact_with_high_mask(i8 %x, i8 %y) {135; CHECK-LABEL: @not_prove_exact_with_high_mask(136; CHECK-NEXT:    [[A:%.*]] = and i8 [[X:%.*]], -8137; CHECK-NEXT:    [[D:%.*]] = sdiv i8 [[A]], 16138; CHECK-NEXT:    ret i8 [[D]]139;140  %a = and i8 %x, -8141  %d = sdiv i8 %a, 16142  ret i8 %d143}144 145define <2 x i8> @prove_exact_with_high_mask_splat_vec(<2 x i8> %x, <2 x i8> %y) {146; CHECK-LABEL: @prove_exact_with_high_mask_splat_vec(147; CHECK-NEXT:    [[A:%.*]] = shl <2 x i8> [[X:%.*]], splat (i8 3)148; CHECK-NEXT:    [[D:%.*]] = ashr exact <2 x i8> [[A]], splat (i8 3)149; CHECK-NEXT:    ret <2 x i8> [[D]]150;151  %a = shl <2 x i8> %x, <i8 3, i8 3>152  %d = sdiv <2 x i8> %a, <i8 8, i8 8>153  ret <2 x i8> %d154}155 156; TODO: Needs knownbits to handle arbitrary vector constants.157 158define <2 x i8> @prove_exact_with_high_mask_vec(<2 x i8> %x, <2 x i8> %y) {159; CHECK-LABEL: @prove_exact_with_high_mask_vec(160; CHECK-NEXT:    [[A:%.*]] = shl <2 x i8> [[X:%.*]], <i8 3, i8 2>161; CHECK-NEXT:    [[D:%.*]] = sdiv <2 x i8> [[A]], <i8 8, i8 4>162; CHECK-NEXT:    ret <2 x i8> [[D]]163;164  %a = shl <2 x i8> %x, <i8 3, i8 2>165  %d = sdiv <2 x i8> %a, <i8 8, i8 4>166  ret <2 x i8> %d167}168