LLVM Discussion Forums

Odd vector lengths

In contrast with low-level hardware vectors, the MLIR project is perhaps the most likely to introduce “odd” vector lengths (both as unusual, but in this case, pun intended, also just meaning not-even).

While looking into the crash I reported at https://bugs.llvm.org/show_bug.cgi?id=45563, I traced this to the following method in llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp

/// GetSplitDestVTs - Compute the VTs needed for the low/hi parts of a type
/// which is split (or expanded) into two not necessarily identical pieces.
std::pair<EVT, EVT> SelectionDAG::GetSplitDestVTs(const EVT &VT) const {
// Currently all types are split in half.
EVT LoVT, HiVT;
if (!VT.isVector())
LoVT = HiVT = TLI->getTypeToTransformTo(*getContext(), VT);
else
LoVT = HiVT = VT.getHalfNumVectorElementsVT(*getContext());

return std::make_pair(LoVT, HiVT);
}

when called with an EVT that denotes a vector with 13 float elements (52 bytes)
from the following line

std::tie(LoMemVT, HiMemVT) = DAG.GetSplitDestVTs(MLD->getMemoryVT());

in the method DAGTypeLegalizer::SplitVecRes_MLOAD() in file lvm/lib/CodeGen/SelectionDAG/LegalizeVectorTypes.cpp

As the method comment suggests, GetSplitDestVTs() should be able to split this into two non-identical parts (6 and 7), but the “currently” comment seems to imply that all uses are expected to have even vector lengths.

Is it time to generalize this method for odd vector lengths? Will this have unintended consequences?

It looks to me like just something that wasn’t implemented because no-one hit this case so far.

Minor update: the particular issues with SplitVecRes_MLOAD reported in the bug https://bugs.llvm.org/show_bug.cgi?id=45563 have been resolved now (guided by an “enveloping” vector with expected hardware lengths, the dependent vector of arbitrary length needed to be split fully in the low vector first, leaving the rest for the high vector). I suspect that other cases that split vectors for similar reasons may eventually encounter problems too for unusual vector lengths. Hopefully the fix gives some inspiration on how to proceed there (happy to help with these too).

It was not hard to make a reproducer for the store.

https://bugs.llvm.org/show_bug.cgi?id=45833

I will work on a fix for that too.