[InstCombine] Signed saturation patterns
[llvm-core.git] / test / Transforms / InstCombine / not.ll
blob42a910aa3f2c5589f9b8061f096fd61a9cb9eefe
1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -instcombine -S | FileCheck %s
4 define i32 @test1(i32 %A) {
5 ; CHECK-LABEL: @test1(
6 ; CHECK-NEXT:    ret i32 [[A:%.*]]
8   %B = xor i32 %A, -1
9   %C = xor i32 %B, -1
10   ret i32 %C
13 define i1 @invert_icmp(i32 %A, i32 %B) {
14 ; CHECK-LABEL: @invert_icmp(
15 ; CHECK-NEXT:    [[CMP:%.*]] = icmp sgt i32 [[A:%.*]], [[B:%.*]]
16 ; CHECK-NEXT:    ret i1 [[CMP]]
18   %cmp = icmp sle i32 %A, %B
19   %not = xor i1 %cmp, true
20   ret i1 %not
23 ; PR1570
25 define i1 @invert_fcmp(float %X, float %Y) {
26 ; CHECK-LABEL: @invert_fcmp(
27 ; CHECK-NEXT:    [[CMP:%.*]] = fcmp uge float [[X:%.*]], [[Y:%.*]]
28 ; CHECK-NEXT:    ret i1 [[CMP]]
30   %cmp = fcmp olt float %X, %Y
31   %not = xor i1 %cmp, true
32   ret i1 %not
35 ; PR2298
37 define i1 @not_not_cmp(i32 %a, i32 %b) {
38 ; CHECK-LABEL: @not_not_cmp(
39 ; CHECK-NEXT:    [[CMP:%.*]] = icmp slt i32 [[B:%.*]], [[A:%.*]]
40 ; CHECK-NEXT:    ret i1 [[CMP]]
42   %nota = xor i32 %a, -1
43   %notb = xor i32 %b, -1
44   %cmp = icmp slt i32 %nota, %notb
45   ret i1 %cmp
48 define <2 x i1> @not_not_cmp_vector(<2 x i32> %a, <2 x i32> %b) {
49 ; CHECK-LABEL: @not_not_cmp_vector(
50 ; CHECK-NEXT:    [[CMP:%.*]] = icmp ugt <2 x i32> [[B:%.*]], [[A:%.*]]
51 ; CHECK-NEXT:    ret <2 x i1> [[CMP]]
53   %nota = xor <2 x i32> %a, <i32 -1, i32 -1>
54   %notb = xor <2 x i32> %b, <i32 -1, i32 -1>
55   %cmp = icmp ugt <2 x i32> %nota, %notb
56   ret <2 x i1> %cmp
59 define i1 @not_cmp_constant(i32 %a) {
60 ; CHECK-LABEL: @not_cmp_constant(
61 ; CHECK-NEXT:    [[CMP:%.*]] = icmp ult i32 [[A:%.*]], -43
62 ; CHECK-NEXT:    ret i1 [[CMP]]
64   %nota = xor i32 %a, -1
65   %cmp = icmp ugt i32 %nota, 42
66   ret i1 %cmp
69 define <2 x i1> @not_cmp_constant_vector(<2 x i32> %a) {
70 ; CHECK-LABEL: @not_cmp_constant_vector(
71 ; CHECK-NEXT:    [[CMP:%.*]] = icmp sgt <2 x i32> [[A:%.*]], <i32 -43, i32 -43>
72 ; CHECK-NEXT:    ret <2 x i1> [[CMP]]
74   %nota = xor <2 x i32> %a, <i32 -1, i32 -1>
75   %cmp = icmp slt <2 x i32> %nota, <i32 42, i32 42>
76   ret <2 x i1> %cmp
79 define <2 x i1> @test7(<2 x i32> %A, <2 x i32> %B) {
80 ; CHECK-LABEL: @test7(
81 ; CHECK-NEXT:    [[COND:%.*]] = icmp sgt <2 x i32> [[A:%.*]], [[B:%.*]]
82 ; CHECK-NEXT:    ret <2 x i1> [[COND]]
84   %cond = icmp sle <2 x i32> %A, %B
85   %Ret = xor <2 x i1> %cond, <i1 true, i1 true>
86   ret <2 x i1> %Ret
89 define i32 @not_ashr_not(i32 %A, i32 %B) {
90 ; CHECK-LABEL: @not_ashr_not(
91 ; CHECK-NEXT:    [[NOT2:%.*]] = ashr i32 [[A:%.*]], [[B:%.*]]
92 ; CHECK-NEXT:    ret i32 [[NOT2]]
94   %not1 = xor i32 %A, -1
95   %ashr = ashr i32 %not1, %B
96   %not2 = xor i32 %ashr, -1
97   ret i32 %not2
100 define i8 @not_ashr_const(i8 %x) {
101 ; CHECK-LABEL: @not_ashr_const(
102 ; CHECK-NEXT:    [[NOT:%.*]] = lshr i8 41, [[X:%.*]]
103 ; CHECK-NEXT:    ret i8 [[NOT]]
105   %shr = ashr i8 -42, %x
106   %not = xor i8 %shr, -1
107   ret i8 %not
110 define <2 x i8> @not_ashr_const_splat(<2 x i8> %x) {
111 ; CHECK-LABEL: @not_ashr_const_splat(
112 ; CHECK-NEXT:    [[NOT:%.*]] = lshr <2 x i8> <i8 41, i8 41>, [[X:%.*]]
113 ; CHECK-NEXT:    ret <2 x i8> [[NOT]]
115   %shr = ashr <2 x i8> <i8 -42, i8 -42>, %x
116   %not = xor <2 x i8> %shr, <i8 -1, i8 -1>
117   ret <2 x i8> %not
120 ; We can't get rid of the 'not' on a logical shift of a negative constant.
122 define i8 @not_lshr_const_negative(i8 %x) {
123 ; CHECK-LABEL: @not_lshr_const_negative(
124 ; CHECK-NEXT:    [[SHR:%.*]] = lshr i8 -42, [[X:%.*]]
125 ; CHECK-NEXT:    [[NOT:%.*]] = xor i8 [[SHR]], -1
126 ; CHECK-NEXT:    ret i8 [[NOT]]
128   %shr = lshr i8 -42, %x
129   %not = xor i8 %shr, -1
130   ret i8 %not
133 define i8 @not_lshr_const(i8 %x) {
134 ; CHECK-LABEL: @not_lshr_const(
135 ; CHECK-NEXT:    [[NOT:%.*]] = ashr i8 -43, [[X:%.*]]
136 ; CHECK-NEXT:    ret i8 [[NOT]]
138   %shr = lshr i8 42, %x
139   %not = xor i8 %shr, -1
140   ret i8 %not
143 define <2 x i8> @not_lshr_const_splat(<2 x i8> %x) {
144 ; CHECK-LABEL: @not_lshr_const_splat(
145 ; CHECK-NEXT:    [[NOT:%.*]] = ashr <2 x i8> <i8 -43, i8 -43>, [[X:%.*]]
146 ; CHECK-NEXT:    ret <2 x i8> [[NOT]]
148   %shr = lshr <2 x i8> <i8 42, i8 42>, %x
149   %not = xor <2 x i8> %shr, <i8 -1, i8 -1>
150   ret <2 x i8> %not
153 define i32 @not_sub(i32 %y) {
154 ; CHECK-LABEL: @not_sub(
155 ; CHECK-NEXT:    [[R:%.*]] = add i32 [[Y:%.*]], -124
156 ; CHECK-NEXT:    ret i32 [[R]]
158   %s = sub i32 123, %y
159   %r = xor i32 %s, -1
160   ret i32 %r
163 define i32 @not_sub_extra_use(i32 %y, i32* %p) {
164 ; CHECK-LABEL: @not_sub_extra_use(
165 ; CHECK-NEXT:    [[S:%.*]] = sub i32 123, [[Y:%.*]]
166 ; CHECK-NEXT:    store i32 [[S]], i32* [[P:%.*]], align 4
167 ; CHECK-NEXT:    [[R:%.*]] = add i32 [[Y]], -124
168 ; CHECK-NEXT:    ret i32 [[R]]
170   %s = sub i32 123, %y
171   store i32 %s, i32* %p
172   %r = xor i32 %s, -1
173   ret i32 %r
176 define <2 x i32> @not_sub_splat(<2 x i32> %y) {
177 ; CHECK-LABEL: @not_sub_splat(
178 ; CHECK-NEXT:    [[R:%.*]] = add <2 x i32> [[Y:%.*]], <i32 -124, i32 -124>
179 ; CHECK-NEXT:    ret <2 x i32> [[R]]
181   %s = sub <2 x i32> <i32 123, i32 123>, %y
182   %r = xor <2 x i32> %s, <i32 -1, i32 -1>
183   ret <2 x i32> %r
186 define <2 x i32> @not_sub_extra_use_splat(<2 x i32> %y, <2 x i32>* %p) {
187 ; CHECK-LABEL: @not_sub_extra_use_splat(
188 ; CHECK-NEXT:    [[S:%.*]] = sub <2 x i32> <i32 123, i32 123>, [[Y:%.*]]
189 ; CHECK-NEXT:    store <2 x i32> [[S]], <2 x i32>* [[P:%.*]], align 8
190 ; CHECK-NEXT:    [[R:%.*]] = add <2 x i32> [[Y]], <i32 -124, i32 -124>
191 ; CHECK-NEXT:    ret <2 x i32> [[R]]
193   %s = sub <2 x i32> <i32 123, i32 123>, %y
194   store <2 x i32> %s, <2 x i32>* %p
195   %r = xor <2 x i32> %s, <i32 -1, i32 -1>
196   ret <2 x i32> %r
199 define <2 x i32> @not_sub_vec(<2 x i32> %y) {
200 ; CHECK-LABEL: @not_sub_vec(
201 ; CHECK-NEXT:    [[R:%.*]] = add <2 x i32> [[Y:%.*]], <i32 -43, i32 -124>
202 ; CHECK-NEXT:    ret <2 x i32> [[R]]
204   %s = sub <2 x i32> <i32 42, i32 123>, %y
205   %r = xor <2 x i32> %s, <i32 -1, i32 -1>
206   ret <2 x i32> %r
209 define <2 x i32> @not_sub_extra_use_vec(<2 x i32> %y, <2 x i32>* %p) {
210 ; CHECK-LABEL: @not_sub_extra_use_vec(
211 ; CHECK-NEXT:    [[S:%.*]] = sub <2 x i32> <i32 123, i32 42>, [[Y:%.*]]
212 ; CHECK-NEXT:    store <2 x i32> [[S]], <2 x i32>* [[P:%.*]], align 8
213 ; CHECK-NEXT:    [[R:%.*]] = add <2 x i32> [[Y]], <i32 -124, i32 -43>
214 ; CHECK-NEXT:    ret <2 x i32> [[R]]
216   %s = sub <2 x i32> <i32 123, i32 42>, %y
217   store <2 x i32> %s, <2 x i32>* %p
218   %r = xor <2 x i32> %s, <i32 -1, i32 -1>
219   ret <2 x i32> %r
222 ; ~(X + C) --> -X - C - 1 --> -(C + 1) - X
224 define i32 @not_add(i32 %x) {
225 ; CHECK-LABEL: @not_add(
226 ; CHECK-NEXT:    [[R:%.*]] = sub i32 -124, [[X:%.*]]
227 ; CHECK-NEXT:    ret i32 [[R]]
229   %a = add i32 %x, 123
230   %r = xor i32 %a, -1
231   ret i32 %r
234 define <2 x i32> @not_add_splat(<2 x i32> %x) {
235 ; CHECK-LABEL: @not_add_splat(
236 ; CHECK-NEXT:    [[R:%.*]] = sub <2 x i32> <i32 -124, i32 -124>, [[X:%.*]]
237 ; CHECK-NEXT:    ret <2 x i32> [[R]]
239   %a = add <2 x i32> %x, <i32 123, i32 123>
240   %r = xor <2 x i32> %a, <i32 -1, i32 -1>
241   ret <2 x i32> %r
244 define <2 x i32> @not_add_vec(<2 x i32> %x) {
245 ; CHECK-LABEL: @not_add_vec(
246 ; CHECK-NEXT:    [[R:%.*]] = sub <2 x i32> <i32 -43, i32 -124>, [[X:%.*]]
247 ; CHECK-NEXT:    ret <2 x i32> [[R]]
249   %a = add <2 x i32> %x, <i32 42, i32 123>
250   %r = xor <2 x i32> %a, <i32 -1, i32 -1>
251   ret <2 x i32> %r