blob: be26f5712e7fe2a3078509c662a5d57fbebaf0a7 [file] [log] [blame]
Chen Zheng0f609db2018-07-20 13:38:59 +00001; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
Chen Zhengc992cc42018-07-17 01:04:41 +00002; RUN: opt < %s -instsimplify -S | FileCheck %s
Chen Zheng1ff49312018-07-16 15:06:42 +00003
4define i32 @negated_operand(i32 %x) {
5; CHECK-LABEL: @negated_operand(
6; CHECK-NEXT: [[NEGX:%.*]] = sub nsw i32 0, [[X:%.*]]
7; CHECK-NEXT: [[DIV:%.*]] = sdiv i32 [[NEGX]], [[X]]
8; CHECK-NEXT: ret i32 [[DIV]]
9;
10 %negx = sub nsw i32 0, %x
11 %div = sdiv i32 %negx, %x
12 ret i32 %div
13}
14
15define <2 x i32> @negated_operand_commute_vec(<2 x i32> %x) {
16; CHECK-LABEL: @negated_operand_commute_vec(
17; CHECK-NEXT: [[NEGX:%.*]] = sub nsw <2 x i32> zeroinitializer, [[X:%.*]]
18; CHECK-NEXT: [[DIV:%.*]] = sdiv <2 x i32> [[NEGX]], [[X]]
19; CHECK-NEXT: ret <2 x i32> [[DIV]]
20;
21 %negx = sub nsw <2 x i32> zeroinitializer, %x
22 %div = sdiv <2 x i32> %negx, %x
23 ret <2 x i32> %div
24}
25
26define i32 @knownnegation(i32 %x, i32 %y) {
27; CHECK-LABEL: @knownnegation(
28; CHECK-NEXT: [[XY:%.*]] = sub nsw i32 [[X:%.*]], [[Y:%.*]]
29; CHECK-NEXT: [[YX:%.*]] = sub nsw i32 [[Y]], [[X]]
30; CHECK-NEXT: [[DIV:%.*]] = sdiv i32 [[XY]], [[YX]]
31; CHECK-NEXT: ret i32 [[DIV]]
32;
33 %xy = sub nsw i32 %x, %y
34 %yx = sub nsw i32 %y, %x
35 %div = sdiv i32 %xy, %yx
36 ret i32 %div
37}
38
39define <2 x i32> @knownnegation_commute_vec(<2 x i32> %x, <2 x i32> %y) {
40; CHECK-LABEL: @knownnegation_commute_vec(
41; CHECK-NEXT: [[XY:%.*]] = sub nsw <2 x i32> [[X:%.*]], [[Y:%.*]]
42; CHECK-NEXT: [[YX:%.*]] = sub nsw <2 x i32> [[Y]], [[X]]
43; CHECK-NEXT: [[DIV:%.*]] = sdiv <2 x i32> [[XY]], [[YX]]
44; CHECK-NEXT: ret <2 x i32> [[DIV]]
45;
46 %xy = sub nsw <2 x i32> %x, %y
47 %yx = sub nsw <2 x i32> %y, %x
48 %div = sdiv <2 x i32> %xy, %yx
49 ret <2 x i32> %div
50}
Chen Zheng0f609db2018-07-20 13:38:59 +000051
52define i32 @negated_operand_2(i32 %t) {
53; CHECK-LABEL: @negated_operand_2(
54; CHECK-NEXT: [[X:%.*]] = sub i32 [[T:%.*]], 5
55; CHECK-NEXT: [[NEGX:%.*]] = sub nsw i32 0, [[X]]
56; CHECK-NEXT: [[DIV:%.*]] = sdiv i32 [[NEGX]], [[X]]
57; CHECK-NEXT: ret i32 [[DIV]]
58;
59 %x = sub i32 %t, 5
60 %negx = sub nsw i32 0, %x
61 %div = sdiv i32 %negx, %x
62 ret i32 %div
63}
64
65define i32 @negated_operand_commute(i32 %x) {
66; CHECK-LABEL: @negated_operand_commute(
67; CHECK-NEXT: [[NEGX:%.*]] = sub nsw i32 0, [[X]]
68; CHECK-NEXT: [[DIV:%.*]] = sdiv i32 [[X]], [[NEGX]]
69; CHECK-NEXT: ret i32 [[DIV]]
70;
71 %negx = sub nsw i32 0, %x
72 %div = sdiv i32 %x, %negx
73 ret i32 %div
74}
75
76define i32 @negated_operand_bad(i32 %x) {
77; CHECK-LABEL: @negated_operand_bad(
78; CHECK-NEXT: [[NEGX:%.*]] = sub i32 0, [[X:%.*]]
79; CHECK-NEXT: [[DIV:%.*]] = sdiv i32 [[NEGX]], [[X]]
80; CHECK-NEXT: ret i32 [[DIV]]
81;
82 %negx = sub i32 0, %x ; not nsw
83 %div = sdiv i32 %negx, %x
84 ret i32 %div
85}
86
87define i32 @knownnegation_bad_1(i32 %x, i32 %y) {
88; CHECK-LABEL: @knownnegation_bad_1(
89; CHECK-NEXT: [[XY:%.*]] = sub nsw i32 [[X:%.*]], [[Y:%.*]]
90; CHECK-NEXT: [[YX:%.*]] = sub i32 [[Y]], [[X]]
91; CHECK-NEXT: [[DIV:%.*]] = sdiv i32 [[XY]], [[YX]]
92; CHECK-NEXT: ret i32 [[DIV]]
93;
94 %xy = sub nsw i32 %x, %y
95 %yx = sub i32 %y, %x ; not nsw
96 %div = sdiv i32 %xy, %yx
97 ret i32 %div
98}
99
100define i32 @knownnegation_bad_2(i32 %x, i32 %y) {
101; CHECK-LABEL: @knownnegation_bad_2(
102; CHECK-NEXT: [[XY:%.*]] = sub i32 [[X:%.*]], [[Y:%.*]]
103; CHECK-NEXT: [[YX:%.*]] = sub nsw i32 [[Y]], [[X]]
104; CHECK-NEXT: [[DIV:%.*]] = sdiv i32 [[XY]], [[YX]]
105; CHECK-NEXT: ret i32 [[DIV]]
106;
107 %xy = sub i32 %x, %y ; not nsw
108 %yx = sub nsw i32 %y, %x
109 %div = sdiv i32 %xy, %yx
110 ret i32 %div
111}
112
113define i32 @knownnegation_bad_3(i32 %x, i32 %y) {
114; CHECK-LABEL: @knownnegation_bad_3(
115; CHECK-NEXT: [[XY:%.*]] = sub i32 [[X:%.*]], [[Y:%.*]]
116; CHECK-NEXT: [[YX:%.*]] = sub i32 [[Y]], [[X]]
117; CHECK-NEXT: [[DIV:%.*]] = sdiv i32 [[XY]], [[YX]]
118; CHECK-NEXT: ret i32 [[DIV]]
119;
120 %xy = sub i32 %x, %y ; not nsw
121 %yx = sub i32 %y, %x ; not nsw
122 %div = sdiv i32 %xy, %yx
123 ret i32 %div
124}
125
126define <2 x i32> @negated_operand_commute_vec_bad(<2 x i32> %x) {
127; CHECK-LABEL: @negated_operand_commute_vec_bad(
128; CHECK-NEXT: [[NEGX:%.*]] = sub <2 x i32> zeroinitializer, [[X:%.*]]
129; CHECK-NEXT: [[DIV:%.*]] = sdiv <2 x i32> [[NEGX]], [[X]]
130; CHECK-NEXT: ret <2 x i32> [[DIV]]
131;
132 %negx = sub <2 x i32> zeroinitializer, %x ; not nsw
133 %div = sdiv <2 x i32> %negx, %x
134 ret <2 x i32> %div
135}
136
137define <2 x i32> @knownnegation_commute_vec_bad1(<2 x i32> %x, <2 x i32> %y) {
138; CHECK-LABEL: @knownnegation_commute_vec_bad1(
139; CHECK-NEXT: [[XY:%.*]] = sub nsw <2 x i32> [[X:%.*]], [[Y:%.*]]
140; CHECK-NEXT: [[YX:%.*]] = sub <2 x i32> [[Y]], [[X]]
141; CHECK-NEXT: [[DIV:%.*]] = sdiv <2 x i32> [[XY]], [[YX]]
142; CHECK-NEXT: ret <2 x i32> [[DIV]]
143;
144 %xy = sub nsw <2 x i32> %x, %y
145 %yx = sub <2 x i32> %y, %x ; not nsw
146 %div = sdiv <2 x i32> %xy, %yx
147 ret <2 x i32> %div
148}
149
150define <2 x i32> @knownnegation_commute_vec_bad2(<2 x i32> %x, <2 x i32> %y) {
151; CHECK-LABEL: @knownnegation_commute_vec_bad2(
152; CHECK-NEXT: [[XY:%.*]] = sub <2 x i32> [[X:%.*]], [[Y:%.*]]
153; CHECK-NEXT: [[YX:%.*]] = sub nsw <2 x i32> [[Y]], [[X]]
154; CHECK-NEXT: [[DIV:%.*]] = sdiv <2 x i32> [[XY]], [[YX]]
155; CHECK-NEXT: ret <2 x i32> [[DIV]]
156;
157 %xy = sub <2 x i32> %x, %y ; not nsw
158 %yx = sub nsw <2 x i32> %y, %x
159 %div = sdiv <2 x i32> %xy, %yx
160 ret <2 x i32> %div
161}
162
163define <2 x i32> @knownnegation_commute_vec_bad3(<2 x i32> %x, <2 x i32> %y) {
164; CHECK-LABEL: @knownnegation_commute_vec_bad3(
165; CHECK-NEXT: [[XY:%.*]] = sub <2 x i32> [[X:%.*]], [[Y:%.*]]
166; CHECK-NEXT: [[YX:%.*]] = sub <2 x i32> [[Y]], [[X]]
167; CHECK-NEXT: [[DIV:%.*]] = sdiv <2 x i32> [[XY]], [[YX]]
168; CHECK-NEXT: ret <2 x i32> [[DIV]]
169;
170 %xy = sub <2 x i32> %x, %y ; not nsw
171 %yx = sub <2 x i32> %y, %x ; not nsw
172 %div = sdiv <2 x i32> %xy, %yx
173 ret <2 x i32> %div
174}
175
176define <3 x i32> @negated_operand_vec_undef(<3 x i32> %x) {
177; CHECK-LABEL: @negated_operand_vec_undef(
178; CHECK-NEXT: [[NEGX:%.*]] = sub nsw <3 x i32> <i32 0, i32 undef, i32 0>, [[X:%.*]]
179; CHECK-NEXT: [[DIV:%.*]] = sdiv <3 x i32> [[NEGX]], [[X]]
180; CHECK-NEXT: ret <3 x i32> [[DIV]]
181;
182 %negx = sub nsw <3 x i32> <i32 0, i32 undef, i32 0>, %x
183 %div = sdiv <3 x i32> %negx, %x
184 ret <3 x i32> %div
185}
186
187define <2 x i32> @negated_operand_vec_nonsplat(<2 x i32> %x) {
188; CHECK-LABEL: @negated_operand_vec_nonsplat(
189; CHECK-NEXT: [[NEGX:%.*]] = sub nsw <2 x i32> <i32 0, i32 1>, [[X:%.*]]
190; CHECK-NEXT: [[DIV:%.*]] = sdiv <2 x i32> [[NEGX]], [[X]]
191; CHECK-NEXT: ret <2 x i32> [[DIV]]
192;
193 %negx = sub nsw <2 x i32> <i32 0, i32 1>, %x ; not 0, don't fold
194 %div = sdiv <2 x i32> %negx, %x
195 ret <2 x i32> %div
196}