125 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 y)8 9define i8 @t0(i8 %x) {10; CHECK-LABEL: @t0(11; CHECK-NEXT: [[DIV_NEG:%.*]] = ashr exact i8 [[X:%.*]], 512; CHECK-NEXT: [[DIV:%.*]] = sub nsw i8 0, [[DIV_NEG]]13; 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 <2 x i8> @t2_vec_splat(<2 x i8> %x) {29; CHECK-LABEL: @t2_vec_splat(30; CHECK-NEXT: [[DIV_NEG:%.*]] = ashr exact <2 x i8> [[X:%.*]], splat (i8 5)31; CHECK-NEXT: [[DIV:%.*]] = sub nsw <2 x i8> zeroinitializer, [[DIV_NEG]]32; CHECK-NEXT: ret <2 x i8> [[DIV]]33;34 %div = sdiv exact <2 x i8> %x, <i8 -32, i8 -32>35 ret <2 x i8> %div36}37 38define <2 x i8> @t3_vec(<2 x i8> %x) {39; CHECK-LABEL: @t3_vec(40; CHECK-NEXT: [[DIV_NEG:%.*]] = ashr exact <2 x i8> [[X:%.*]], <i8 5, i8 4>41; CHECK-NEXT: [[DIV:%.*]] = sub nsw <2 x i8> zeroinitializer, [[DIV_NEG]]42; CHECK-NEXT: ret <2 x i8> [[DIV]]43;44 %div = sdiv exact <2 x i8> %x, <i8 -32, i8 -16>45 ret <2 x i8> %div46}47 48define <2 x i8> @n4_vec_mixed(<2 x i8> %x) {49; CHECK-LABEL: @n4_vec_mixed(50; CHECK-NEXT: [[DIV:%.*]] = sdiv exact <2 x i8> [[X:%.*]], <i8 -32, i8 16>51; CHECK-NEXT: ret <2 x i8> [[DIV]]52;53 %div = sdiv exact <2 x i8> %x, <i8 -32, i8 16>54 ret <2 x i8> %div55}56 57define <2 x i8> @n4_vec_undef(<2 x i8> %x) {58; CHECK-LABEL: @n4_vec_undef(59; CHECK-NEXT: ret <2 x i8> poison60;61 %div = sdiv exact <2 x i8> %x, <i8 -32, i8 undef>62 ret <2 x i8> %div63}64 65define i8 @prove_exact_with_high_mask(i8 %x, i8 %y) {66; CHECK-LABEL: @prove_exact_with_high_mask(67; CHECK-NEXT: [[A:%.*]] = ashr i8 [[X:%.*]], 268; CHECK-NEXT: [[D_NEG:%.*]] = and i8 [[A]], -869; CHECK-NEXT: [[D:%.*]] = sub nsw i8 0, [[D_NEG]]70; CHECK-NEXT: ret i8 [[D]]71;72 %a = and i8 %x, -3273 %d = sdiv i8 %a, -474 ret i8 %d75}76 77define i8 @prove_exact_with_high_mask_limit(i8 %x, i8 %y) {78; CHECK-LABEL: @prove_exact_with_high_mask_limit(79; CHECK-NEXT: [[D_NEG:%.*]] = ashr i8 [[X:%.*]], 580; CHECK-NEXT: [[D:%.*]] = sub nsw i8 0, [[D_NEG]]81; CHECK-NEXT: ret i8 [[D]]82;83 %a = and i8 %x, -3284 %d = sdiv i8 %a, -3285 ret i8 %d86}87 88; negative test - not enough low zeros in dividend89 90define i8 @not_prove_exact_with_high_mask(i8 %x, i8 %y) {91; CHECK-LABEL: @not_prove_exact_with_high_mask(92; CHECK-NEXT: [[A:%.*]] = and i8 [[X:%.*]], -3293; CHECK-NEXT: [[D:%.*]] = sdiv i8 [[A]], -6494; CHECK-NEXT: ret i8 [[D]]95;96 %a = and i8 %x, -3297 %d = sdiv i8 %a, -6498 ret i8 %d99}100 101define <2 x i8> @prove_exact_with_high_mask_splat_vec(<2 x i8> %x, <2 x i8> %y) {102; CHECK-LABEL: @prove_exact_with_high_mask_splat_vec(103; CHECK-NEXT: [[A:%.*]] = shl <2 x i8> [[X:%.*]], splat (i8 5)104; CHECK-NEXT: [[D_NEG:%.*]] = ashr exact <2 x i8> [[A]], splat (i8 4)105; CHECK-NEXT: [[D:%.*]] = sub nsw <2 x i8> zeroinitializer, [[D_NEG]]106; CHECK-NEXT: ret <2 x i8> [[D]]107;108 %a = shl <2 x i8> %x, <i8 5, i8 5>109 %d = sdiv <2 x i8> %a, <i8 -16, i8 -16>110 ret <2 x i8> %d111}112 113; TODO: Needs knownbits to handle arbitrary vector constants.114 115define <2 x i8> @prove_exact_with_high_mask_vec(<2 x i8> %x, <2 x i8> %y) {116; CHECK-LABEL: @prove_exact_with_high_mask_vec(117; CHECK-NEXT: [[A:%.*]] = shl <2 x i8> [[X:%.*]], <i8 3, i8 2>118; CHECK-NEXT: [[D:%.*]] = sdiv <2 x i8> [[A]], <i8 -8, i8 -4>119; CHECK-NEXT: ret <2 x i8> [[D]]120;121 %a = shl <2 x i8> %x, <i8 3, i8 2>122 %d = sdiv <2 x i8> %a, <i8 -8, i8 -4>123 ret <2 x i8> %d124}125