1; RUN: opt < %s -instcombine -S | FileCheck %s 2 3; With left shift, the comparison should not be modified. 4; CHECK-LABEL: @test_shift_and_cmp_not_changed1( 5; CHECK: icmp slt i8 %andp, 32 6define i1 @test_shift_and_cmp_not_changed1(i8 %p) #0 { 7entry: 8 %shlp = shl i8 %p, 5 9 %andp = and i8 %shlp, -64 10 %cmp = icmp slt i8 %andp, 32 11 ret i1 %cmp 12} 13 14; With arithmetic right shift, the comparison should not be modified. 15; CHECK-LABEL: @test_shift_and_cmp_not_changed2( 16; CHECK: icmp slt i8 %andp, 32 17define i1 @test_shift_and_cmp_not_changed2(i8 %p) #0 { 18entry: 19 %shlp = ashr i8 %p, 5 20 %andp = and i8 %shlp, -64 21 %cmp = icmp slt i8 %andp, 32 22 ret i1 %cmp 23} 24 25; This should simplify functionally to the left shift case. 26; The extra input parameter should be optimized away. 27; CHECK-LABEL: @test_shift_and_cmp_changed1( 28; CHECK: %andp = shl i8 %p, 5 29; CHECK-NEXT: %shl = and i8 %andp, -64 30; CHECK-NEXT: %cmp = icmp slt i8 %shl, 32 31define i1 @test_shift_and_cmp_changed1(i8 %p, i8 %q) #0 { 32entry: 33 %andp = and i8 %p, 6 34 %andq = and i8 %q, 8 35 %or = or i8 %andq, %andp 36 %shl = shl i8 %or, 5 37 %ashr = ashr i8 %shl, 5 38 %cmp = icmp slt i8 %ashr, 1 39 ret i1 %cmp 40} 41 42; Unsigned compare allows a transformation to compare against 0. 43; CHECK-LABEL: @test_shift_and_cmp_changed2( 44; CHECK: icmp eq i8 %andp, 0 45define i1 @test_shift_and_cmp_changed2(i8 %p) #0 { 46entry: 47 %shlp = shl i8 %p, 5 48 %andp = and i8 %shlp, -64 49 %cmp = icmp ult i8 %andp, 32 50 ret i1 %cmp 51} 52 53; nsw on the shift should not affect the comparison. 54; CHECK-LABEL: @test_shift_and_cmp_changed3( 55; CHECK: icmp slt i8 %andp, 32 56define i1 @test_shift_and_cmp_changed3(i8 %p) #0 { 57entry: 58 %shlp = shl nsw i8 %p, 5 59 %andp = and i8 %shlp, -64 60 %cmp = icmp slt i8 %andp, 32 61 ret i1 %cmp 62} 63 64; Logical shift right allows a return true because the 'and' guarantees no bits are set. 65; CHECK-LABEL: @test_shift_and_cmp_changed4( 66; CHECK: ret i1 true 67define i1 @test_shift_and_cmp_changed4(i8 %p) #0 { 68entry: 69 %shlp = lshr i8 %p, 5 70 %andp = and i8 %shlp, -64 71 %cmp = icmp slt i8 %andp, 32 72 ret i1 %cmp 73} 74 75