Skip to content

Commit 7591909

Browse files
committed
[WebAssembly] Lower ANY_EXTEND_VECTOR_INREG
Treat it in the same manner of zero_extend_vector_inreg and generate an extend_low_u if possible. This is to try an prevent expensive shuffles from being generated instead.
1 parent d47fdfe commit 7591909

File tree

3 files changed

+11
-6
lines changed

3 files changed

+11
-6
lines changed

llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,7 @@ WebAssemblyTargetLowering::WebAssemblyTargetLowering(
319319

320320
// Support vector extending
321321
for (auto T : MVT::integer_fixedlen_vector_valuetypes()) {
322+
setOperationAction(ISD::ANY_EXTEND_VECTOR_INREG, T, Custom);
322323
setOperationAction(ISD::SIGN_EXTEND_VECTOR_INREG, T, Custom);
323324
setOperationAction(ISD::ZERO_EXTEND_VECTOR_INREG, T, Custom);
324325
}
@@ -1705,6 +1706,7 @@ SDValue WebAssemblyTargetLowering::LowerOperation(SDValue Op,
17051706
return LowerSIGN_EXTEND_INREG(Op, DAG);
17061707
case ISD::ZERO_EXTEND_VECTOR_INREG:
17071708
case ISD::SIGN_EXTEND_VECTOR_INREG:
1709+
case ISD::ANY_EXTEND_VECTOR_INREG:
17081710
return LowerEXTEND_VECTOR_INREG(Op, DAG);
17091711
case ISD::BUILD_VECTOR:
17101712
return LowerBUILD_VECTOR(Op, DAG);
@@ -2299,6 +2301,9 @@ WebAssemblyTargetLowering::LowerEXTEND_VECTOR_INREG(SDValue Op,
22992301

23002302
unsigned Ext;
23012303
switch (Op.getOpcode()) {
2304+
default:
2305+
llvm_unreachable("unexpected opcode");
2306+
case ISD::ANY_EXTEND_VECTOR_INREG:
23022307
case ISD::ZERO_EXTEND_VECTOR_INREG:
23032308
Ext = WebAssemblyISD::EXTEND_LOW_U;
23042309
break;

llvm/test/CodeGen/WebAssembly/simd-arith.ll

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1997,10 +1997,10 @@ define void @avgr_undef_shuffle_lanes(ptr %res, <8 x i8> %a, <8 x i8> %b, <8 x i
19971997
; SIMD128: .functype avgr_undef_shuffle_lanes (i32, v128, v128, v128, v128) -> ()
19981998
; SIMD128-NEXT: # %bb.0:
19991999
; SIMD128-NEXT: i8x16.avgr_u $push1=, $1, $2
2000-
; SIMD128-NEXT: i8x16.shuffle $push12=, $pop1, $4, 0, 0, 1, 0, 2, 0, 3, 0, 4, 0, 5, 0, 6, 0, 7, 0
2000+
; SIMD128-NEXT: i16x8.extend_low_i8x16_u $push12=, $pop1
20012001
; SIMD128-NEXT: local.tee $push11=, $2=, $pop12
20022002
; SIMD128-NEXT: i8x16.avgr_u $push0=, $3, $4
2003-
; SIMD128-NEXT: i8x16.shuffle $push10=, $pop0, $4, 0, 0, 1, 0, 2, 0, 3, 0, 4, 0, 5, 0, 6, 0, 7, 0
2003+
; SIMD128-NEXT: i16x8.extend_low_i8x16_u $push10=, $pop0
20042004
; SIMD128-NEXT: local.tee $push9=, $4=, $pop10
20052005
; SIMD128-NEXT: i8x16.shuffle $push4=, $pop11, $pop9, 0, 1, 16, 17, 2, 3, 18, 19, 4, 5, 20, 21, 6, 7, 22, 23
20062006
; SIMD128-NEXT: v128.const $push8=, 255, 255, 255, 255, 255, 255, 255, 255
@@ -2016,10 +2016,10 @@ define void @avgr_undef_shuffle_lanes(ptr %res, <8 x i8> %a, <8 x i8> %b, <8 x i
20162016
; SIMD128-FAST: .functype avgr_undef_shuffle_lanes (i32, v128, v128, v128, v128) -> ()
20172017
; SIMD128-FAST-NEXT: # %bb.0:
20182018
; SIMD128-FAST-NEXT: i8x16.avgr_u $push1=, $1, $2
2019-
; SIMD128-FAST-NEXT: i8x16.shuffle $push12=, $pop1, $4, 0, 0, 1, 0, 2, 0, 3, 0, 4, 0, 5, 0, 6, 0, 7, 0
2019+
; SIMD128-FAST-NEXT: i16x8.extend_low_i8x16_u $push12=, $pop1
20202020
; SIMD128-FAST-NEXT: local.tee $push11=, $2=, $pop12
20212021
; SIMD128-FAST-NEXT: i8x16.avgr_u $push0=, $3, $4
2022-
; SIMD128-FAST-NEXT: i8x16.shuffle $push10=, $pop0, $4, 0, 0, 1, 0, 2, 0, 3, 0, 4, 0, 5, 0, 6, 0, 7, 0
2022+
; SIMD128-FAST-NEXT: i16x8.extend_low_i8x16_u $push10=, $pop0
20232023
; SIMD128-FAST-NEXT: local.tee $push9=, $4=, $pop10
20242024
; SIMD128-FAST-NEXT: i8x16.shuffle $push4=, $pop11, $pop9, 0, 1, 16, 17, 2, 3, 18, 19, 4, 5, 20, 21, 6, 7, 22, 23
20252025
; SIMD128-FAST-NEXT: v128.const $push8=, 255, 255, 255, 255, 255, 255, 255, 255

llvm/test/CodeGen/WebAssembly/simd-vecreduce-bool.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ define i1 @test_any_v8i8(<8 x i8> %x) {
276276
; CHECK-LABEL: test_any_v8i8:
277277
; CHECK: .functype test_any_v8i8 (v128) -> (i32)
278278
; CHECK-NEXT: # %bb.0:
279-
; CHECK-NEXT: i8x16.shuffle $push0=, $0, $0, 0, 0, 1, 0, 2, 0, 3, 0, 4, 0, 5, 0, 6, 0, 7, 0
279+
; CHECK-NEXT: i16x8.extend_low_i8x16_u $push0=, $0
280280
; CHECK-NEXT: i32.const $push1=, 15
281281
; CHECK-NEXT: i16x8.shl $push2=, $pop0, $pop1
282282
; CHECK-NEXT: i32.const $push5=, 15
@@ -292,7 +292,7 @@ define i1 @test_all_v8i8(<8 x i8> %x) {
292292
; CHECK-LABEL: test_all_v8i8:
293293
; CHECK: .functype test_all_v8i8 (v128) -> (i32)
294294
; CHECK-NEXT: # %bb.0:
295-
; CHECK-NEXT: i8x16.shuffle $push0=, $0, $0, 0, 0, 1, 0, 2, 0, 3, 0, 4, 0, 5, 0, 6, 0, 7, 0
295+
; CHECK-NEXT: i16x8.extend_low_i8x16_u $push0=, $0
296296
; CHECK-NEXT: i32.const $push1=, 15
297297
; CHECK-NEXT: i16x8.shl $push2=, $pop0, $pop1
298298
; CHECK-NEXT: i32.const $push5=, 15

0 commit comments

Comments
 (0)