1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -instcombine -S | FileCheck %s
4 ; https://bugs.llvm.org/show_bug.cgi?id=38708
8 ; Should be transformed into:
11 ; ============================================================================ ;
12 ; Basic positive tests
13 ; ============================================================================ ;
15 define i1 @p0(i8 %val, i8 %bits) {
17 ; CHECK-NEXT: [[VAL_HIGHBITS:%.*]] = lshr i8 [[VAL:%.*]], [[BITS:%.*]]
18 ; CHECK-NEXT: [[R:%.*]] = icmp eq i8 [[VAL_HIGHBITS]], 0
19 ; CHECK-NEXT: ret i1 [[R]]
22 %r = icmp ugt i8 %t0, %val
26 ; ============================================================================ ;
28 ; ============================================================================ ;
30 define <2 x i1> @p1_vec(<2 x i8> %val, <2 x i8> %bits) {
31 ; CHECK-LABEL: @p1_vec(
32 ; CHECK-NEXT: [[VAL_HIGHBITS:%.*]] = lshr <2 x i8> [[VAL:%.*]], [[BITS:%.*]]
33 ; CHECK-NEXT: [[R:%.*]] = icmp eq <2 x i8> [[VAL_HIGHBITS]], zeroinitializer
34 ; CHECK-NEXT: ret <2 x i1> [[R]]
36 %t0 = shl <2 x i8> <i8 1, i8 1>, %bits
37 %r = icmp ugt <2 x i8> %t0, %val
41 define <3 x i1> @p2_vec_undef(<3 x i8> %val, <3 x i8> %bits) {
42 ; CHECK-LABEL: @p2_vec_undef(
43 ; CHECK-NEXT: [[VAL_HIGHBITS:%.*]] = lshr <3 x i8> [[VAL:%.*]], [[BITS:%.*]]
44 ; CHECK-NEXT: [[R:%.*]] = icmp eq <3 x i8> [[VAL_HIGHBITS]], zeroinitializer
45 ; CHECK-NEXT: ret <3 x i1> [[R]]
47 %t0 = shl <3 x i8> <i8 1, i8 undef, i8 1>, %bits
48 %r = icmp ugt <3 x i8> %t0, %val
52 ; ============================================================================ ;
53 ; Commutativity tests.
54 ; ============================================================================ ;
58 define i1 @c0(i8 %bits) {
60 ; CHECK-NEXT: [[VAL:%.*]] = call i8 @gen8()
61 ; CHECK-NEXT: [[VAL_HIGHBITS:%.*]] = lshr i8 [[VAL]], [[BITS:%.*]]
62 ; CHECK-NEXT: [[R:%.*]] = icmp eq i8 [[VAL_HIGHBITS]], 0
63 ; CHECK-NEXT: ret i1 [[R]]
66 %val = call i8 @gen8()
67 %r = icmp ult i8 %val, %t0 ; swapped order and predicate
71 ; What if we have the same pattern on both sides?
72 define i1 @both(i8 %bits0, i8 %bits1) {
74 ; CHECK-NEXT: [[T1:%.*]] = shl i8 1, [[BITS1:%.*]]
75 ; CHECK-NEXT: [[T1_HIGHBITS:%.*]] = lshr i8 [[T1]], [[BITS0:%.*]]
76 ; CHECK-NEXT: [[R:%.*]] = icmp eq i8 [[T1_HIGHBITS]], 0
77 ; CHECK-NEXT: ret i1 [[R]]
79 %t0 = shl i8 1, %bits0
80 %t1 = shl i8 1, %bits1
81 %r = icmp ugt i8 %t0, %t1
85 ; ============================================================================ ;
87 ; ============================================================================ ;
89 declare void @use8(i8)
91 define i1 @oneuse0(i8 %val, i8 %bits) {
92 ; CHECK-LABEL: @oneuse0(
93 ; CHECK-NEXT: [[T0:%.*]] = shl i8 1, [[BITS:%.*]]
94 ; CHECK-NEXT: call void @use8(i8 [[T0]])
95 ; CHECK-NEXT: [[R:%.*]] = icmp ugt i8 [[T0]], [[VAL:%.*]]
96 ; CHECK-NEXT: ret i1 [[R]]
99 call void @use8(i8 %t0)
100 %r = icmp ugt i8 %t0, %val
104 ; ============================================================================ ;
106 ; ============================================================================ ;
108 define i1 @n0(i8 %val, i8 %bits) {
110 ; CHECK-NEXT: [[T0:%.*]] = shl i8 2, [[BITS:%.*]]
111 ; CHECK-NEXT: [[R:%.*]] = icmp ugt i8 [[T0]], [[VAL:%.*]]
112 ; CHECK-NEXT: ret i1 [[R]]
114 %t0 = shl i8 2, %bits ; constant is not 1
115 %r = icmp ugt i8 %t0, %val
119 define <2 x i1> @n1_vec_nonsplat(<2 x i8> %val, <2 x i8> %bits) {
120 ; CHECK-LABEL: @n1_vec_nonsplat(
121 ; CHECK-NEXT: [[T0:%.*]] = shl <2 x i8> <i8 1, i8 2>, [[BITS:%.*]]
122 ; CHECK-NEXT: [[R:%.*]] = icmp ugt <2 x i8> [[T0]], [[VAL:%.*]]
123 ; CHECK-NEXT: ret <2 x i1> [[R]]
125 %t0 = shl <2 x i8> <i8 1, i8 2>, %bits ; again, wrong constant
126 %r = icmp ugt <2 x i8> %t0, %val
130 define i1 @n2(i8 %val, i8 %bits) {
132 ; CHECK-NEXT: [[T0:%.*]] = shl i8 1, [[BITS:%.*]]
133 ; CHECK-NEXT: [[R:%.*]] = icmp uge i8 [[T0]], [[VAL:%.*]]
134 ; CHECK-NEXT: ret i1 [[R]]
136 %t0 = shl i8 1, %bits
137 %r = icmp uge i8 %t0, %val ; wrong predicate
141 define i1 @n3(i8 %bits) {
143 ; CHECK-NEXT: [[T0:%.*]] = shl i8 1, [[BITS:%.*]]
144 ; CHECK-NEXT: [[VAL:%.*]] = call i8 @gen8()
145 ; CHECK-NEXT: [[R:%.*]] = icmp ule i8 [[VAL]], [[T0]]
146 ; CHECK-NEXT: ret i1 [[R]]
148 %t0 = shl i8 1, %bits
149 %val = call i8 @gen8()
150 %r = icmp ule i8 %val, %t0 ; swapped order and [wrong] predicate