50 lines · plain
1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py2; RUN: opt < %s -passes=instcombine -S | FileCheck %s3 4; Result of left shifting a non-negative integer5; with nsw flag should also be non-negative6define i1 @test_shift_nonnegative(i32 %a) {7; CHECK-LABEL: @test_shift_nonnegative(8; CHECK-NEXT: ret i1 true9;10 %b = lshr i32 %a, 211 %shift = shl nsw i32 %b, 312 %cmp = icmp sge i32 %shift, 013 ret i1 %cmp14}15 16; Result of left shifting a negative integer with17; nsw flag should also be negative18define i1 @test_shift_negative(i32 %a, i32 %b) {19; CHECK-LABEL: @test_shift_negative(20; CHECK-NEXT: ret i1 true21;22 %c = or i32 %a, -214748364823 %d = and i32 %b, 724 %shift = shl nsw i32 %c, %d25 %cmp = icmp slt i32 %shift, 026 ret i1 %cmp27}28 29; If sign bit is a known zero, it cannot be a known one.30; This test should not crash opt. The shift produces poison.31define i32 @test_no_sign_bit_conflict1(i1 %b) {32; CHECK-LABEL: @test_no_sign_bit_conflict1(33; CHECK-NEXT: ret i32 poison34;35 %sel = select i1 %b, i32 8193, i32 819236 %mul = shl nsw i32 %sel, 1837 ret i32 %mul38}39 40; If sign bit is a known one, it cannot be a known zero.41; This test should not crash opt. The shift produces poison.42define i32 @test_no_sign_bit_conflict2(i1 %b) {43; CHECK-LABEL: @test_no_sign_bit_conflict2(44; CHECK-NEXT: ret i32 poison45;46 %sel = select i1 %b, i32 -8193, i32 -819447 %mul = shl nsw i32 %sel, 1848 ret i32 %mul49}50