Skip to content

Commit 46f31fc

Browse files
committed
codestyle
1 parent 3133f1d commit 46f31fc

File tree

2 files changed

+37
-55
lines changed

2 files changed

+37
-55
lines changed

llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1606,18 +1606,17 @@ foldIntrinsicUsingDistributiveLaws(IntrinsicInst *II,
16061606
if (Op0->isCommutative() && A != C && B != D && A == D)
16071607
std::swap(C, D);
16081608

1609-
if (A != C && B != D)
1610-
return nullptr;
1611-
16121609
BinaryOperator *NewBinop;
16131610
if (A == C) {
16141611
Value *NewIntrinsic = Builder.CreateBinaryIntrinsic(TopLevelOpcode, B, D);
16151612
NewBinop =
16161613
cast<BinaryOperator>(Builder.CreateBinOp(InnerOpcode, A, NewIntrinsic));
1617-
} else { // B == D
1614+
} else if (B == D) {
16181615
Value *NewIntrinsic = Builder.CreateBinaryIntrinsic(TopLevelOpcode, A, C);
16191616
NewBinop =
16201617
cast<BinaryOperator>(Builder.CreateBinOp(InnerOpcode, NewIntrinsic, B));
1618+
} else {
1619+
return nullptr;
16211620
}
16221621

16231622
NewBinop->setHasNoUnsignedWrap(HasNUW);

llvm/test/Transforms/InstCombine/shift-uminmax.ll

Lines changed: 34 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,8 @@
1010
define i32 @umax_shl_common_lhs(i32 %x, i32 %y, i32 %z) {
1111
; CHECK-LABEL: define i32 @umax_shl_common_lhs(
1212
; CHECK-SAME: i32 [[X:%.*]], i32 [[Y:%.*]], i32 [[Z:%.*]]) {
13-
; CHECK-NEXT: [[SHL_X:%.*]] = shl nuw i32 [[Z]], [[X]]
14-
; CHECK-NEXT: [[SHL_Y:%.*]] = shl nuw i32 [[Z]], [[Y]]
15-
; CHECK-NEXT: [[MAX:%.*]] = call i32 @llvm.umax.i32(i32 [[SHL_X]], i32 [[SHL_Y]])
13+
; CHECK-NEXT: [[TMP1:%.*]] = call i32 @llvm.umax.i32(i32 [[X]], i32 [[Y]])
14+
; CHECK-NEXT: [[MAX:%.*]] = shl nuw i32 [[Z]], [[TMP1]]
1615
; CHECK-NEXT: ret i32 [[MAX]]
1716
;
1817
%shl_x = shl nuw i32 %z, %x
@@ -24,9 +23,8 @@ define i32 @umax_shl_common_lhs(i32 %x, i32 %y, i32 %z) {
2423
define i32 @umax_shl_common_rhs(i32 %x, i32 %y, i32 %z) {
2524
; CHECK-LABEL: define i32 @umax_shl_common_rhs(
2625
; CHECK-SAME: i32 [[X:%.*]], i32 [[Y:%.*]], i32 [[Z:%.*]]) {
27-
; CHECK-NEXT: [[SHL_X:%.*]] = shl nuw i32 [[X]], [[Z]]
28-
; CHECK-NEXT: [[SHL_Y:%.*]] = shl nuw i32 [[Y]], [[Z]]
29-
; CHECK-NEXT: [[MAX:%.*]] = call i32 @llvm.umax.i32(i32 [[SHL_X]], i32 [[SHL_Y]])
26+
; CHECK-NEXT: [[TMP1:%.*]] = call i32 @llvm.umax.i32(i32 [[X]], i32 [[Y]])
27+
; CHECK-NEXT: [[MAX:%.*]] = shl nuw i32 [[TMP1]], [[Z]]
3028
; CHECK-NEXT: ret i32 [[MAX]]
3129
;
3230
%shl_x = shl nuw i32 %x, %z
@@ -38,9 +36,8 @@ define i32 @umax_shl_common_rhs(i32 %x, i32 %y, i32 %z) {
3836
define i32 @umin_shl_common_lhs(i32 %x, i32 %y, i32 %z) {
3937
; CHECK-LABEL: define i32 @umin_shl_common_lhs(
4038
; CHECK-SAME: i32 [[X:%.*]], i32 [[Y:%.*]], i32 [[Z:%.*]]) {
41-
; CHECK-NEXT: [[SHL_X:%.*]] = shl nuw i32 [[Z]], [[X]]
42-
; CHECK-NEXT: [[SHL_Y:%.*]] = shl nuw i32 [[Z]], [[Y]]
43-
; CHECK-NEXT: [[MIN:%.*]] = call i32 @llvm.umin.i32(i32 [[SHL_X]], i32 [[SHL_Y]])
39+
; CHECK-NEXT: [[TMP1:%.*]] = call i32 @llvm.umin.i32(i32 [[X]], i32 [[Y]])
40+
; CHECK-NEXT: [[MIN:%.*]] = shl nuw i32 [[Z]], [[TMP1]]
4441
; CHECK-NEXT: ret i32 [[MIN]]
4542
;
4643
%shl_x = shl nuw i32 %z, %x
@@ -52,9 +49,8 @@ define i32 @umin_shl_common_lhs(i32 %x, i32 %y, i32 %z) {
5249
define i32 @umin_shl_common_rhs(i32 %x, i32 %y, i32 %z) {
5350
; CHECK-LABEL: define i32 @umin_shl_common_rhs(
5451
; CHECK-SAME: i32 [[X:%.*]], i32 [[Y:%.*]], i32 [[Z:%.*]]) {
55-
; CHECK-NEXT: [[SHL_X:%.*]] = shl nuw i32 [[X]], [[Z]]
56-
; CHECK-NEXT: [[SHL_Y:%.*]] = shl nuw i32 [[Y]], [[Z]]
57-
; CHECK-NEXT: [[MIN:%.*]] = call i32 @llvm.umin.i32(i32 [[SHL_X]], i32 [[SHL_Y]])
52+
; CHECK-NEXT: [[TMP1:%.*]] = call i32 @llvm.umin.i32(i32 [[X]], i32 [[Y]])
53+
; CHECK-NEXT: [[MIN:%.*]] = shl nuw i32 [[TMP1]], [[Z]]
5854
; CHECK-NEXT: ret i32 [[MIN]]
5955
;
6056
%shl_x = shl nuw i32 %x, %z
@@ -66,9 +62,8 @@ define i32 @umin_shl_common_rhs(i32 %x, i32 %y, i32 %z) {
6662
define i32 @umax_shl_common_lhs_const1(i32 %x, i32 %y) {
6763
; CHECK-LABEL: define i32 @umax_shl_common_lhs_const1(
6864
; CHECK-SAME: i32 [[X:%.*]], i32 [[Y:%.*]]) {
69-
; CHECK-NEXT: [[SHL_X:%.*]] = shl nuw i32 1, [[X]]
70-
; CHECK-NEXT: [[SHL_Y:%.*]] = shl nuw i32 1, [[Y]]
71-
; CHECK-NEXT: [[MAX:%.*]] = call i32 @llvm.umax.i32(i32 [[SHL_X]], i32 [[SHL_Y]])
65+
; CHECK-NEXT: [[TMP1:%.*]] = call i32 @llvm.umax.i32(i32 [[X]], i32 [[Y]])
66+
; CHECK-NEXT: [[MAX:%.*]] = shl nuw i32 1, [[TMP1]]
7267
; CHECK-NEXT: ret i32 [[MAX]]
7368
;
7469
%shl_x = shl nuw i32 1, %x
@@ -80,9 +75,8 @@ define i32 @umax_shl_common_lhs_const1(i32 %x, i32 %y) {
8075
define i32 @umax_shl_common_rhs_const1(i32 %x, i32 %y) {
8176
; CHECK-LABEL: define i32 @umax_shl_common_rhs_const1(
8277
; CHECK-SAME: i32 [[X:%.*]], i32 [[Y:%.*]]) {
83-
; CHECK-NEXT: [[SHL_X:%.*]] = shl nuw i32 [[X]], 1
84-
; CHECK-NEXT: [[SHL_Y:%.*]] = shl nuw i32 [[Y]], 1
85-
; CHECK-NEXT: [[MAX:%.*]] = call i32 @llvm.umax.i32(i32 [[SHL_X]], i32 [[SHL_Y]])
78+
; CHECK-NEXT: [[TMP1:%.*]] = call i32 @llvm.umax.i32(i32 [[X]], i32 [[Y]])
79+
; CHECK-NEXT: [[MAX:%.*]] = shl nuw i32 [[TMP1]], 1
8680
; CHECK-NEXT: ret i32 [[MAX]]
8781
;
8882
%shl_x = shl nuw i32 %x, 1
@@ -94,9 +88,8 @@ define i32 @umax_shl_common_rhs_const1(i32 %x, i32 %y) {
9488
define i32 @umin_shl_common_lhs_const1(i32 %x, i32 %y) {
9589
; CHECK-LABEL: define i32 @umin_shl_common_lhs_const1(
9690
; CHECK-SAME: i32 [[X:%.*]], i32 [[Y:%.*]]) {
97-
; CHECK-NEXT: [[SHL_X:%.*]] = shl nuw i32 1, [[X]]
98-
; CHECK-NEXT: [[SHL_Y:%.*]] = shl nuw i32 1, [[Y]]
99-
; CHECK-NEXT: [[MIN:%.*]] = call i32 @llvm.umin.i32(i32 [[SHL_X]], i32 [[SHL_Y]])
91+
; CHECK-NEXT: [[TMP1:%.*]] = call i32 @llvm.umin.i32(i32 [[X]], i32 [[Y]])
92+
; CHECK-NEXT: [[MIN:%.*]] = shl nuw i32 1, [[TMP1]]
10093
; CHECK-NEXT: ret i32 [[MIN]]
10194
;
10295
%shl_x = shl nuw i32 1, %x
@@ -108,9 +101,8 @@ define i32 @umin_shl_common_lhs_const1(i32 %x, i32 %y) {
108101
define i32 @umin_shl_common_rhs_const1(i32 %x, i32 %y) {
109102
; CHECK-LABEL: define i32 @umin_shl_common_rhs_const1(
110103
; CHECK-SAME: i32 [[X:%.*]], i32 [[Y:%.*]]) {
111-
; CHECK-NEXT: [[SHL_X:%.*]] = shl nuw i32 [[X]], 1
112-
; CHECK-NEXT: [[SHL_Y:%.*]] = shl nuw i32 [[Y]], 1
113-
; CHECK-NEXT: [[MIN:%.*]] = call i32 @llvm.umin.i32(i32 [[SHL_X]], i32 [[SHL_Y]])
104+
; CHECK-NEXT: [[TMP1:%.*]] = call i32 @llvm.umin.i32(i32 [[X]], i32 [[Y]])
105+
; CHECK-NEXT: [[MIN:%.*]] = shl nuw i32 [[TMP1]], 1
114106
; CHECK-NEXT: ret i32 [[MIN]]
115107
;
116108
%shl_x = shl nuw i32 %x, 1
@@ -196,9 +188,8 @@ define i32 @umin_shl_common_rhs_multi_use(i32 %x, i32 %y, i32 %z) {
196188
define i32 @umax_shl_common_lhs_commuted(i32 %x, i32 %y, i32 %z) {
197189
; CHECK-LABEL: define i32 @umax_shl_common_lhs_commuted(
198190
; CHECK-SAME: i32 [[X:%.*]], i32 [[Y:%.*]], i32 [[Z:%.*]]) {
199-
; CHECK-NEXT: [[SHL_X:%.*]] = shl nuw i32 [[Z]], [[X]]
200-
; CHECK-NEXT: [[SHL_Y:%.*]] = shl nuw i32 [[Z]], [[Y]]
201-
; CHECK-NEXT: [[MAX:%.*]] = call i32 @llvm.umax.i32(i32 [[SHL_Y]], i32 [[SHL_X]])
191+
; CHECK-NEXT: [[TMP1:%.*]] = call i32 @llvm.umax.i32(i32 [[Y]], i32 [[X]])
192+
; CHECK-NEXT: [[MAX:%.*]] = shl nuw i32 [[Z]], [[TMP1]]
202193
; CHECK-NEXT: ret i32 [[MAX]]
203194
;
204195
%shl_x = shl nuw i32 %z, %x
@@ -210,9 +201,8 @@ define i32 @umax_shl_common_lhs_commuted(i32 %x, i32 %y, i32 %z) {
210201
define i32 @umax_shl_common_rhs_commuted(i32 %x, i32 %y, i32 %z) {
211202
; CHECK-LABEL: define i32 @umax_shl_common_rhs_commuted(
212203
; CHECK-SAME: i32 [[X:%.*]], i32 [[Y:%.*]], i32 [[Z:%.*]]) {
213-
; CHECK-NEXT: [[SHL_X:%.*]] = shl nuw i32 [[X]], [[Z]]
214-
; CHECK-NEXT: [[SHL_Y:%.*]] = shl nuw i32 [[Y]], [[Z]]
215-
; CHECK-NEXT: [[MAX:%.*]] = call i32 @llvm.umax.i32(i32 [[SHL_Y]], i32 [[SHL_X]])
204+
; CHECK-NEXT: [[TMP1:%.*]] = call i32 @llvm.umax.i32(i32 [[Y]], i32 [[X]])
205+
; CHECK-NEXT: [[MAX:%.*]] = shl nuw i32 [[TMP1]], [[Z]]
216206
; CHECK-NEXT: ret i32 [[MAX]]
217207
;
218208
%shl_x = shl nuw i32 %x, %z
@@ -224,9 +214,8 @@ define i32 @umax_shl_common_rhs_commuted(i32 %x, i32 %y, i32 %z) {
224214
define i32 @umin_shl_common_lhs_commuted(i32 %x, i32 %y, i32 %z) {
225215
; CHECK-LABEL: define i32 @umin_shl_common_lhs_commuted(
226216
; CHECK-SAME: i32 [[X:%.*]], i32 [[Y:%.*]], i32 [[Z:%.*]]) {
227-
; CHECK-NEXT: [[SHL_X:%.*]] = shl nuw i32 [[Z]], [[X]]
228-
; CHECK-NEXT: [[SHL_Y:%.*]] = shl nuw i32 [[Z]], [[Y]]
229-
; CHECK-NEXT: [[MIN:%.*]] = call i32 @llvm.umin.i32(i32 [[SHL_Y]], i32 [[SHL_X]])
217+
; CHECK-NEXT: [[TMP1:%.*]] = call i32 @llvm.umin.i32(i32 [[Y]], i32 [[X]])
218+
; CHECK-NEXT: [[MIN:%.*]] = shl nuw i32 [[Z]], [[TMP1]]
230219
; CHECK-NEXT: ret i32 [[MIN]]
231220
;
232221
%shl_x = shl nuw i32 %z, %x
@@ -238,9 +227,8 @@ define i32 @umin_shl_common_lhs_commuted(i32 %x, i32 %y, i32 %z) {
238227
define i32 @umin_shl_common_rhs_commuted(i32 %x, i32 %y, i32 %z) {
239228
; CHECK-LABEL: define i32 @umin_shl_common_rhs_commuted(
240229
; CHECK-SAME: i32 [[X:%.*]], i32 [[Y:%.*]], i32 [[Z:%.*]]) {
241-
; CHECK-NEXT: [[SHL_X:%.*]] = shl nuw i32 [[X]], [[Z]]
242-
; CHECK-NEXT: [[SHL_Y:%.*]] = shl nuw i32 [[Y]], [[Z]]
243-
; CHECK-NEXT: [[MIN:%.*]] = call i32 @llvm.umin.i32(i32 [[SHL_Y]], i32 [[SHL_X]])
230+
; CHECK-NEXT: [[TMP1:%.*]] = call i32 @llvm.umin.i32(i32 [[Y]], i32 [[X]])
231+
; CHECK-NEXT: [[MIN:%.*]] = shl nuw i32 [[TMP1]], [[Z]]
244232
; CHECK-NEXT: ret i32 [[MIN]]
245233
;
246234
%shl_x = shl nuw i32 %x, %z
@@ -252,9 +240,8 @@ define i32 @umin_shl_common_rhs_commuted(i32 %x, i32 %y, i32 %z) {
252240
define <2 x i32> @umax_shl_common_lhs_vector(<2 x i32> %z, <2 x i32> %x, <2 x i32> %y) {
253241
; CHECK-LABEL: define <2 x i32> @umax_shl_common_lhs_vector(
254242
; CHECK-SAME: <2 x i32> [[Z:%.*]], <2 x i32> [[X:%.*]], <2 x i32> [[Y:%.*]]) {
255-
; CHECK-NEXT: [[SHL_X:%.*]] = shl nuw <2 x i32> [[Z]], [[X]]
256-
; CHECK-NEXT: [[SHL_Y:%.*]] = shl nuw <2 x i32> [[Z]], [[Y]]
257-
; CHECK-NEXT: [[MAX:%.*]] = call <2 x i32> @llvm.umax.v2i32(<2 x i32> [[SHL_X]], <2 x i32> [[SHL_Y]])
243+
; CHECK-NEXT: [[TMP1:%.*]] = call <2 x i32> @llvm.umax.v2i32(<2 x i32> [[X]], <2 x i32> [[Y]])
244+
; CHECK-NEXT: [[MAX:%.*]] = shl nuw <2 x i32> [[Z]], [[TMP1]]
258245
; CHECK-NEXT: ret <2 x i32> [[MAX]]
259246
;
260247
%shl_x = shl nuw <2 x i32> %z, %x
@@ -266,9 +253,8 @@ define <2 x i32> @umax_shl_common_lhs_vector(<2 x i32> %z, <2 x i32> %x, <2 x i3
266253
define <2 x i32> @umax_shl_common_rhs_vector(<2 x i32> %z, <2 x i32> %x, <2 x i32> %y) {
267254
; CHECK-LABEL: define <2 x i32> @umax_shl_common_rhs_vector(
268255
; CHECK-SAME: <2 x i32> [[Z:%.*]], <2 x i32> [[X:%.*]], <2 x i32> [[Y:%.*]]) {
269-
; CHECK-NEXT: [[SHL_X:%.*]] = shl nuw <2 x i32> [[X]], [[Z]]
270-
; CHECK-NEXT: [[SHL_Y:%.*]] = shl nuw <2 x i32> [[Y]], [[Z]]
271-
; CHECK-NEXT: [[MAX:%.*]] = call <2 x i32> @llvm.umax.v2i32(<2 x i32> [[SHL_X]], <2 x i32> [[SHL_Y]])
256+
; CHECK-NEXT: [[TMP1:%.*]] = call <2 x i32> @llvm.umax.v2i32(<2 x i32> [[X]], <2 x i32> [[Y]])
257+
; CHECK-NEXT: [[MAX:%.*]] = shl nuw <2 x i32> [[TMP1]], [[Z]]
272258
; CHECK-NEXT: ret <2 x i32> [[MAX]]
273259
;
274260
%shl_x = shl nuw <2 x i32> %x, %z
@@ -281,9 +267,8 @@ define <2 x i32> @umax_shl_common_rhs_vector(<2 x i32> %z, <2 x i32> %x, <2 x i3
281267
define <2 x i32> @umin_shl_common_lhs_vector(<2 x i32> %z, <2 x i32> %x, <2 x i32> %y) {
282268
; CHECK-LABEL: define <2 x i32> @umin_shl_common_lhs_vector(
283269
; CHECK-SAME: <2 x i32> [[Z:%.*]], <2 x i32> [[X:%.*]], <2 x i32> [[Y:%.*]]) {
284-
; CHECK-NEXT: [[SHL_X:%.*]] = shl nuw <2 x i32> [[Z]], [[X]]
285-
; CHECK-NEXT: [[SHL_Y:%.*]] = shl nuw <2 x i32> [[Z]], [[Y]]
286-
; CHECK-NEXT: [[MIN:%.*]] = call <2 x i32> @llvm.umin.v2i32(<2 x i32> [[SHL_X]], <2 x i32> [[SHL_Y]])
270+
; CHECK-NEXT: [[TMP1:%.*]] = call <2 x i32> @llvm.umin.v2i32(<2 x i32> [[X]], <2 x i32> [[Y]])
271+
; CHECK-NEXT: [[MIN:%.*]] = shl nuw <2 x i32> [[Z]], [[TMP1]]
287272
; CHECK-NEXT: ret <2 x i32> [[MIN]]
288273
;
289274
%shl_x = shl nuw <2 x i32> %z, %x
@@ -295,9 +280,8 @@ define <2 x i32> @umin_shl_common_lhs_vector(<2 x i32> %z, <2 x i32> %x, <2 x i3
295280
define <2 x i32> @umin_shl_common_rhs_vector(<2 x i32> %z, <2 x i32> %x, <2 x i32> %y) {
296281
; CHECK-LABEL: define <2 x i32> @umin_shl_common_rhs_vector(
297282
; CHECK-SAME: <2 x i32> [[Z:%.*]], <2 x i32> [[X:%.*]], <2 x i32> [[Y:%.*]]) {
298-
; CHECK-NEXT: [[SHL_X:%.*]] = shl nuw <2 x i32> [[X]], [[Z]]
299-
; CHECK-NEXT: [[SHL_Y:%.*]] = shl nuw <2 x i32> [[Y]], [[Z]]
300-
; CHECK-NEXT: [[MIN:%.*]] = call <2 x i32> @llvm.umin.v2i32(<2 x i32> [[SHL_X]], <2 x i32> [[SHL_Y]])
283+
; CHECK-NEXT: [[TMP1:%.*]] = call <2 x i32> @llvm.umin.v2i32(<2 x i32> [[X]], <2 x i32> [[Y]])
284+
; CHECK-NEXT: [[MIN:%.*]] = shl nuw <2 x i32> [[TMP1]], [[Z]]
301285
; CHECK-NEXT: ret <2 x i32> [[MIN]]
302286
;
303287
%shl_x = shl nuw <2 x i32> %x, %z
@@ -423,9 +407,8 @@ define i32 @umax_shl_common_rhs_no_nuw_flag(i32 %x, i32 %y) {
423407
define i32 @umax_shl_common_lhs_preserve_nsw(i32 %x, i32 %y, i32 %z) {
424408
; CHECK-LABEL: define i32 @umax_shl_common_lhs_preserve_nsw(
425409
; CHECK-SAME: i32 [[X:%.*]], i32 [[Y:%.*]], i32 [[Z:%.*]]) {
426-
; CHECK-NEXT: [[SHL_X:%.*]] = shl nuw nsw i32 [[Z]], [[X]]
427-
; CHECK-NEXT: [[SHL_Y:%.*]] = shl nuw nsw i32 [[Z]], [[Y]]
428-
; CHECK-NEXT: [[MAX:%.*]] = call i32 @llvm.umax.i32(i32 [[SHL_X]], i32 [[SHL_Y]])
410+
; CHECK-NEXT: [[TMP1:%.*]] = call i32 @llvm.umax.i32(i32 [[X]], i32 [[Y]])
411+
; CHECK-NEXT: [[MAX:%.*]] = shl nuw nsw i32 [[Z]], [[TMP1]]
429412
; CHECK-NEXT: ret i32 [[MAX]]
430413
;
431414
%shl_x = shl nuw nsw i32 %z, %x

0 commit comments

Comments
 (0)