[llvm] [SelectionDAG] Replace `INSERT_SUBVECTOR` with series of `INSERT_VECTOR_ELT` (PR #124420)
via llvm-commits
llvm-commits at lists.llvm.org
Sat Jan 25 09:29:11 PST 2025
https://github.com/abhishek-kaushik22 created https://github.com/llvm/llvm-project/pull/124420
If the operands to `INSERT_SUBVECTOR` can't be widened legally, just replace the `INSERT_SUBVECTOR` with a series of `INSERT_VECTOR_ELT`.
Closes #124255 (and possibly #102016)
>From 085cc302bc4dcc86414ae200a59ac3e2b6b43b98 Mon Sep 17 00:00:00 2001
From: abhishek-kaushik22 <abhishek.kaushik at intel.com>
Date: Sat, 25 Jan 2025 22:57:25 +0530
Subject: [PATCH] [SelectionDAG] Replace `INSERT_SUBVECTOR` with series of
`INSERT_VECTOR_ELT`
If the operands to `INSERT_SUBVECTOR` can't be widened legally, just replace the `INSERT_SUBVECTOR` with a series of `INSERT_VECTOR_ELT`.
Closes #124255 (and possibly #102016)
---
.../SelectionDAG/LegalizeVectorTypes.cpp | 26 ++++++++++++++++---
1 file changed, 22 insertions(+), 4 deletions(-)
diff --git a/llvm/lib/CodeGen/SelectionDAG/LegalizeVectorTypes.cpp b/llvm/lib/CodeGen/SelectionDAG/LegalizeVectorTypes.cpp
index f39d9ca15496a9..81cf1afe746e88 100644
--- a/llvm/lib/CodeGen/SelectionDAG/LegalizeVectorTypes.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/LegalizeVectorTypes.cpp
@@ -7040,8 +7040,11 @@ SDValue DAGTypeLegalizer::WidenVecOp_INSERT_SUBVECTOR(SDNode *N) {
SDValue SubVec = N->getOperand(1);
SDValue InVec = N->getOperand(0);
- if (getTypeAction(SubVec.getValueType()) == TargetLowering::TypeWidenVector)
- SubVec = GetWidenedVector(SubVec);
+ SDValue OrigSubVec;
+ if (getTypeAction(SubVec.getValueType()) == TargetLowering::TypeWidenVector) {
+ OrigSubVec = std::move(SubVec);
+ SubVec = GetWidenedVector(OrigSubVec);
+ }
EVT SubVT = SubVec.getValueType();
@@ -7070,8 +7073,23 @@ SDValue DAGTypeLegalizer::WidenVecOp_INSERT_SUBVECTOR(SDNode *N) {
return DAG.getNode(ISD::INSERT_SUBVECTOR, SDLoc(N), VT, InVec, SubVec,
N->getOperand(2));
- report_fatal_error("Don't know how to widen the operands for "
- "INSERT_SUBVECTOR");
+ // If the operands can't be widened legally, just replace the INSERT_SUBVECTOR
+ // with a series of INSERT_VECTOR_ELT
+ EVT OrigVT = OrigSubVec.getValueType();
+ unsigned Idx = N->getConstantOperandVal(2);
+
+ SDValue InsertVecElt;
+ SDLoc DL(N);
+ for (unsigned I = 0; I < OrigVT.getVectorNumElements(); ++I) {
+ SDValue Extract =
+ DAG.getNode(ISD::EXTRACT_VECTOR_ELT, DL, VT.getScalarType(), SubVec,
+ DAG.getIntPtrConstant(I, DL, /*isTarget*/ true));
+ InsertVecElt = DAG.getNode(ISD::INSERT_VECTOR_ELT, DL, VT,
+ I != 0 ? InsertVecElt : InVec, Extract,
+ DAG.getIntPtrConstant(I + Idx, DL, true));
+ }
+
+ return InsertVecElt;
}
SDValue DAGTypeLegalizer::WidenVecOp_EXTRACT_SUBVECTOR(SDNode *N) {
More information about the llvm-commits
mailing list