[PATCH] D124733: [AMDGPU][NFC] Make lowerINSERT_VECTOR_ELT() more readable
Mahesha S via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon May 2 19:31:16 PDT 2022
This revision was not accepted when it landed; it landed in state "Needs Review".
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG3175323ce109: [AMDGPU][NFC] Make lowerINSERT_VECTOR_ELT() more readable (authored by hsmhsm).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D124733/new/
https://reviews.llvm.org/D124733
Files:
llvm/lib/Target/AMDGPU/SIISelLowering.cpp
Index: llvm/lib/Target/AMDGPU/SIISelLowering.cpp
===================================================================
--- llvm/lib/Target/AMDGPU/SIISelLowering.cpp
+++ llvm/lib/Target/AMDGPU/SIISelLowering.cpp
@@ -5768,14 +5768,11 @@
EVT EltVT = VecVT.getVectorElementType();
unsigned VecSize = VecVT.getSizeInBits();
unsigned EltSize = EltVT.getSizeInBits();
+ SDLoc SL(Op);
-
- assert(VecSize <= 64);
-
+ // Specially handle the case of v4i16 with static indexing.
unsigned NumElts = VecVT.getVectorNumElements();
- SDLoc SL(Op);
auto KIdx = dyn_cast<ConstantSDNode>(Idx);
-
if (NumElts == 4 && EltSize == 16 && KIdx) {
SDValue BCVec = DAG.getNode(ISD::BITCAST, SL, MVT::v2i32, Vec);
@@ -5803,35 +5800,41 @@
return DAG.getNode(ISD::BITCAST, SL, VecVT, Concat);
}
+ // Static indexing does not lower to stack access, and hence there is no need
+ // for special custom lowering to avoid stack access.
if (isa<ConstantSDNode>(Idx))
return SDValue();
- MVT IntVT = MVT::getIntegerVT(VecSize);
-
- // Avoid stack access for dynamic indexing.
+ // Avoid stack access for dynamic indexing by custom lowering to
// v_bfi_b32 (v_bfm_b32 16, (shl idx, 16)), val, vec
- // Create a congruent vector with the target value in each element so that
- // the required element can be masked and ORed into the target vector.
- SDValue ExtVal = DAG.getNode(ISD::BITCAST, SL, IntVT,
- DAG.getSplatBuildVector(VecVT, SL, InsVal));
+ assert(VecSize <= 64 && "Expected target vector size to be <= 64 bits");
+ MVT IntVT = MVT::getIntegerVT(VecSize);
+
+ // Convert vector index to bit-index and get the required bit mask.
assert(isPowerOf2_32(EltSize));
SDValue ScaleFactor = DAG.getConstant(Log2_32(EltSize), SL, MVT::i32);
-
- // Convert vector index to bit-index.
SDValue ScaledIdx = DAG.getNode(ISD::SHL, SL, MVT::i32, Idx, ScaleFactor);
-
- SDValue BCVec = DAG.getNode(ISD::BITCAST, SL, IntVT, Vec);
SDValue BFM = DAG.getNode(ISD::SHL, SL, IntVT,
DAG.getConstant(0xffff, SL, IntVT),
ScaledIdx);
+ // 1. Create a congruent vector with the target value in each element.
+ SDValue ExtVal = DAG.getNode(ISD::BITCAST, SL, IntVT,
+ DAG.getSplatBuildVector(VecVT, SL, InsVal));
+
+ // 2. Mask off all other indicies except the required index within (1).
SDValue LHS = DAG.getNode(ISD::AND, SL, IntVT, BFM, ExtVal);
+
+ // 3. Mask off the required index within the target vector.
+ SDValue BCVec = DAG.getNode(ISD::BITCAST, SL, IntVT, Vec);
SDValue RHS = DAG.getNode(ISD::AND, SL, IntVT,
DAG.getNOT(SL, BFM, IntVT), BCVec);
+ // 4. Get (2) and (3) ORed into the target vector.
SDValue BFI = DAG.getNode(ISD::OR, SL, IntVT, LHS, RHS);
+
return DAG.getNode(ISD::BITCAST, SL, VecVT, BFI);
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D124733.426556.patch
Type: text/x-patch
Size: 2918 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220503/7a261cfc/attachment.bin>
More information about the llvm-commits
mailing list