[fuzzer-found] [AArch64] Crash at -O2 with `-msve-vector-bits=256 -mstrict-align`: "Cannot select: v2i32,ch = load<..., zext from v2i16>"
With fixed-length SVE of 256 bits or more and strict alignment, converting four under-aligned i16 elements to float crashes instruction selection. After vector legalization the DAG combiner splits zero_extend (load v4i16) into two extending v2i16 to v2i32 loads. Those are marked Custom since #163064, but their custom lowering declines under-aligned loads when strict alignment is on, so they stay as they are and no pattern selects them. clang 22.1.0 to 22.1.8, 23.1.6 and main crash; 21.1.0 compiles the function.
Reproducer
godbolt (armv8-a clang trunk, 23.1.0, 22.1.0 and 21.1.0): https://godbolt.org/z/1aWeP4fK8
void f(float *restrict a, const unsigned short *restrict b) {
for (int i = 0; i < 4; i++)
a[i] = b[i];
}
$ clang --target=aarch64-linux-gnu -O2 -march=armv8-a+sve -msve-vector-bits=256 -mstrict-align -c repro.c
fatal error: error in backend: Cannot select: t18: v2i32,ch = load<(load (s32) from %ir.b + 4, align 2, !tbaa !12), zext from v2i16> t0, t17, poison:i64
t17: i64 = add t4, Constant:i64<4>
t4: i64,ch = CopyFromReg t0, Register:i64 %1
In function: f
...
4. Running pass 'AArch64 Instruction Selection' on function '@f'
IR
godbolt (llc trunk, llc 23.1.0, llc 22.1.0 and llc 21.1.0): https://godbolt.org/z/8TfYPW7TG
target triple = "aarch64-unknown-linux-gnu"
define <4 x float> @f(ptr %p) vscale_range(2,2) "target-features"="+sve,+strict-align" {
%v = load <4 x i16>, ptr %p, align 2
%c = uitofp <4 x i16> %v to <4 x float>
ret <4 x float> %c
}
$ llc repro.ll -o /dev/null
LLVM ERROR: Cannot select: t16: v2i32,ch = load<(load (s32) from %ir.p + 4, align 2), zext from v2i16> t0, t15, poison:i64
t15: i64 = add t2, Constant:i64<4>
t2: i64,ch = CopyFromReg t0, Register:i64 %0
In function: f
What goes wrong
From llc -debug-only=isel,legalizedag,dagcombine:
-
Vector legalization turns the conversion into
uint_to_fp (zero_extend (load v4i16)). -
The DAG combine that follows runs
DAGCombiner::CombineExtLoad.AArch64TargetLowering::isVectorLoadExtDesirablereturns true for it: the load is not a small-vector load, butuseSVEForFixedLengthVectors()is true (this is why-msve-vector-bitsof 256 or more is needed) and the source elements arei16. The combine then halves the types untilisLoadLegalOrCustomaccepts them.v4i16tov4i32is Expand;v2i16tov2i32is Custom (setLoadExtAction(ISD::ZEXTLOAD, MVT::v2i32, MVT::v2i16, Custom), added by #163064), so it replaces the node witht13: v2i32,ch = load<(load (s32) from %ir.p, align 2), zext from v2i16> t0, t2, poison:i64 t15: i64 = add t2, Constant:i64<4> t16: v2i32,ch = load<(load (s32) from %ir.p + 4, align 2), zext from v2i16> t0, t15, poison:i64 t19: v4i32 = concat_vectors t13, t16 t12: v4f32 = uint_to_fp t19 -
Operation legalization visits both loads ("Legalizing extending load operation") and calls the custom lowering.
LowerLOADreachestryLowerSmallVectorExtLoad, which returns nothing becauseisEligibleForSmallVectorLoadOptrejects the load:requiresStrictAlign()is true and the alignment (2) is below the store size ofv2i16(4). The loads are left unchanged. -
Instruction selection has no pattern for a
v2i32load that zero-extends fromv2i16.
So the legality query in step 2 says Custom without looking at the alignment, and the custom lowering in step 3 then refuses because of the alignment.
Notes
-
Flags, C function above, on main:
Flags Result -O2,-O3or-Os,-march=armv8-a+sve -msve-vector-bits=256 -mstrict-aligncrash -msve-vector-bits=512,1024or256+instead of256crash -march=armv9-a,-mcpu=neoverse-v1or-mcpu=a64fx(with-msve-vector-bits=512) instead of-march=armv8-a+svecrash -mno-unaligned-accessinstead of-mstrict-aligncrash without -mstrict-aligncompiles without -msve-vector-bits, or with-msve-vector-bits=128compiles -O1compiles -
Variants of the IR,
llcon main:Variant Result align 1on the loadcrash no alignon the load (the vector type's own alignment)compiles sitofpcrash ( sext from v2i16)vscale_range(4,4),vscale_range(2,16)crash vscale_range(1,1)compiles without +strict-aligncompiles zextto<4 x i32>returned directly;<4 x i8>source; 2 or 8 elements;<4 x double>resultcompiles -
Tested: main at 5a464bdd79c1 (2026-11-27), 9833b0c710ef and 84a7a7d12ccc, the 23.1.6 release, the 22.1.8 release. All crash on the C function and on the IR. On godbolt, clang 22.1.0 crashes and clang 21.1.0, 20.1.0 and 19.1.0 compile the C function; llc 21.1.0 and 20.1.0 compile the IR.
This problem was found with a fuzzer; the C function above was written by hand from its test case. The report was written with LLM assistance.
@llvm/issue-subscribers-backend-aarch64
Author: Nirmal (ubmaxxer)
Reproducer
godbolt (armv8-a clang trunk, 23.1.0, 22.1.0 and 21.1.0): https://godbolt.org/z/1aWeP4fK8
void f(float *restrict a, const unsigned short *restrict b) {
for (int i = 0; i < 4; i++)
a[i] = b[i];
}
$ clang --target=aarch64-linux-gnu -O2 -march=armv8-a+sve -msve-vector-bits=256 -mstrict-align -c repro.c
fatal error: error in backend: Cannot select: t18: v2i32,ch = load<(load (s32) from %ir.b + 4, align 2, !tbaa !12), zext from v2i16> t0, t17, poison:i64
t17: i64 = add t4, Constant:i64<4>
t4: i64,ch = CopyFromReg t0, Register:i64 %1
In function: f
...
4. Running pass 'AArch64 Instruction Selection' on function '@<!-- -->f'
IR
godbolt (llc trunk, llc 23.1.0, llc 22.1.0 and llc 21.1.0): https://godbolt.org/z/8TfYPW7TG
target triple = "aarch64-unknown-linux-gnu"
define <4 x float> @<!-- -->f(ptr %p) vscale_range(2,2) "target-features"="+sve,+strict-align" {
%v = load <4 x i16>, ptr %p, align 2
%c = uitofp <4 x i16> %v to <4 x float>
ret <4 x float> %c
}
$ llc repro.ll -o /dev/null
LLVM ERROR: Cannot select: t16: v2i32,ch = load<(load (s32) from %ir.p + 4, align 2), zext from v2i16> t0, t15, poison:i64
t15: i64 = add t2, Constant:i64<4>
t2: i64,ch = CopyFromReg t0, Register:i64 %0
In function: f
What goes wrong
From llc -debug-only=isel,legalizedag,dagcombine:
-
Vector legalization turns the conversion into
uint_to_fp (zero_extend (load v4i16)). -
The DAG combine that follows runs
DAGCombiner::CombineExtLoad.AArch64TargetLowering::isVectorLoadExtDesirablereturns true for it: the load is not a small-vector load, butuseSVEForFixedLengthVectors()is true (this is why-msve-vector-bitsof 256 or more is needed) and the source elements arei16. The combine then halves the types untilisLoadLegalOrCustomaccepts them.v4i16tov4i32is Expand;v2i16tov2i32is Custom (setLoadExtAction(ISD::ZEXTLOAD, MVT::v2i32, MVT::v2i16, Custom), added by #163064), so it replaces the node witht13: v2i32,ch = load<(load (s32) from %ir.p, align 2), zext from v2i16> t0, t2, poison:i64 t15: i64 = add t2, Constant:i64<4> t16: v2i32,ch = load<(load (s32) from %ir.p + 4, align 2), zext from v2i16> t0, t15, poison:i64 t19: v4i32 = concat_vectors t13, t16 t12: v4f32 = uint_to_fp t19 -
Operation legalization visits both loads ("Legalizing extending load operation") and calls the custom lowering.
LowerLOADreachestryLowerSmallVectorExtLoad, which returns nothing becauseisEligibleForSmallVectorLoadOptrejects the load:requiresStrictAlign()is true and the alignment (2) is below the store size ofv2i16(4). The loads are left unchanged. -
Instruction selection has no pattern for a
v2i32load that zero-extends fromv2i16.
So the legality query in step 2 says Custom without looking at the alignment, and the custom lowering in step 3 then refuses because of the alignment.
Notes
-
Flags, C function above, on main:
Flags Result -O2,-O3or-Os,-march=armv8-a+sve -msve-vector-bits=256 -mstrict-aligncrash -msve-vector-bits=512,1024or256+instead of256crash -march=armv9-a,-mcpu=neoverse-v1or-mcpu=a64fx(with-msve-vector-bits=512) instead of-march=armv8-a+svecrash -mno-unaligned-accessinstead of-mstrict-aligncrash without -mstrict-aligncompiles without -msve-vector-bits, or with-msve-vector-bits=128compiles -O1compiles -
Variants of the IR,
llcon main:Variant Result align 1on the loadcrash no alignon the load (the vector type's own alignment)compiles sitofpcrash ( sext from v2i16)vscale_range(4,4),vscale_range(2,16)crash vscale_range(1,1)compiles without +strict-aligncompiles zextto<4 x i32>returned directly;<4 x i8>source; 2 or 8 elements;<4 x double>resultcompiles -
Tested: main at 5a464bdd79c1 (2026-11-27), 9833b0c710ef and 84a7a7d12ccc, the 23.1.6 release, the 22.1.8 release. All crash on the C function and on the IR. On godbolt, clang 22.1.0 crashes and clang 21.1.0, 20.1.0 and 19.1.0 compile the C function; llc 21.1.0 and 20.1.0 compile the IR.
This problem was found with a fuzzer; the C function above was written by hand from its test case. The report was written with LLM assistance.