Skip to content

Commit 76c4529

Browse files
authored
[WebAssembly] Fix assertion in LowerBUILD_VECTOR (#101961)
The assertion was failing in the case where we were trying to lower to loadxx_zero, but lane zero was undef.
1 parent 934dd20 commit 76c4529

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2276,9 +2276,9 @@ SDValue WebAssemblyTargetLowering::LowerBUILD_VECTOR(SDValue Op,
22762276
};
22772277
} else {
22782278
size_t DestLaneSize = VecT.getVectorElementType().getFixedSizeInBits();
2279-
if (NumSplatLanes == 1 && (DestLaneSize == 32 || DestLaneSize == 64)) {
2279+
if (NumSplatLanes == 1 && Op->getOperand(0) == SplatValue &&
2280+
(DestLaneSize == 32 || DestLaneSize == 64)) {
22802281
// Could be selected to load_zero.
2281-
assert(SplatValue == Op->getOperand(0));
22822282
Result = DAG.getNode(ISD::SCALAR_TO_VECTOR, DL, VecT, SplatValue);
22832283
} else {
22842284
// Use a splat (which might be selected as a load splat)

llvm/test/CodeGen/WebAssembly/simd-build-vector.ll

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -495,6 +495,20 @@ define <4 x float> @load_zero_lane_f32x4(ptr %addr.a, ptr %addr.b, ptr %addr.c,
495495
ret <4 x float> %v.3
496496
}
497497

498+
define <4 x float> @load_zero_undef_lane_f32x4(ptr %addr.a, ptr %addr.b) {
499+
; CHECK-LABEL: load_zero_undef_lane_f32x4:
500+
; CHECK: .functype load_zero_undef_lane_f32x4 (i32, i32) -> (v128)
501+
; CHECK-NEXT: # %bb.0:
502+
; CHECK-NEXT: v128.load32_splat $push0=, 0($0)
503+
; CHECK-NEXT: v128.load32_lane $push1=, 0($1), $pop0, 3
504+
; CHECK-NEXT: return $pop1
505+
%a = load float, ptr %addr.a
506+
%b = load float, ptr %addr.b
507+
%v = insertelement <4 x float> undef, float %a, i32 1
508+
%v.1 = insertelement <4 x float> %v, float %b, i32 3
509+
ret <4 x float> %v.1
510+
}
511+
498512
define <2 x double> @load_zero_lane_f64x2(ptr %addr.a, ptr %addr.b) {
499513
; CHECK-LABEL: load_zero_lane_f64x2:
500514
; CHECK: .functype load_zero_lane_f64x2 (i32, i32) -> (v128)

0 commit comments

Comments
 (0)