Skip to content

Commit 614fb09

Browse files
[SVE] Disable some BUILD_VECTOR related code generator features.
Fixed length vector code generation for SVE does not yet custom lower BUILD_VECTOR and instead relies on expansion. At the same time custom lowering for VECTOR_SHUFFLE is also not available so this patch updates isShuffleMaskLegal to reject vector types that require SVE. Related to this it also prevents the merging of stores after legalisation because this only works when BUILD_VECTOR is either legal or can be elminated. When this is not the case the code generator enters an infinite legalisation loop. Differential Revision: https://reviews.llvm.org/D83408
1 parent 54bdde1 commit 614fb09

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

llvm/lib/Target/AArch64/AArch64ISelLowering.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8741,6 +8741,10 @@ SDValue AArch64TargetLowering::LowerINSERT_SUBVECTOR(SDValue Op,
87418741
}
87428742

87438743
bool AArch64TargetLowering::isShuffleMaskLegal(ArrayRef<int> M, EVT VT) const {
8744+
// Currently no fixed length shuffles that require SVE are legal.
8745+
if (useSVEForFixedLengthVectorVT(VT))
8746+
return false;
8747+
87448748
if (VT.getVectorNumElements() == 4 &&
87458749
(VT.is128BitVector() || VT.is64BitVector())) {
87468750
unsigned PFIndexes[4];

llvm/lib/Target/AArch64/AArch64ISelLowering.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -734,6 +734,16 @@ class AArch64TargetLowering : public TargetLowering {
734734

735735
bool fallBackToDAGISel(const Instruction &Inst) const override;
736736

737+
/// SVE code generation for fixed length vectors does not custom lower
738+
/// BUILD_VECTOR. This makes BUILD_VECTOR legalisation a source of stores to
739+
/// merge. However, merging them creates a BUILD_VECTOR that is just as
740+
/// illegal as the original, thus leading to an infinite legalisation loop.
741+
/// NOTE: Once BUILD_VECTOR is legal or can be custom lowered for all legal
742+
/// vector types this override can be removed.
743+
bool mergeStoresAfterLegalization(EVT VT) const override {
744+
return !useSVEForFixedLengthVectors();
745+
}
746+
737747
private:
738748
/// Keep a pointer to the AArch64Subtarget around so that we can
739749
/// make the right decision when generating code for different targets.

llvm/test/CodeGen/AArch64/sve-fixed-length-shuffles.ll

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,18 @@
33

44
target triple = "aarch64-unknown-linux-gnu"
55

6+
; Currently there is no custom lowering for vector shuffles operating on types
7+
; bigger than NEON. However, having no support opens us up to a code generator
8+
; hang when expanding BUILD_VECTOR. Here we just validate the promblematic case
9+
; successfully exits code generation.
10+
define void @hang_when_merging_stores_after_legalisation(<8 x i32>* %a, <2 x i32> %b) #0 {
11+
; CHECK-LABEL: hang_when_merging_stores_after_legalisation:
12+
%splat = shufflevector <2 x i32> %b, <2 x i32> undef, <8 x i32> zeroinitializer
13+
%interleaved.vec = shufflevector <8 x i32> %splat, <8 x i32> undef, <8 x i32> <i32 0, i32 4, i32 1, i32 5, i32 2, i32 6, i32 3, i32 7>
14+
store <8 x i32> %interleaved.vec, <8 x i32>* %a, align 4
15+
ret void
16+
}
17+
618
; NOTE: Currently all CONCAT_VECTORS get expanded so there's little point in
719
; validating all combinations of vector type.
820

0 commit comments

Comments
 (0)