llvm / llvm/llvm-project

[WebAssembly] Manual splat of i32x4 not recognized in store chain

Open
#188,063 4 comments 0 reactions 1 assignee Claimed by @badumbatish View on GitHub
backend:WebAssembly
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

In #187596, although the store chain for i16x8, and i8x16 has been vectorized successfully, i32x4 is still not vectorized.

By changing the shuffle cost to 0, we can vectorize the case of i32x4 as well.
A further look is needed into the SLP vectorizer for said case to make sure this is the right fix (there might be other costs being added up to be considered).

See test case here for the desired effects versus undesired:

```llvm
define void @splat_i32x4(i32 %v, ptr noalias %p) {
; SIMD128-LABEL: @splat_i32x4(
; SIMD128-NEXT: entry:
; SIMD128-NEXT: [[TMP0:%.*]] = insertelement <4 x i32> poison, i32 [[V:%.*]], i32 0
; SIMD128-NEXT: [[TMP1:%.*]] = shufflevector <4 x i32> [[TMP0]], <4 x i32> poison, <4 x i32> zeroinitializer
; SIMD128-NEXT: store <4 x i32> [[TMP1]], ptr [[P:%.*]], align 1
; SIMD128-NEXT: ret void
;
; NO-SIMD128-LABEL: @splat_i32x4(
; NO-SIMD128-NEXT: entry:
; NO-SIMD128-NEXT: store i32 [[V:%.*]], ptr [[P:%.*]], align 1
; NO-SIMD128-NEXT: [[IDX2:%.*]] = getelementptr inbounds nuw i8, ptr [[P]], i32 4
; NO-SIMD128-NEXT: store i32 [[V]], ptr [[IDX2]], align 1
; NO-SIMD128-NEXT: [[IDX4:%.*]] = getelementptr inbounds nuw i8, ptr [[P]], i32 8
; NO-SIMD128-NEXT: store i32 [[V]], ptr [[IDX4]], align 1
; NO-SIMD128-NEXT: [[IDX3:%.*]] = getelementptr inbounds nuw i8, ptr [[P]], i32 12
; NO-SIMD128-NEXT: store i32 [[V]], ptr [[IDX3]], align 1
; NO-SIMD128-NEXT: ret void
;
entry:
store i32 %v, ptr %p, align 1
%idx1 = getelementptr inbounds nuw i8, ptr %p, i32 4
store i32 %v, ptr %idx1, align 1
%idx2 = getelementptr inbounds nuw i8, ptr %p, i32 8
store i32 %v, ptr %idx2, align 1
%idx3 = getelementptr inbounds nuw i8, ptr %p, i32 12
store i32 %v, ptr %idx3, align 1
ret void
}
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.