Skip to content

Commit 5ba084c

Browse files
committed
[InstCombine] Extend 'shift with constants' vector tests
Added missing test coverage for shl(add(and(lshr(x,c1),c2),y),c1) -> add(and(x,c2<<c1),shl(y,c1)) combine Rename tests as 'foo' and 'bar' isn't very extensible Added vector tests with undefs and nonuniform constants
1 parent 2efd9fd commit 5ba084c

File tree

1 file changed

+122
-8
lines changed

1 file changed

+122
-8
lines changed

llvm/test/Transforms/InstCombine/pr19420.ll

Lines changed: 122 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ define <16 x i8> @test_FoldShiftByConstant_CreateAnd(<16 x i8> %in0) {
3333
ret <16 x i8> %vshl_n
3434
}
3535

36-
define i32 @bar(i32 %x, i32 %y) {
37-
; CHECK-LABEL: @bar(
36+
define i32 @lshr_add_shl(i32 %x, i32 %y) {
37+
; CHECK-LABEL: @lshr_add_shl(
3838
; CHECK-NEXT: [[B1:%.*]] = shl i32 [[Y:%.*]], 4
3939
; CHECK-NEXT: [[A2:%.*]] = add i32 [[B1]], [[X:%.*]]
4040
; CHECK-NEXT: [[C:%.*]] = and i32 [[A2]], -16
@@ -46,8 +46,8 @@ define i32 @bar(i32 %x, i32 %y) {
4646
ret i32 %c
4747
}
4848

49-
define <2 x i32> @bar_v2i32(<2 x i32> %x, <2 x i32> %y) {
50-
; CHECK-LABEL: @bar_v2i32(
49+
define <2 x i32> @lshr_add_shl_v2i32(<2 x i32> %x, <2 x i32> %y) {
50+
; CHECK-LABEL: @lshr_add_shl_v2i32(
5151
; CHECK-NEXT: [[B1:%.*]] = shl <2 x i32> [[Y:%.*]], <i32 5, i32 5>
5252
; CHECK-NEXT: [[A2:%.*]] = add <2 x i32> [[B1]], [[X:%.*]]
5353
; CHECK-NEXT: [[C:%.*]] = and <2 x i32> [[A2]], <i32 -32, i32 -32>
@@ -59,8 +59,93 @@ define <2 x i32> @bar_v2i32(<2 x i32> %x, <2 x i32> %y) {
5959
ret <2 x i32> %c
6060
}
6161

62-
define i32 @foo(i32 %x, i32 %y) {
63-
; CHECK-LABEL: @foo(
62+
define <2 x i32> @lshr_add_shl_v2i32_undef(<2 x i32> %x, <2 x i32> %y) {
63+
; CHECK-LABEL: @lshr_add_shl_v2i32_undef(
64+
; CHECK-NEXT: [[A:%.*]] = lshr <2 x i32> [[X:%.*]], <i32 5, i32 undef>
65+
; CHECK-NEXT: [[B:%.*]] = add <2 x i32> [[A]], [[Y:%.*]]
66+
; CHECK-NEXT: [[C:%.*]] = shl <2 x i32> [[B]], <i32 undef, i32 5>
67+
; CHECK-NEXT: ret <2 x i32> [[C]]
68+
;
69+
%a = lshr <2 x i32> %x, <i32 5, i32 undef>
70+
%b = add <2 x i32> %a, %y
71+
%c = shl <2 x i32> %b, <i32 undef, i32 5>
72+
ret <2 x i32> %c
73+
}
74+
75+
define <2 x i32> @lshr_add_shl_v2i32_nonuniform(<2 x i32> %x, <2 x i32> %y) {
76+
; CHECK-LABEL: @lshr_add_shl_v2i32_nonuniform(
77+
; CHECK-NEXT: [[A:%.*]] = lshr <2 x i32> [[X:%.*]], <i32 5, i32 6>
78+
; CHECK-NEXT: [[B:%.*]] = add <2 x i32> [[A]], [[Y:%.*]]
79+
; CHECK-NEXT: [[C:%.*]] = shl <2 x i32> [[B]], <i32 5, i32 6>
80+
; CHECK-NEXT: ret <2 x i32> [[C]]
81+
;
82+
%a = lshr <2 x i32> %x, <i32 5, i32 6>
83+
%b = add <2 x i32> %a, %y
84+
%c = shl <2 x i32> %b, <i32 5, i32 6>
85+
ret <2 x i32> %c
86+
}
87+
88+
define i32 @lshr_add_and_shl(i32 %x, i32 %y) {
89+
; CHECK-LABEL: @lshr_add_and_shl(
90+
; CHECK-NEXT: [[TMP1:%.*]] = shl i32 [[Y:%.*]], 5
91+
; CHECK-NEXT: [[X_MASK:%.*]] = and i32 [[X:%.*]], 4064
92+
; CHECK-NEXT: [[TMP2:%.*]] = add i32 [[X_MASK]], [[TMP1]]
93+
; CHECK-NEXT: ret i32 [[TMP2]]
94+
;
95+
%1 = lshr i32 %x, 5
96+
%2 = and i32 %1, 127
97+
%3 = add i32 %y, %2
98+
%4 = shl i32 %3, 5
99+
ret i32 %4
100+
}
101+
102+
define <2 x i32> @lshr_add_and_shl_v2i32(<2 x i32> %x, <2 x i32> %y) {
103+
; CHECK-LABEL: @lshr_add_and_shl_v2i32(
104+
; CHECK-NEXT: [[TMP1:%.*]] = lshr <2 x i32> [[X:%.*]], <i32 5, i32 5>
105+
; CHECK-NEXT: [[TMP2:%.*]] = and <2 x i32> [[TMP1]], <i32 127, i32 127>
106+
; CHECK-NEXT: [[TMP3:%.*]] = add <2 x i32> [[TMP2]], [[Y:%.*]]
107+
; CHECK-NEXT: [[TMP4:%.*]] = shl <2 x i32> [[TMP3]], <i32 5, i32 5>
108+
; CHECK-NEXT: ret <2 x i32> [[TMP4]]
109+
;
110+
%1 = lshr <2 x i32> %x, <i32 5, i32 5>
111+
%2 = and <2 x i32> %1, <i32 127, i32 127>
112+
%3 = add <2 x i32> %y, %2
113+
%4 = shl <2 x i32> %3, <i32 5, i32 5>
114+
ret <2 x i32> %4
115+
}
116+
117+
define <2 x i32> @lshr_add_and_shl_v2i32_undef(<2 x i32> %x, <2 x i32> %y) {
118+
; CHECK-LABEL: @lshr_add_and_shl_v2i32_undef(
119+
; CHECK-NEXT: [[TMP1:%.*]] = lshr <2 x i32> [[X:%.*]], <i32 undef, i32 5>
120+
; CHECK-NEXT: [[TMP2:%.*]] = and <2 x i32> [[TMP1]], <i32 127, i32 127>
121+
; CHECK-NEXT: [[TMP3:%.*]] = add <2 x i32> [[TMP2]], [[Y:%.*]]
122+
; CHECK-NEXT: [[TMP4:%.*]] = shl <2 x i32> [[TMP3]], <i32 5, i32 undef>
123+
; CHECK-NEXT: ret <2 x i32> [[TMP4]]
124+
;
125+
%1 = lshr <2 x i32> %x, <i32 undef, i32 5>
126+
%2 = and <2 x i32> %1, <i32 127, i32 127>
127+
%3 = add <2 x i32> %y, %2
128+
%4 = shl <2 x i32> %3, <i32 5, i32 undef>
129+
ret <2 x i32> %4
130+
}
131+
132+
define <2 x i32> @lshr_add_and_shl_v2i32_nonuniform(<2 x i32> %x, <2 x i32> %y) {
133+
; CHECK-LABEL: @lshr_add_and_shl_v2i32_nonuniform(
134+
; CHECK-NEXT: [[TMP1:%.*]] = lshr <2 x i32> [[X:%.*]], <i32 5, i32 6>
135+
; CHECK-NEXT: [[TMP2:%.*]] = and <2 x i32> [[TMP1]], <i32 127, i32 255>
136+
; CHECK-NEXT: [[TMP3:%.*]] = add <2 x i32> [[TMP2]], [[Y:%.*]]
137+
; CHECK-NEXT: [[TMP4:%.*]] = shl <2 x i32> [[TMP3]], <i32 5, i32 6>
138+
; CHECK-NEXT: ret <2 x i32> [[TMP4]]
139+
;
140+
%1 = lshr <2 x i32> %x, <i32 5, i32 6>
141+
%2 = and <2 x i32> %1, <i32 127, i32 255>
142+
%3 = add <2 x i32> %y, %2
143+
%4 = shl <2 x i32> %3, <i32 5, i32 6>
144+
ret <2 x i32> %4
145+
}
146+
147+
define i32 @shl_add_and_lshr(i32 %x, i32 %y) {
148+
; CHECK-LABEL: @shl_add_and_lshr(
64149
; CHECK-NEXT: [[C1:%.*]] = shl i32 [[Y:%.*]], 4
65150
; CHECK-NEXT: [[X_MASK:%.*]] = and i32 [[X:%.*]], 128
66151
; CHECK-NEXT: [[D:%.*]] = add i32 [[X_MASK]], [[C1]]
@@ -73,8 +158,8 @@ define i32 @foo(i32 %x, i32 %y) {
73158
ret i32 %d
74159
}
75160

76-
define <2 x i32> @foo_v2i32(<2 x i32> %x, <2 x i32> %y) {
77-
; CHECK-LABEL: @foo_v2i32(
161+
define <2 x i32> @shl_add_and_lshr_v2i32(<2 x i32> %x, <2 x i32> %y) {
162+
; CHECK-LABEL: @shl_add_and_lshr_v2i32(
78163
; CHECK-NEXT: [[A:%.*]] = lshr <2 x i32> [[X:%.*]], <i32 4, i32 4>
79164
; CHECK-NEXT: [[B:%.*]] = and <2 x i32> [[A]], <i32 8, i32 8>
80165
; CHECK-NEXT: [[C:%.*]] = add <2 x i32> [[B]], [[Y:%.*]]
@@ -88,3 +173,32 @@ define <2 x i32> @foo_v2i32(<2 x i32> %x, <2 x i32> %y) {
88173
ret <2 x i32> %d
89174
}
90175

176+
define <2 x i32> @shl_add_and_lshr_v2i32_undef(<2 x i32> %x, <2 x i32> %y) {
177+
; CHECK-LABEL: @shl_add_and_lshr_v2i32_undef(
178+
; CHECK-NEXT: [[A:%.*]] = lshr <2 x i32> [[X:%.*]], <i32 4, i32 undef>
179+
; CHECK-NEXT: [[B:%.*]] = and <2 x i32> [[A]], <i32 8, i32 undef>
180+
; CHECK-NEXT: [[C:%.*]] = add <2 x i32> [[B]], [[Y:%.*]]
181+
; CHECK-NEXT: [[D:%.*]] = shl <2 x i32> [[C]], <i32 4, i32 undef>
182+
; CHECK-NEXT: ret <2 x i32> [[D]]
183+
;
184+
%a = lshr <2 x i32> %x, <i32 4, i32 undef>
185+
%b = and <2 x i32> %a, <i32 8, i32 undef>
186+
%c = add <2 x i32> %b, %y
187+
%d = shl <2 x i32> %c, <i32 4, i32 undef>
188+
ret <2 x i32> %d
189+
}
190+
191+
define <2 x i32> @shl_add_and_lshr_v2i32_nonuniform(<2 x i32> %x, <2 x i32> %y) {
192+
; CHECK-LABEL: @shl_add_and_lshr_v2i32_nonuniform(
193+
; CHECK-NEXT: [[A:%.*]] = lshr <2 x i32> [[X:%.*]], <i32 4, i32 5>
194+
; CHECK-NEXT: [[B:%.*]] = and <2 x i32> [[A]], <i32 8, i32 9>
195+
; CHECK-NEXT: [[C:%.*]] = add <2 x i32> [[B]], [[Y:%.*]]
196+
; CHECK-NEXT: [[D:%.*]] = shl <2 x i32> [[C]], <i32 4, i32 5>
197+
; CHECK-NEXT: ret <2 x i32> [[D]]
198+
;
199+
%a = lshr <2 x i32> %x, <i32 4, i32 5>
200+
%b = and <2 x i32> %a, <i32 8, i32 9>
201+
%c = add <2 x i32> %b, %y
202+
%d = shl <2 x i32> %c, <i32 4, i32 5>
203+
ret <2 x i32> %d
204+
}

0 commit comments

Comments
 (0)