@@ -121,6 +121,48 @@ define <16 x i8> @bitcast_shuf_uses(<4 x i32> %v) {
121121 ret <16 x i8 > %r
122122}
123123
124+ ; shuffle of 2 operands removes bitcasts
125+
126+ define <4 x i64 > @bitcast_shuf_remove_bitcasts (<2 x i64 > %a0 , <2 x i64 > %a1 ) {
127+ ; CHECK-LABEL: @bitcast_shuf_remove_bitcasts(
128+ ; CHECK-NEXT: [[R:%.*]] = shufflevector <2 x i64> [[A0:%.*]], <2 x i64> [[A1:%.*]], <4 x i32> <i32 0, i32 1, i32 2, i32 3>
129+ ; CHECK-NEXT: ret <4 x i64> [[R]]
130+ ;
131+ %bc0 = bitcast <2 x i64 > %a0 to <4 x i32 >
132+ %bc1 = bitcast <2 x i64 > %a1 to <4 x i32 >
133+ %shuf = shufflevector <4 x i32 > %bc0 , <4 x i32 > %bc1 , <8 x i32 > <i32 0 , i32 1 , i32 2 , i32 3 , i32 4 , i32 5 , i32 6 , i32 7 >
134+ %r = bitcast <8 x i32 > %shuf to <4 x i64 >
135+ ret <4 x i64 > %r
136+ }
137+
138+ ; shuffle of 2 operands must reduce bitcasts
139+
140+ define <8 x i32 > @bitcast_shuf_one_bitcast (<4 x i32 > %a0 , <2 x i64 > %a1 ) {
141+ ; CHECK-LABEL: @bitcast_shuf_one_bitcast(
142+ ; CHECK-NEXT: [[TMP1:%.*]] = bitcast <2 x i64> [[A1:%.*]] to <4 x i32>
143+ ; CHECK-NEXT: [[R:%.*]] = shufflevector <4 x i32> [[A0:%.*]], <4 x i32> [[TMP1]], <8 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7>
144+ ; CHECK-NEXT: ret <8 x i32> [[R]]
145+ ;
146+ %bc0 = bitcast <4 x i32 > %a0 to <2 x i64 >
147+ %shuf = shufflevector <2 x i64 > %bc0 , <2 x i64 > %a1 , <4 x i32 > <i32 0 , i32 1 , i32 2 , i32 3 >
148+ %r = bitcast <4 x i64 > %shuf to <8 x i32 >
149+ ret <8 x i32 > %r
150+ }
151+
152+ ; TODO - Negative test - shuffle of 2 operands must not increase bitcasts
153+
154+ define <8 x i32 > @bitcast_shuf_too_many_bitcasts (<2 x i64 > %a0 , <2 x i64 > %a1 ) {
155+ ; CHECK-LABEL: @bitcast_shuf_too_many_bitcasts(
156+ ; CHECK-NEXT: [[TMP1:%.*]] = bitcast <2 x i64> [[A0:%.*]] to <4 x i32>
157+ ; CHECK-NEXT: [[TMP2:%.*]] = bitcast <2 x i64> [[A1:%.*]] to <4 x i32>
158+ ; CHECK-NEXT: [[R:%.*]] = shufflevector <4 x i32> [[TMP1]], <4 x i32> [[TMP2]], <8 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7>
159+ ; CHECK-NEXT: ret <8 x i32> [[R]]
160+ ;
161+ %shuf = shufflevector <2 x i64 > %a0 , <2 x i64 > %a1 , <4 x i32 > <i32 0 , i32 1 , i32 2 , i32 3 >
162+ %r = bitcast <4 x i64 > %shuf to <8 x i32 >
163+ ret <8 x i32 > %r
164+ }
165+
124166define <2 x i64 > @PR35454_1 (<2 x i64 > %v ) {
125167; SSE-LABEL: @PR35454_1(
126168; SSE-NEXT: [[BC:%.*]] = bitcast <2 x i64> [[V:%.*]] to <4 x i32>
0 commit comments