Skip to content

Commit 73b255c

Browse files
committed
[DAG] Ensure extract_subvector(insert_subvector(x,y,c1),c2) --> extract_subvector(y,c2-c1) is working on fixed vector types
#87925 failed to ensure we weren't removing the extracted subvector from a scalable vector type Thanks to @antmox for the headsup.
1 parent a66c09a commit 73b255c

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24478,7 +24478,8 @@ SDValue DAGCombiner::visitEXTRACT_SUBVECTOR(SDNode *N) {
2447824478
unsigned NumSubElts = NVT.getVectorMinNumElements();
2447924479
if (InsIdx <= ExtIdx && (ExtIdx + NumSubElts) <= (InsIdx + NumInsElts) &&
2448024480
TLI.isExtractSubvectorCheap(NVT, InsSubVT, ExtIdx - InsIdx) &&
24481-
InsSubVT.isFixedLengthVector() && NVT.isFixedLengthVector())
24481+
InsSubVT.isFixedLengthVector() && NVT.isFixedLengthVector() &&
24482+
V.getValueType().isFixedLengthVector())
2448224483
return DAG.getNode(ISD::EXTRACT_SUBVECTOR, DL, NVT, InsSub,
2448324484
DAG.getVectorIdxConstant(ExtIdx - InsIdx, DL));
2448424485
}

llvm/test/CodeGen/AArch64/sve-fixed-length-extract-subvector.ll

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -613,6 +613,40 @@ define void @extract_subvector_v32f64(ptr %a, ptr %b) vscale_range(16,0) #0 {
613613
ret void
614614
}
615615

616+
; Test for infinite loop due to fold:
617+
; extract_subvector(insert_subvector(x,y,c1),c2)--> extract_subvector(y,c2-c1)
618+
define void @extract_subvector_legalization_v8i32() vscale_range(2,2) #0 {
619+
; CHECK-LABEL: extract_subvector_legalization_v8i32:
620+
; CHECK: // %bb.0: // %entry
621+
; CHECK-NEXT: ptrue p0.s
622+
; CHECK-NEXT: adrp x8, .LCPI40_0
623+
; CHECK-NEXT: add x8, x8, :lo12:.LCPI40_0
624+
; CHECK-NEXT: movi v2.2d, #0000000000000000
625+
; CHECK-NEXT: ptrue p1.d
626+
; CHECK-NEXT: ld1w { z0.s }, p0/z, [x8]
627+
; CHECK-NEXT: mov z1.d, z0.d
628+
; CHECK-NEXT: ext z1.b, z1.b, z0.b, #16
629+
; CHECK-NEXT: cmeq v0.4s, v0.4s, v2.4s
630+
; CHECK-NEXT: cmeq v1.4s, v1.4s, v2.4s
631+
; CHECK-NEXT: sunpklo z0.d, z0.s
632+
; CHECK-NEXT: sunpklo z1.d, z1.s
633+
; CHECK-NEXT: cmpne p0.d, p1/z, z1.d, #0
634+
; CHECK-NEXT: cmpne p1.d, p1/z, z0.d, #0
635+
; CHECK-NEXT: .LBB40_1: // %body
636+
; CHECK-NEXT: // =>This Inner Loop Header: Depth=1
637+
; CHECK-NEXT: st1d { z0.d }, p1, [x8]
638+
; CHECK-NEXT: st1d { z0.d }, p0, [x8]
639+
; CHECK-NEXT: b .LBB40_1
640+
entry:
641+
%splat = shufflevector <8 x i32> poison, <8 x i32> poison, <8 x i32> zeroinitializer
642+
br label %body
643+
body:
644+
%0 = icmp eq <8 x i32> zeroinitializer, %splat
645+
tail call void @llvm.masked.store.v8f64.p0(<8 x double> poison, ptr poison, i32 8, <8 x i1> %0)
646+
br label %body
647+
}
648+
declare void @llvm.masked.store.v8f64.p0(<8 x double>, ptr nocapture, i32 immarg, <8 x i1>)
649+
616650
declare <4 x i8> @llvm.vector.extract.v4i8.v8i8(<8 x i8>, i64)
617651
declare <8 x i8> @llvm.vector.extract.v8i8.v16i8(<16 x i8>, i64)
618652
declare <16 x i8> @llvm.vector.extract.v16i8.v32i8(<32 x i8>, i64)

0 commit comments

Comments
 (0)