1 ; RUN: opt < %s -instcombine -S | FileCheck %s
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
6 define i1 @test_shift_and_cmp_not_changed1(i8 %p) #0 {
9 %andp = and i8 %shlp, -64
10 %cmp = icmp slt i8 %andp, 32
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
17 define i1 @test_shift_and_cmp_not_changed2(i8 %p) #0 {
20 %andp = and i8 %shlp, -64
21 %cmp = icmp slt i8 %andp, 32
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
31 define i1 @test_shift_and_cmp_changed1(i8 %p, i8 %q) #0 {
35 %or = or i8 %andq, %andp
37 %ashr = ashr i8 %shl, 5
38 %cmp = icmp slt i8 %ashr, 1
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
45 define i1 @test_shift_and_cmp_changed2(i8 %p) #0 {
48 %andp = and i8 %shlp, -64
49 %cmp = icmp ult i8 %andp, 32
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
56 define i1 @test_shift_and_cmp_changed3(i8 %p) #0 {
58 %shlp = shl nsw i8 %p, 5
59 %andp = and i8 %shlp, -64
60 %cmp = icmp slt i8 %andp, 32
64 ; Logical shift right allows a return true because the 'and' guarantees no bits are set.
65 ; CHECK-LABEL: @test_shift_and_cmp_changed4(
67 define i1 @test_shift_and_cmp_changed4(i8 %p) #0 {
70 %andp = and i8 %shlp, -64
71 %cmp = icmp slt i8 %andp, 32