[llvm] [X86] Add combineTruncateOfConcat and simplify EltsFromConsecutiveLoads strided truncation (PR #208869)

Simon Pilgrim via llvm-commits llvm-commits at lists.llvm.org
Sun Jul 12 23:39:17 PDT 2026


================
@@ -55868,6 +55844,70 @@ static SDValue detectPMADDUBSW(SDValue In, EVT VT, SelectionDAG &DAG,
                           PMADDBuilder);
 }
 
+// Fold trunc(concat(trunc(x0), trunc(x1), ...)) -> shuffle(vtrunc(x0), ...).
+// A truncate of the concat narrows twice. VTRUNC narrows each source straight
+// to its final sub-128-bit width leaving only the shuffles.
+static SDValue combineTruncateOfConcat(SDValue Src, EVT VT, const SDLoc &DL,
+                                       SelectionDAG &DAG,
+                                       const X86Subtarget &Subtarget) {
+  if (!Subtarget.hasAVX512() || !VT.isVector() || !Src.hasOneUse())
+    return SDValue();
+
+  SmallVector<SDValue, 4> Ops;
+  if (!collectConcatOps(Src.getNode(), Ops, DAG) || Ops.size() < 2 ||
+      !isPowerOf2_32(Ops.size()))
+    return SDValue();
+
+  // Every piece must be a truncate from one common source type.
+  using namespace SDPatternMatch;
+  EVT InVT = Ops[0].getOperand(0).getValueType();
+  if (!all_of(Ops, [InVT](SDValue Op) {
+        return sd_match(Op, m_OneUse(m_Trunc(m_SpecificVT(InVT))));
+      }))
+    return SDValue();
+
+  // VTRUNC writes to the low lanes of an xmm, so it only helps when a piece is
+  // narrower than that. It needs a 512-bit source (or 256 with VLX), and BWI
+  // for the i16 to i8 form.
+  unsigned InBits = InVT.getSizeInBits();
+  unsigned PieceLanes = InVT.getVectorNumElements();
----------------
RKSimon wrote:

Don't use "Lanes" - x86 backend tends to use that term for 128-bit subvectors - use "NumPieceElts" or similar.

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


More information about the llvm-commits mailing list