1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -passes=instcombine -S | FileCheck %s
4 ; With left shift, the comparison should not be modified.
5 define i1 @test_shift_and_cmp_not_changed1(i8 %p) {
6 ; CHECK-LABEL: @test_shift_and_cmp_not_changed1(
7 ; CHECK-NEXT: [[SHLP:%.*]] = shl i8 [[P:%.*]], 5
8 ; CHECK-NEXT: [[ANDP:%.*]] = and i8 [[SHLP]], -64
9 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i8 [[ANDP]], 32
10 ; CHECK-NEXT: ret i1 [[CMP]]
13 %andp = and i8 %shlp, -64
14 %cmp = icmp slt i8 %andp, 32
18 ; With arithmetic right shift, the comparison should not be modified.
19 define i1 @test_shift_and_cmp_not_changed2(i8 %p) {
20 ; CHECK-LABEL: @test_shift_and_cmp_not_changed2(
21 ; CHECK-NEXT: [[SHLP:%.*]] = ashr i8 [[P:%.*]], 5
22 ; CHECK-NEXT: [[ANDP:%.*]] = and i8 [[SHLP]], -64
23 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i8 [[ANDP]], 32
24 ; CHECK-NEXT: ret i1 [[CMP]]
27 %andp = and i8 %shlp, -64
28 %cmp = icmp slt i8 %andp, 32
32 ; This should simplify functionally to the left shift case.
33 ; The extra input parameter should be optimized away.
34 define i1 @test_shift_and_cmp_changed1(i8 %p, i8 %q) {
35 ; CHECK-LABEL: @test_shift_and_cmp_changed1(
36 ; CHECK-NEXT: [[ANDP:%.*]] = shl i8 [[P:%.*]], 5
37 ; CHECK-NEXT: [[TMP1:%.*]] = and i8 [[ANDP]], -64
38 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i8 [[TMP1]], 32
39 ; CHECK-NEXT: ret i1 [[CMP]]
43 %or = or i8 %andq, %andp
45 %ashr = ashr i8 %shl, 5
46 %cmp = icmp slt i8 %ashr, 1
50 define <2 x i1> @test_shift_and_cmp_changed1_vec(<2 x i8> %p, <2 x i8> %q) {
51 ; CHECK-LABEL: @test_shift_and_cmp_changed1_vec(
52 ; CHECK-NEXT: [[ANDP:%.*]] = shl <2 x i8> [[P:%.*]], <i8 5, i8 5>
53 ; CHECK-NEXT: [[TMP1:%.*]] = and <2 x i8> [[ANDP]], <i8 -64, i8 -64>
54 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt <2 x i8> [[TMP1]], <i8 32, i8 32>
55 ; CHECK-NEXT: ret <2 x i1> [[CMP]]
57 %andp = and <2 x i8> %p, <i8 6, i8 6>
58 %andq = and <2 x i8> %q, <i8 8, i8 8>
59 %or = or <2 x i8> %andq, %andp
60 %shl = shl <2 x i8> %or, <i8 5, i8 5>
61 %ashr = ashr <2 x i8> %shl, <i8 5, i8 5>
62 %cmp = icmp slt <2 x i8> %ashr, <i8 1, i8 1>
66 ; Unsigned compare allows a transformation to compare against 0.
67 define i1 @test_shift_and_cmp_changed2(i8 %p) {
68 ; CHECK-LABEL: @test_shift_and_cmp_changed2(
69 ; CHECK-NEXT: [[TMP1:%.*]] = and i8 [[P:%.*]], 6
70 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i8 [[TMP1]], 0
71 ; CHECK-NEXT: ret i1 [[CMP]]
74 %andp = and i8 %shlp, -64
75 %cmp = icmp ult i8 %andp, 32
79 define <2 x i1> @test_shift_and_cmp_changed2_vec(<2 x i8> %p) {
80 ; CHECK-LABEL: @test_shift_and_cmp_changed2_vec(
81 ; CHECK-NEXT: [[TMP1:%.*]] = and <2 x i8> [[P:%.*]], <i8 6, i8 6>
82 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq <2 x i8> [[TMP1]], zeroinitializer
83 ; CHECK-NEXT: ret <2 x i1> [[CMP]]
85 %shlp = shl <2 x i8> %p, <i8 5, i8 5>
86 %andp = and <2 x i8> %shlp, <i8 -64, i8 -64>
87 %cmp = icmp ult <2 x i8> %andp, <i8 32, i8 32>
91 ; nsw on the shift should not affect the comparison.
92 define i1 @test_shift_and_cmp_changed3(i8 %p) {
93 ; CHECK-LABEL: @test_shift_and_cmp_changed3(
94 ; CHECK-NEXT: [[SHLP:%.*]] = shl nsw i8 [[P:%.*]], 5
95 ; CHECK-NEXT: [[ANDP:%.*]] = and i8 [[SHLP]], -64
96 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i8 [[ANDP]], 32
97 ; CHECK-NEXT: ret i1 [[CMP]]
99 %shlp = shl nsw i8 %p, 5
100 %andp = and i8 %shlp, -64
101 %cmp = icmp slt i8 %andp, 32
105 ; Logical shift right allows a return true because the 'and' guarantees no bits are set.
106 define i1 @test_shift_and_cmp_changed4(i8 %p) {
107 ; CHECK-LABEL: @test_shift_and_cmp_changed4(
108 ; CHECK-NEXT: ret i1 true
110 %shlp = lshr i8 %p, 5
111 %andp = and i8 %shlp, -64
112 %cmp = icmp slt i8 %andp, 32