• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2; RUN: opt -instcombine -S < %s | FileCheck %s
3
4declare void @use(i8)
5
6define i8 @basic(i8 %x, i8 %y) {
7; CHECK-LABEL: @basic(
8; CHECK-NEXT:    [[NOTA:%.*]] = sub i8 [[X:%.*]], [[Y:%.*]]
9; CHECK-NEXT:    ret i8 [[NOTA]]
10;
11  %notx = xor i8 %x, -1
12  %a = add i8 %notx, %y
13  %nota = xor i8 %a, -1
14  ret i8 %nota
15}
16
17define 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]]
21;
22  %noty = xor i8 %y, -1
23  %a = add i8 %x, %noty
24  %nota = xor i8 %a, -1
25  ret i8 %nota
26}
27
28define 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]]
34;
35  %notx = xor i8 %x, -1
36  call void @use(i8 %notx)
37  %a = add i8 %notx, %y
38  %nota = xor i8 %a, -1
39  ret i8 %nota
40}
41
42define 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]]
49;
50  %notx = xor i8 %x, -1
51  %a = add i8 %notx, %y
52  call void @use(i8 %a)
53  %nota = xor i8 %a, -1
54  ret i8 %nota
55}
56
57define 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]]
65;
66  %notx = xor i8 %x, -1
67  call void @use(i8 %notx)
68  %a = add i8 %notx, %y
69  call void @use(i8 %a)
70  %nota = xor i8 %a, -1
71  ret i8 %nota
72}
73
74define 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]]
78;
79  %notx = xor i8 %x, -1
80  %a = add nsw i8 %notx, %y
81  %nota = xor i8 %a, -1
82  ret i8 %nota
83}
84
85define 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]]
89;
90  %notx = xor i8 %x, -1
91  %a = add nuw i8 %notx, %y
92  %nota = xor i8 %a, -1
93  ret i8 %nota
94}
95
96define 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]]
100;
101  %notx = xor i8 %x, -1
102  %a = add nuw nsw i8 %notx, %y
103  %nota = xor i8 %a, -1
104  ret i8 %nota
105}
106
107define <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]]
111;
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>
115  ret <4 x i32> %nota
116}
117
118define <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]]
122;
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>
126  ret <4 x i32> %nota
127}
128
129
130define <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]]
134;
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>
138  ret <4 x i32> %nota
139}
140