1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2; RUN: opt < %s -instcombine -S | FileCheck %s
3
4declare void @use(i8)
5
6define i8 @sub_not(i8 %x, i8 %y) {
7; CHECK-LABEL: @sub_not(
8; CHECK-NEXT:    [[TMP1:%.*]] = xor i8 [[X:%.*]], -1
9; CHECK-NEXT:    [[R:%.*]] = add i8 [[TMP1]], [[Y:%.*]]
10; CHECK-NEXT:    ret i8 [[R]]
11;
12  %s = sub i8 %x, %y
13  %r = xor i8 %s, -1
14  ret i8 %r
15}
16
17define i8 @sub_not_extra_use(i8 %x, i8 %y) {
18; CHECK-LABEL: @sub_not_extra_use(
19; CHECK-NEXT:    [[S:%.*]] = sub i8 [[X:%.*]], [[Y:%.*]]
20; CHECK-NEXT:    [[R:%.*]] = xor i8 [[S]], -1
21; CHECK-NEXT:    call void @use(i8 [[S]])
22; CHECK-NEXT:    ret i8 [[R]]
23;
24  %s = sub i8 %x, %y
25  %r = xor i8 %s, -1
26  call void @use(i8 %s)
27  ret i8 %r
28}
29
30define <2 x i8> @sub_not_vec(<2 x i8> %x, <2 x i8> %y) {
31; CHECK-LABEL: @sub_not_vec(
32; CHECK-NEXT:    [[TMP1:%.*]] = xor <2 x i8> [[X:%.*]], <i8 -1, i8 -1>
33; CHECK-NEXT:    [[R:%.*]] = add <2 x i8> [[TMP1]], [[Y:%.*]]
34; CHECK-NEXT:    ret <2 x i8> [[R]]
35;
36  %s = sub <2 x i8> %x, %y
37  %r = xor <2 x i8> %s, <i8 -1, i8 undef>
38  ret <2 x i8> %r
39}
40
41define i8 @dec_sub(i8 %x, i8 %y) {
42; CHECK-LABEL: @dec_sub(
43; CHECK-NEXT:    [[TMP1:%.*]] = xor i8 [[Y:%.*]], -1
44; CHECK-NEXT:    [[R:%.*]] = add i8 [[TMP1]], [[X:%.*]]
45; CHECK-NEXT:    ret i8 [[R]]
46;
47  %s = sub i8 %x, %y
48  %r = add i8 %s, -1
49  ret i8 %r
50}
51
52define i8 @dec_sub_extra_use(i8 %x, i8 %y) {
53; CHECK-LABEL: @dec_sub_extra_use(
54; CHECK-NEXT:    [[S:%.*]] = sub i8 [[X:%.*]], [[Y:%.*]]
55; CHECK-NEXT:    [[R:%.*]] = add i8 [[S]], -1
56; CHECK-NEXT:    call void @use(i8 [[S]])
57; CHECK-NEXT:    ret i8 [[R]]
58;
59  %s = sub i8 %x, %y
60  %r = add i8 %s, -1
61  call void @use(i8 %s)
62  ret i8 %r
63}
64
65define <2 x i8> @dec_sub_vec(<2 x i8> %x, <2 x i8> %y) {
66; CHECK-LABEL: @dec_sub_vec(
67; CHECK-NEXT:    [[TMP1:%.*]] = xor <2 x i8> [[Y:%.*]], <i8 -1, i8 -1>
68; CHECK-NEXT:    [[R:%.*]] = add <2 x i8> [[TMP1]], [[X:%.*]]
69; CHECK-NEXT:    ret <2 x i8> [[R]]
70;
71  %s = sub <2 x i8> %x, %y
72  %r = add <2 x i8> %s, <i8 -1, i8 undef>
73  ret <2 x i8> %r
74}
75
76define i8 @sub_inc(i8 %x, i8 %y) {
77; CHECK-LABEL: @sub_inc(
78; CHECK-NEXT:    [[TMP1:%.*]] = xor i8 [[X:%.*]], -1
79; CHECK-NEXT:    [[R:%.*]] = add i8 [[TMP1]], [[Y:%.*]]
80; CHECK-NEXT:    ret i8 [[R]]
81;
82  %s = add i8 %x, 1
83  %r = sub i8 %y, %s
84  ret i8 %r
85}
86
87define i8 @sub_inc_extra_use(i8 %x, i8 %y) {
88; CHECK-LABEL: @sub_inc_extra_use(
89; CHECK-NEXT:    [[S:%.*]] = add i8 [[X:%.*]], 1
90; CHECK-NEXT:    [[R:%.*]] = sub i8 [[Y:%.*]], [[S]]
91; CHECK-NEXT:    call void @use(i8 [[S]])
92; CHECK-NEXT:    ret i8 [[R]]
93;
94  %s = add i8 %x, 1
95  %r = sub i8 %y, %s
96  call void @use(i8 %s)
97  ret i8 %r
98}
99
100define <2 x i8> @sub_inc_vec(<2 x i8> %x, <2 x i8> %y) {
101; CHECK-LABEL: @sub_inc_vec(
102; CHECK-NEXT:    [[TMP1:%.*]] = xor <2 x i8> [[X:%.*]], <i8 -1, i8 -1>
103; CHECK-NEXT:    [[R:%.*]] = add <2 x i8> [[TMP1]], [[Y:%.*]]
104; CHECK-NEXT:    ret <2 x i8> [[R]]
105;
106  %s = add <2 x i8> %x, <i8 undef, i8 1>
107  %r = sub <2 x i8> %y, %s
108  ret <2 x i8> %r
109}
110
111define i8 @sub_dec(i8 %x, i8 %y) {
112; CHECK-LABEL: @sub_dec(
113; CHECK-NEXT:    [[TMP1:%.*]] = xor i8 [[Y:%.*]], -1
114; CHECK-NEXT:    [[R:%.*]] = add i8 [[TMP1]], [[X:%.*]]
115; CHECK-NEXT:    ret i8 [[R]]
116;
117  %s = add i8 %x, -1
118  %r = sub i8 %s, %y
119  ret i8 %r
120}
121
122define i8 @sub_dec_extra_use(i8 %x, i8 %y) {
123; CHECK-LABEL: @sub_dec_extra_use(
124; CHECK-NEXT:    [[S:%.*]] = add i8 [[X:%.*]], -1
125; CHECK-NEXT:    [[R:%.*]] = sub i8 [[S]], [[Y:%.*]]
126; CHECK-NEXT:    call void @use(i8 [[S]])
127; CHECK-NEXT:    ret i8 [[R]]
128;
129  %s = add i8 %x, -1
130  %r = sub i8 %s, %y
131  call void @use(i8 %s)
132  ret i8 %r
133}
134
135define <2 x i8> @sub_dec_vec(<2 x i8> %x, <2 x i8> %y) {
136; CHECK-LABEL: @sub_dec_vec(
137; CHECK-NEXT:    [[TMP1:%.*]] = xor <2 x i8> [[Y:%.*]], <i8 -1, i8 -1>
138; CHECK-NEXT:    [[R:%.*]] = add <2 x i8> [[TMP1]], [[X:%.*]]
139; CHECK-NEXT:    ret <2 x i8> [[R]]
140;
141  %s = add <2 x i8> %x, <i8 undef, i8 -1>
142  %r = sub <2 x i8> %s, %y
143  ret <2 x i8> %r
144}
145
146