1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -passes=instcombine -S | FileCheck %s
4 define i1 @icmp_ugt_32(i64) {
5 ; CHECK-LABEL: @icmp_ugt_32(
6 ; CHECK-NEXT: [[D:%.*]] = icmp ne i64 [[TMP0:%.*]], 0
7 ; CHECK-NEXT: ret i1 [[D]]
9 %c = shl nuw i64 %0, 32
10 %d = icmp ugt i64 %c, 4294967295
14 define i1 @icmp_ule_64(i128) {
15 ; CHECK-LABEL: @icmp_ule_64(
16 ; CHECK-NEXT: [[D:%.*]] = icmp eq i128 [[TMP0:%.*]], 0
17 ; CHECK-NEXT: ret i1 [[D]]
19 %c = shl nuw i128 %0, 64
20 %d = icmp ule i128 %c, 18446744073709551615
24 define i1 @icmp_ugt_16(i64) {
25 ; CHECK-LABEL: @icmp_ugt_16(
26 ; CHECK-NEXT: [[D:%.*]] = icmp ugt i64 [[TMP0:%.*]], 15
27 ; CHECK-NEXT: ret i1 [[D]]
29 %c = shl nuw i64 %0, 16
30 %d = icmp ugt i64 %c, 1048575 ; 0x0f_ffff
34 define <2 x i1> @icmp_ule_16x2(<2 x i64>) {
35 ; CHECK-LABEL: @icmp_ule_16x2(
36 ; CHECK-NEXT: [[D:%.*]] = icmp eq <2 x i64> [[TMP0:%.*]], zeroinitializer
37 ; CHECK-NEXT: ret <2 x i1> [[D]]
39 %c = shl nuw <2 x i64> %0, <i64 16, i64 16>
40 %d = icmp ule <2 x i64> %c, <i64 65535, i64 65535>
44 define <2 x i1> @icmp_ule_16x2_nonzero(<2 x i64>) {
45 ; CHECK-LABEL: @icmp_ule_16x2_nonzero(
46 ; CHECK-NEXT: [[D:%.*]] = icmp ult <2 x i64> [[TMP0:%.*]], splat (i64 4)
47 ; CHECK-NEXT: ret <2 x i1> [[D]]
49 %c = shl nuw <2 x i64> %0, <i64 16, i64 16>
50 %d = icmp ule <2 x i64> %c, <i64 196608, i64 196608> ; 0x03_0000
54 define <2 x i1> @icmp_ule_12x2(<2 x i64>) {
55 ; CHECK-LABEL: @icmp_ule_12x2(
56 ; CHECK-NEXT: [[D:%.*]] = icmp ult <2 x i64> [[TMP0:%.*]], splat (i64 4)
57 ; CHECK-NEXT: ret <2 x i1> [[D]]
59 %c = shl nuw <2 x i64> %0, <i64 12, i64 12>
60 %d = icmp ule <2 x i64> %c, <i64 12288, i64 12288> ; 0x3000
64 define i1 @icmp_ult_8(i64) {
65 ; CHECK-LABEL: @icmp_ult_8(
66 ; CHECK-NEXT: [[D:%.*]] = icmp ult i64 [[TMP0:%.*]], 16
67 ; CHECK-NEXT: ret i1 [[D]]
69 %c = shl nuw i64 %0, 8
70 %d = icmp ult i64 %c, 4095 ; 0x0fff
74 define <2 x i1> @icmp_uge_8x2(<2 x i16>) {
75 ; CHECK-LABEL: @icmp_uge_8x2(
76 ; CHECK-NEXT: [[D:%.*]] = icmp ugt <2 x i16> [[TMP0:%.*]], splat (i16 15)
77 ; CHECK-NEXT: ret <2 x i1> [[D]]
79 %c = shl nuw <2 x i16> %0, <i16 8, i16 8>
80 %d = icmp uge <2 x i16> %c, <i16 4095, i16 4095>
84 define <2 x i1> @icmp_ugt_16x2(<2 x i32>) {
85 ; CHECK-LABEL: @icmp_ugt_16x2(
86 ; CHECK-NEXT: [[D:%.*]] = icmp ugt <2 x i32> [[TMP0:%.*]], splat (i32 15)
87 ; CHECK-NEXT: ret <2 x i1> [[D]]
89 %c = shl nuw <2 x i32> %0, <i32 16, i32 16>
90 %d = icmp ugt <2 x i32> %c, <i32 1048575, i32 1048575>
94 define i1 @fold_icmp_shl_nuw_c1(i32 %x) {
95 ; CHECK-LABEL: @fold_icmp_shl_nuw_c1(
96 ; CHECK-NEXT: [[TMP1:%.*]] = and i32 [[X:%.*]], 61440
97 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[TMP1]], 0
98 ; CHECK-NEXT: ret i1 [[CMP]]
100 %lshr = lshr i32 %x, 12
101 %and = and i32 %lshr, 15
102 %shl = shl nuw i32 2, %and
103 %cmp = icmp ult i32 %shl, 4
107 define i1 @fold_icmp_shl_nuw_c2(i32 %x) {
108 ; CHECK-LABEL: @fold_icmp_shl_nuw_c2(
109 ; CHECK-NEXT: [[CMP:%.*]] = icmp ult i32 [[X:%.*]], 2
110 ; CHECK-NEXT: ret i1 [[CMP]]
112 %shl = shl nuw i32 16, %x
113 %cmp = icmp ult i32 %shl, 64
117 define i1 @fold_icmp_shl_nuw_c2_non_pow2(i32 %x) {
118 ; CHECK-LABEL: @fold_icmp_shl_nuw_c2_non_pow2(
119 ; CHECK-NEXT: [[CMP:%.*]] = icmp ult i32 [[X:%.*]], 2
120 ; CHECK-NEXT: ret i1 [[CMP]]
122 %shl = shl nuw i32 48, %x
123 %cmp = icmp ult i32 %shl, 192
127 define i1 @fold_icmp_shl_nuw_c2_div_non_pow2(i32 %x) {
128 ; CHECK-LABEL: @fold_icmp_shl_nuw_c2_div_non_pow2(
129 ; CHECK-NEXT: [[CMP:%.*]] = icmp ult i32 [[X:%.*]], 5
130 ; CHECK-NEXT: ret i1 [[CMP]]
132 %shl = shl nuw i32 2, %x
133 %cmp = icmp ult i32 %shl, 60
137 define i1 @fold_icmp_shl_nuw_c3(i32 %x) {
138 ; CHECK-LABEL: @fold_icmp_shl_nuw_c3(
139 ; CHECK-NEXT: [[CMP:%.*]] = icmp ugt i32 [[X:%.*]], 1
140 ; CHECK-NEXT: ret i1 [[CMP]]
142 %shl = shl nuw i32 48, %x
143 %cmp = icmp uge i32 %shl, 144
147 define i1 @fold_icmp_shl_nuw_c2_indivisible(i32 %x) {
148 ; CHECK-LABEL: @fold_icmp_shl_nuw_c2_indivisible(
149 ; CHECK-NEXT: [[CMP:%.*]] = icmp ult i32 [[X:%.*]], 2
150 ; CHECK-NEXT: ret i1 [[CMP]]
152 %shl = shl nuw i32 16, %x
153 %cmp = icmp ult i32 %shl, 63
159 define i1 @fold_icmp_shl_c2_without_nuw(i32 %x) {
160 ; CHECK-LABEL: @fold_icmp_shl_c2_without_nuw(
161 ; CHECK-NEXT: [[SHL:%.*]] = shl i32 16, [[X:%.*]]
162 ; CHECK-NEXT: [[CMP:%.*]] = icmp ult i32 [[SHL]], 64
163 ; CHECK-NEXT: ret i1 [[CMP]]
165 %shl = shl i32 16, %x
166 %cmp = icmp ult i32 %shl, 64
170 ; Make sure this trivial case is folded by InstSimplify.
171 define i1 @fold_icmp_shl_nuw_c2_precondition1(i32 %x) {
172 ; CHECK-LABEL: @fold_icmp_shl_nuw_c2_precondition1(
173 ; CHECK-NEXT: ret i1 true
175 %shl = shl nuw i32 0, %x
176 %cmp = icmp ult i32 %shl, 63
180 ; Make sure this trivial case is folded by InstSimplify.
181 define i1 @fold_icmp_shl_nuw_c2_precondition2(i32 %x) {
182 ; CHECK-LABEL: @fold_icmp_shl_nuw_c2_precondition2(
183 ; CHECK-NEXT: ret i1 false
185 %shl = shl nuw i32 127, %x
186 %cmp = icmp ult i32 %shl, 63
190 ; Make sure we don't crash on this case.
191 define i1 @fold_icmp_shl_nuw_c2_precondition3(i32 %x) {
192 ; CHECK-LABEL: @fold_icmp_shl_nuw_c2_precondition3(
193 ; CHECK-NEXT: ret i1 false
195 %shl = shl nuw i32 1, %x
196 %cmp = icmp ult i32 %shl, 1