1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -instcombine -S < %s | FileCheck %s
6 define i8 @basic(i8 %x, i8 %y) {
8 ; CHECK-NEXT: [[NOTA:%.*]] = sub i8 [[X:%.*]], [[Y:%.*]]
9 ; CHECK-NEXT: ret i8 [[NOTA]]
17 define i8 @basic_com_add(i8 %x, i8 %y) {
18 ; CHECK-LABEL: @basic_com_add(
19 ; CHECK-NEXT: [[NOTA:%.*]] = sub i8 [[Y:%.*]], [[X:%.*]]
20 ; CHECK-NEXT: ret i8 [[NOTA]]
28 define i8 @basic_use_xor(i8 %x, i8 %y) {
29 ; CHECK-LABEL: @basic_use_xor(
30 ; CHECK-NEXT: [[NOTX:%.*]] = xor i8 [[X:%.*]], -1
31 ; CHECK-NEXT: call void @use(i8 [[NOTX]])
32 ; CHECK-NEXT: [[NOTA:%.*]] = sub i8 [[X]], [[Y:%.*]]
33 ; CHECK-NEXT: ret i8 [[NOTA]]
36 call void @use(i8 %notx)
42 define i8 @basic_use_add(i8 %x, i8 %y) {
43 ; CHECK-LABEL: @basic_use_add(
44 ; CHECK-NEXT: [[NOTX:%.*]] = xor i8 [[X:%.*]], -1
45 ; CHECK-NEXT: [[A:%.*]] = add i8 [[NOTX]], [[Y:%.*]]
46 ; CHECK-NEXT: call void @use(i8 [[A]])
47 ; CHECK-NEXT: [[NOTA:%.*]] = sub i8 [[X]], [[Y]]
48 ; CHECK-NEXT: ret i8 [[NOTA]]
57 define i8 @basic_use_both(i8 %x, i8 %y) {
58 ; CHECK-LABEL: @basic_use_both(
59 ; CHECK-NEXT: [[NOTX:%.*]] = xor i8 [[X:%.*]], -1
60 ; CHECK-NEXT: call void @use(i8 [[NOTX]])
61 ; CHECK-NEXT: [[A:%.*]] = add i8 [[NOTX]], [[Y:%.*]]
62 ; CHECK-NEXT: call void @use(i8 [[A]])
63 ; CHECK-NEXT: [[NOTA:%.*]] = sub i8 [[X]], [[Y]]
64 ; CHECK-NEXT: ret i8 [[NOTA]]
67 call void @use(i8 %notx)
74 define i8 @basic_preserve_nsw(i8 %x, i8 %y) {
75 ; CHECK-LABEL: @basic_preserve_nsw(
76 ; CHECK-NEXT: [[NOTA:%.*]] = sub nsw i8 [[X:%.*]], [[Y:%.*]]
77 ; CHECK-NEXT: ret i8 [[NOTA]]
80 %a = add nsw i8 %notx, %y
85 define i8 @basic_preserve_nuw(i8 %x, i8 %y) {
86 ; CHECK-LABEL: @basic_preserve_nuw(
87 ; CHECK-NEXT: [[NOTA:%.*]] = sub nuw i8 [[X:%.*]], [[Y:%.*]]
88 ; CHECK-NEXT: ret i8 [[NOTA]]
91 %a = add nuw i8 %notx, %y
96 define i8 @basic_preserve_nuw_nsw(i8 %x, i8 %y) {
97 ; CHECK-LABEL: @basic_preserve_nuw_nsw(
98 ; CHECK-NEXT: [[NOTA:%.*]] = sub nuw nsw i8 [[X:%.*]], [[Y:%.*]]
99 ; CHECK-NEXT: ret i8 [[NOTA]]
101 %notx = xor i8 %x, -1
102 %a = add nuw nsw i8 %notx, %y
103 %nota = xor i8 %a, -1
107 define <4 x i32> @vector_test(<4 x i32> %x, <4 x i32> %y) {
108 ; CHECK-LABEL: @vector_test(
109 ; CHECK-NEXT: [[NOTA:%.*]] = sub <4 x i32> [[X:%.*]], [[Y:%.*]]
110 ; CHECK-NEXT: ret <4 x i32> [[NOTA]]
112 %notx = xor <4 x i32> %x, <i32 -1, i32 -1, i32 -1, i32 -1>
113 %a = add <4 x i32> %notx, %y
114 %nota = xor <4 x i32> %a, <i32 -1, i32 -1, i32 -1, i32 -1>
118 define <4 x i32> @vector_test_undef(<4 x i32> %x, <4 x i32> %y) {
119 ; CHECK-LABEL: @vector_test_undef(
120 ; CHECK-NEXT: [[NOTA:%.*]] = sub <4 x i32> [[X:%.*]], [[Y:%.*]]
121 ; CHECK-NEXT: ret <4 x i32> [[NOTA]]
123 %notx = xor <4 x i32> %x, <i32 -1, i32 undef, i32 undef, i32 -1>
124 %a = add <4 x i32> %notx, %y
125 %nota = xor <4 x i32> %a, <i32 -1, i32 -1, i32 undef, i32 undef>
130 define <4 x i32> @vector_test_undef_nsw_nuw(<4 x i32> %x, <4 x i32> %y) {
131 ; CHECK-LABEL: @vector_test_undef_nsw_nuw(
132 ; CHECK-NEXT: [[NOTA:%.*]] = sub nuw nsw <4 x i32> [[X:%.*]], [[Y:%.*]]
133 ; CHECK-NEXT: ret <4 x i32> [[NOTA]]
135 %notx = xor <4 x i32> %x, <i32 -1, i32 undef, i32 undef, i32 -1>
136 %a = add nsw nuw <4 x i32> %notx, %y
137 %nota = xor <4 x i32> %a, <i32 -1, i32 -1, i32 undef, i32 undef>
141 define i32 @pr50308(i1 %c1, i32 %v1, i32 %v2, i32 %v3) {
142 ; CHECK-LABEL: @pr50308(
144 ; CHECK-NEXT: br i1 [[C1:%.*]], label [[COND_TRUE:%.*]], label [[COND_END:%.*]]
146 ; CHECK-NEXT: [[ADD_NOT:%.*]] = sub i32 -2, [[V1:%.*]]
147 ; CHECK-NEXT: [[ADD1_NEG:%.*]] = xor i32 [[ADD_NOT]], [[V2:%.*]]
148 ; CHECK-NEXT: br label [[COND_END]]
150 ; CHECK-NEXT: [[COND_NEG:%.*]] = phi i32 [ [[ADD1_NEG]], [[COND_TRUE]] ], [ 0, [[ENTRY:%.*]] ]
151 ; CHECK-NEXT: [[SUB:%.*]] = add i32 [[COND_NEG]], [[V3:%.*]]
152 ; CHECK-NEXT: ret i32 [[SUB]]
155 br i1 %c1, label %cond.true, label %cond.end
158 %add = add nsw i32 1, %v1
159 %xor = xor i32 %add, %v2
160 %add1 = add nsw i32 1, %xor
164 %cond = phi i32 [ %add1, %cond.true ], [ 0, %entry ]
165 %sub = sub nsw i32 %v3, %cond
169 @g = extern_weak global i32
170 define void @pr50370(i32 %x) {
171 ; CHECK-LABEL: @pr50370(
173 ; CHECK-NEXT: [[XOR:%.*]] = xor i32 [[X:%.*]], 1
174 ; CHECK-NEXT: [[B15:%.*]] = srem i32 ashr (i32 65536, i32 or (i32 zext (i1 icmp eq (i32* @g, i32* null) to i32), i32 65537)), [[XOR]]
175 ; CHECK-NEXT: [[B22:%.*]] = add nsw i32 [[B15]], sdiv (i32 or (i32 zext (i1 icmp eq (i32* @g, i32* null) to i32), i32 65537), i32 2147483647)
176 ; CHECK-NEXT: [[B14:%.*]] = srem i32 ashr (i32 65536, i32 or (i32 zext (i1 icmp eq (i32* @g, i32* null) to i32), i32 65537)), [[B22]]
177 ; CHECK-NEXT: [[B12:%.*]] = add nuw nsw i32 [[B15]], ashr (i32 65536, i32 or (i32 zext (i1 icmp eq (i32* @g, i32* null) to i32), i32 65537))
178 ; CHECK-NEXT: [[B8:%.*]] = shl i32 sdiv (i32 or (i32 zext (i1 icmp eq (i32* @g, i32* null) to i32), i32 65537), i32 2147483647), [[B14]]
179 ; CHECK-NEXT: [[B2:%.*]] = xor i32 [[B12]], [[B8]]
180 ; CHECK-NEXT: [[B:%.*]] = xor i32 [[B2]], -1
181 ; CHECK-NEXT: store i32 [[B]], i32* undef, align 4
182 ; CHECK-NEXT: ret void
186 %or4 = or i32 or (i32 zext (i1 icmp eq (i32* @g, i32* null) to i32), i32 1), 65536
187 %B6 = ashr i32 65536, %or4
188 %B15 = srem i32 %B6, %xor
189 %B20 = sdiv i32 %or4, 2147483647
190 %B22 = add i32 %B15, %B20
191 %B14 = srem i32 %B6, %B22
192 %B12 = add i32 %B15, %B6
193 %B8 = shl i32 %B20, %B14
194 %B2 = xor i32 %B12, %B8
195 %B3 = or i32 %B12, undef
196 %B = xor i32 %B2, %B3
197 store i32 %B, i32* undef, align 4