brintos

brintos / llvm-project-archived public Read only

0
0
Text · 5.5 KiB · d62edf2 Raw
169 lines · plain
1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py2; RUN: opt < %s -passes=instcombine -S | FileCheck %s3 4; (x << k) ? 2^k * x : 0 --> 2^k * x5 6define i32 @test_eq(i32 %x) {7; CHECK-LABEL: @test_eq(8; CHECK-NEXT:    [[MUL:%.*]] = shl i32 [[X:%.*]], 29; CHECK-NEXT:    ret i32 [[MUL]]10;11  %shl.mask = and i32 %x, 107374182312  %tobool = icmp eq i32 %shl.mask, 013  %mul = shl i32 %x, 214  %cond = select i1 %tobool, i32 0, i32 %mul15  ret i32 %cond16}17 18define <2 x i32> @test_eq_vect(<2 x i32> %x) {19; CHECK-LABEL: @test_eq_vect(20; CHECK-NEXT:    [[MUL:%.*]] = shl <2 x i32> [[X:%.*]], splat (i32 2)21; CHECK-NEXT:    ret <2 x i32> [[MUL]]22;23  %shl.mask = and <2 x i32> %x, <i32 1073741823, i32 1073741823>24  %tobool = icmp eq <2 x i32> %shl.mask, zeroinitializer25  %mul = shl <2 x i32> %x, <i32 2, i32 2>26  %cond = select <2 x i1> %tobool, <2 x i32> zeroinitializer, <2 x i32> %mul27  ret <2 x i32> %cond28}29 30define i32 @test_ne(i32 %x) {31; CHECK-LABEL: @test_ne(32; CHECK-NEXT:    [[MUL:%.*]] = shl i32 [[X:%.*]], 233; CHECK-NEXT:    ret i32 [[MUL]]34;35  %shl.mask = and i32 %x, 107374182336  %tobool.not = icmp ne i32 %shl.mask, 037  %mul = shl i32 %x, 238  %cond = select i1 %tobool.not, i32 %mul, i32 039  ret i32 %cond40}41 42define <2 x i32> @test_ne_vect(<2 x i32> %x) {43; CHECK-LABEL: @test_ne_vect(44; CHECK-NEXT:    [[MUL:%.*]] = shl <2 x i32> [[X:%.*]], splat (i32 2)45; CHECK-NEXT:    ret <2 x i32> [[MUL]]46;47  %shl.mask = and <2 x i32> %x, <i32 1073741823, i32 1073741823>48  %tobool.not = icmp ne <2 x i32> %shl.mask, zeroinitializer49  %mul = shl <2 x i32> %x, <i32 2, i32 2>50  %cond = select <2 x i1> %tobool.not, <2 x i32> %mul, <2 x i32> zeroinitializer51  ret <2 x i32> %cond52}53 54define i32 @test_nuw_dropped(i32 %x) {55; CHECK-LABEL: @test_nuw_dropped(56; CHECK-NEXT:    [[MUL:%.*]] = shl i32 [[X:%.*]], 257; CHECK-NEXT:    ret i32 [[MUL]]58;59  %shl.mask = and i32 %x, 107374182360  %tobool = icmp eq i32 %shl.mask, 061  %mul = shl nuw i32 %x, 262  %cond = select i1 %tobool, i32 0, i32 %mul63  ret i32 %cond64}65 66define i32 @test_nsw_dropped(i32 %x) {67; CHECK-LABEL: @test_nsw_dropped(68; CHECK-NEXT:    [[MUL:%.*]] = shl i32 [[X:%.*]], 269; CHECK-NEXT:    ret i32 [[MUL]]70;71  %shl.mask = and i32 %x, 107374182372  %tobool = icmp eq i32 %shl.mask, 073  %mul = shl nsw i32 %x, 274  %cond = select i1 %tobool, i32 0, i32 %mul75  ret i32 %cond76}77 78declare void @use_multi(i32, i1, i32)79 80; This will not be canonicalized.81define i32 @test_multi_use(i32 %x) {82; CHECK-LABEL: @test_multi_use(83; CHECK-NEXT:    [[SHL_MASK:%.*]] = and i32 [[X:%.*]], 107374182384; CHECK-NEXT:    [[TOBOOL_NOT:%.*]] = icmp ne i32 [[SHL_MASK]], 085; CHECK-NEXT:    [[MUL:%.*]] = shl i32 [[X]], 286; CHECK-NEXT:    call void @use_multi(i32 [[SHL_MASK]], i1 [[TOBOOL_NOT]], i32 [[MUL]])87; CHECK-NEXT:    ret i32 [[MUL]]88;89  %shl.mask = and i32 %x, 107374182390  %tobool.not = icmp ne i32 %shl.mask, 091  %mul = shl i32 %x, 292  %cond = select i1 %tobool.not, i32 %mul, i32 093  call void @use_multi(i32 %shl.mask, i1 %tobool.not, i32 %mul)94  ret i32 %cond95}96 97define i32 @test_multi_use_nuw_dropped(i32 %x) {98; CHECK-LABEL: @test_multi_use_nuw_dropped(99; CHECK-NEXT:    [[SHL_MASK:%.*]] = and i32 [[X:%.*]], 1073741823100; CHECK-NEXT:    [[TOBOOL:%.*]] = icmp eq i32 [[SHL_MASK]], 0101; CHECK-NEXT:    [[MUL:%.*]] = shl i32 [[X]], 2102; CHECK-NEXT:    call void @use_multi(i32 [[SHL_MASK]], i1 [[TOBOOL]], i32 [[MUL]])103; CHECK-NEXT:    ret i32 [[MUL]]104;105  %shl.mask = and i32 %x, 1073741823106  %tobool = icmp eq i32 %shl.mask, 0107  %mul = shl nuw i32 %x, 2108  %cond = select i1 %tobool, i32 0, i32 %mul109  call void @use_multi(i32 %shl.mask, i1 %tobool, i32 %mul)110  ret i32 %cond111}112 113define i32 @neg_test_bits_not_match(i32 %x) {114; CHECK-LABEL: @neg_test_bits_not_match(115; CHECK-NEXT:    [[SHL_MASK:%.*]] = and i32 [[X:%.*]], 1073741823116; CHECK-NEXT:    [[TOBOOL:%.*]] = icmp eq i32 [[SHL_MASK]], 0117; CHECK-NEXT:    [[MUL:%.*]] = shl i32 [[X]], 3118; CHECK-NEXT:    [[COND:%.*]] = select i1 [[TOBOOL]], i32 0, i32 [[MUL]]119; CHECK-NEXT:    ret i32 [[COND]]120;121  %shl.mask = and i32 %x, 1073741823122  %tobool = icmp eq i32 %shl.mask, 0123  %mul = shl i32 %x, 3124  %cond = select i1 %tobool, i32 0, i32 %mul125  ret i32 %cond126}127 128define i32 @neg_test_icmp_non_equality(i32 %x) {129; CHECK-LABEL: @neg_test_icmp_non_equality(130; CHECK-NEXT:    [[MUL:%.*]] = shl i32 [[X:%.*]], 2131; CHECK-NEXT:    ret i32 [[MUL]]132;133  %shl.mask = and i32 %x, 1073741823134  %tobool = icmp slt i32 %shl.mask, 0135  %mul = shl i32 %x, 2136  %cond = select i1 %tobool, i32 0, i32 %mul137  ret i32 %cond138}139 140define i32 @neg_test_select_non_zero_constant(i32 %x) {141; CHECK-LABEL: @neg_test_select_non_zero_constant(142; CHECK-NEXT:    [[SHL_MASK:%.*]] = and i32 [[X:%.*]], 1073741823143; CHECK-NEXT:    [[TOBOOL:%.*]] = icmp eq i32 [[SHL_MASK]], 0144; CHECK-NEXT:    [[MUL:%.*]] = shl i32 [[X]], 2145; CHECK-NEXT:    [[COND:%.*]] = select i1 [[TOBOOL]], i32 1, i32 [[MUL]]146; CHECK-NEXT:    ret i32 [[COND]]147;148  %shl.mask = and i32 %x, 1073741823149  %tobool = icmp eq i32 %shl.mask, 0150  %mul = shl i32 %x, 2151  %cond = select i1 %tobool, i32 1, i32 %mul152  ret i32 %cond153}154 155define i32 @neg_test_icmp_non_zero_constant(i32 %x) {156; CHECK-LABEL: @neg_test_icmp_non_zero_constant(157; CHECK-NEXT:    [[SHL_MASK:%.*]] = and i32 [[X:%.*]], 1073741823158; CHECK-NEXT:    [[TOBOOL:%.*]] = icmp eq i32 [[SHL_MASK]], 1159; CHECK-NEXT:    [[MUL:%.*]] = shl i32 [[X]], 2160; CHECK-NEXT:    [[COND:%.*]] = select i1 [[TOBOOL]], i32 0, i32 [[MUL]]161; CHECK-NEXT:    ret i32 [[COND]]162;163  %shl.mask = and i32 %x, 1073741823164  %tobool = icmp eq i32 %shl.mask, 1165  %mul = shl i32 %x, 2166  %cond = select i1 %tobool, i32 0, i32 %mul167  ret i32 %cond168}169