[llvm] [X86] Fix bool vector extension for non-power-of-2 sizes (PR #228921)

Doha Nam via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 5 03:12:52 PDT 2026


================
@@ -48649,6 +48649,24 @@ static SDValue combineToExtendBoolVectorInReg(
   unsigned NumElts = VT.getVectorNumElements();
   assert(NumElts == SclVT.getSizeInBits() && "Unexpected bool vector size");
 
+  // If the scalar integer doesn't split evenly into the vector element size
+  // (e.g. i12 -> v12i8), extend it to the next multiple, extend that and
+  // extract the original elements.
+  if (NumElts > EltSizeInBits && (NumElts % EltSizeInBits) != 0) {
+    unsigned WideNumElts = alignTo(NumElts, EltSizeInBits);
----------------
waroad wrote:

I tried bailing out. The result is correct, but type legalization then scalarizes it: the i12 -> v12i8 zext becomes ~90 instructions on x86-64 (a shift/and/movd per bit) instead of 12 with the widening. It was longer for every non-multiple size I tried (N = 9..64 with i8/i16/i32 elements, zext/sext/select), 5-8x more instructions in total depending on the CPU. So I kept the manual widening.

https://github.com/llvm/llvm-project/pull/228921


More information about the llvm-commits mailing list