Skip to content

Commit 5cf9f2c

Browse files
committed
[RISCV] Fix M1 shuffle on wrong SrcVec in lowerShuffleViaVRegSplitting
This fixes a miscompile from #79072 where we were taking the wrong SrcVec to do the M1 shuffle. E.g. if the SrcVecIdx was 2 and we had 2 VRegsPerSrc, we ended up taking it from V1 instead of V2.
1 parent d407e6c commit 5cf9f2c

File tree

2 files changed

+4
-6
lines changed

2 files changed

+4
-6
lines changed

llvm/lib/Target/RISCV/RISCVISelLowering.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -4745,7 +4745,7 @@ static SDValue lowerShuffleViaVRegSplitting(ShuffleVectorSDNode *SVN,
47454745
if (SrcVecIdx == -1)
47464746
continue;
47474747
unsigned ExtractIdx = (SrcVecIdx % VRegsPerSrc) * NumOpElts;
4748-
SDValue SrcVec = (unsigned)SrcVecIdx > VRegsPerSrc ? V2 : V1;
4748+
SDValue SrcVec = (unsigned)SrcVecIdx >= VRegsPerSrc ? V2 : V1;
47494749
SDValue SubVec = DAG.getNode(ISD::EXTRACT_SUBVECTOR, DL, M1VT, SrcVec,
47504750
DAG.getVectorIdxConstant(ExtractIdx, DL));
47514751
SubVec = convertFromScalableVector(OneRegVT, SubVec, DAG, Subtarget);

llvm/test/CodeGen/RISCV/rvv/fixed-vectors-shuffle-exact-vlen.ll

+3-5
Original file line numberDiff line numberDiff line change
@@ -149,15 +149,13 @@ define <4 x i64> @m2_splat_into_identity_two_source_v2_hi(<4 x i64> %v1, <4 x i6
149149
ret <4 x i64> %res
150150
}
151151

152-
; FIXME: This is a miscompile, we're clobbering the lower reg group of %v2
153-
; (v10), and the vmv1r.v is moving from the wrong reg group (should be v10)
154152
define <4 x i64> @m2_splat_into_slide_two_source_v2_lo(<4 x i64> %v1, <4 x i64> %v2) vscale_range(2,2) {
155153
; CHECK-LABEL: m2_splat_into_slide_two_source_v2_lo:
156154
; CHECK: # %bb.0:
157155
; CHECK-NEXT: vsetivli zero, 2, e64, m1, ta, ma
158-
; CHECK-NEXT: vrgather.vi v10, v8, 0
159-
; CHECK-NEXT: vmv1r.v v11, v8
160-
; CHECK-NEXT: vmv2r.v v8, v10
156+
; CHECK-NEXT: vrgather.vi v12, v8, 0
157+
; CHECK-NEXT: vmv1r.v v13, v10
158+
; CHECK-NEXT: vmv2r.v v8, v12
161159
; CHECK-NEXT: ret
162160
%res = shufflevector <4 x i64> %v1, <4 x i64> %v2, <4 x i32> <i32 0, i32 0, i32 4, i32 5>
163161
ret <4 x i64> %res

0 commit comments

Comments
 (0)