[X86] Vector input for inline-asm constraint "A" asserts "lossy conversion of vector to scalar type"; missing diagnostic
https://godbolt.org/z/K7n6Kn8h3 (-O0; -O2 crashes the same way, x86_64)
typedef long v2i64 __attribute__((vector_size(16)));
void f(v2i64 v) { asm("" : : "A"(v)); }
clang: llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp:745: void getCopyToPartsVector(llvm::SelectionDAG&, const llvm::SDLoc&, llvm::SDValue, llvm::SDValue*, unsigned int, llvm::MVT, const llvm::Value*, std::optional<unsigned int>): Assertion `PartVT.getFixedSizeInBits() > ValueSize && "lossy conversion of vector to scalar type"' failed.
#10 getCopyToParts(...) SelectionDAGBuilder.cpp
#11 llvm::RegsForValue::getCopyToRegs(...) const
#12 prepareDAGLevelOperands(...) SelectionDAGBuilder.cpp
#13 llvm::SelectionDAGBuilder::visitInlineAsm(llvm::CallBase const&, llvm::BasicBlock const*)
The operand is invalid. GCC rejects it (error: inconsistent operand constraints in an 'asm'), and clang rejects the same vector as an "=A" output (https://godbolt.org/z/8e7ccTEac: error: non-trivial scalar-to-vector conversion, possible invalid constraint for vector type) and as an "r" input (error: could not allocate input reg for constraint 'r'). "+A" asserts the same way as "A". A __int128 in "A" works (movq %rdi, %rax / movq %rsi, %rdx).
Release builds give no diagnostic. They put only the low 64 bits of the vector in rax (movq %xmm0, %rax) and leave rdx unset (release trunk and GCC: https://godbolt.org/z/65fs1vd7j).
The same assertion from IR, with llc -O0 or -O2 (the -O0 run is in the link above):
target triple = "x86_64-unknown-linux-gnu"
define void @f(<2 x i64> %v) {
call void asm sideeffect "", "A"(<2 x i64> %v)
ret void
}
#50251 was this assertion for a vector in "r". Its fix, 81f6d7c, added !VT.isVector() guards to the GPR constraints (r, q, Q, R) in X86TargetLowering::getRegForInlineAsmConstraint. That is why "r" now gets the "could not allocate" error. case 'A' has no such guard: in 64-bit mode it returns GR64_ADRegClass for any type, so getCopyToRegs tries to fit the 128-bit vector into a single 64-bit part. There are two possible fixes: the same vector guard for 'A', or a diagnostic in getCopyToPartsVector like the one getCopyFromPartsVector already gives for outputs ("non-trivial scalar-to-vector conversion").
Found by a fuzzer (generated C program), reduced by hand.
Command: clang --target=x86_64-unknown-linux-gnu -O0 -c repro.c (same with -O2)
Tested: clang 24.0.0git ef45ca75ce72 (Compiler Explorer assertions trunk, 2026-09-29): the assertion above. Release trunk f4085066128a: exit 0, no diagnostic.
History: long-standing. Every assertions build I checked hits this assertion: 10.0, 12.0, 13.0, 16.0, 20.1, 23.1 and trunk. 3.9 also asserts in getCopyToPartsVector, with an older message ("Only trivial vector-to-scalar conversions should get here!"). The "r" variant still asserts in 12.0 and gets the error from 13.0 on. Not bisected.
Classification: crash on invalid code (GCC rejects it); release builds accept it without a diagnostic.
Related: #50251 (closed 2021): the same assertion with "r", fixed by 81f6d7c. #173481 (open): the same assertion on AArch64 via llc. The X86 'A' handling here is separate target code, so it is not a duplicate. No open X86 issue found (searched "lossy conversion of vector to scalar type", getCopyToPartsVector).