[llvm] 69edef1 - [DAG] Simplify control flow in SelectionDAGBuilder::visitShuffleVector [NFC]
Philip Reames via llvm-commits
llvm-commits at lists.llvm.org
Fri Nov 1 08:59:39 PDT 2024
Author: Philip Reames
Date: 2024-11-01T08:59:15-07:00
New Revision: 69edef1ab9a2357b0e4fc2e245cf9c70177795d0
URL: https://github.com/llvm/llvm-project/commit/69edef1ab9a2357b0e4fc2e245cf9c70177795d0
DIFF: https://github.com/llvm/llvm-project/commit/69edef1ab9a2357b0e4fc2e245cf9c70177795d0.diff
LOG: [DAG] Simplify control flow in SelectionDAGBuilder::visitShuffleVector [NFC]
If we've handled ==, and < above, the only case left can be >. We don't
need to branch on this, and can instead assert and reduce indentation,
and simplify reasoning about the fallthrough path.
Added:
Modified:
llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
Removed:
################################################################################
diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
index f41dbe81434c7e..bfe7bbe534db5e 100644
--- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
@@ -4119,61 +4119,61 @@ void SelectionDAGBuilder::visitShuffleVector(const User &I) {
return;
}
- if (SrcNumElts > MaskNumElts) {
- // Analyze the access pattern of the vector to see if we can extract
- // two subvectors and do the shuffle.
- int StartIdx[2] = { -1, -1 }; // StartIdx to extract from
- bool CanExtract = true;
- for (int Idx : Mask) {
- unsigned Input = 0;
- if (Idx < 0)
- continue;
+ assert(SrcNumElts > MaskNumElts);
- if (Idx >= (int)SrcNumElts) {
- Input = 1;
- Idx -= SrcNumElts;
- }
+ // Analyze the access pattern of the vector to see if we can extract
+ // two subvectors and do the shuffle.
+ int StartIdx[2] = {-1, -1}; // StartIdx to extract from
+ bool CanExtract = true;
+ for (int Idx : Mask) {
+ unsigned Input = 0;
+ if (Idx < 0)
+ continue;
- // If all the indices come from the same MaskNumElts sized portion of
- // the sources we can use extract. Also make sure the extract wouldn't
- // extract past the end of the source.
- int NewStartIdx = alignDown(Idx, MaskNumElts);
- if (NewStartIdx + MaskNumElts > SrcNumElts ||
- (StartIdx[Input] >= 0 && StartIdx[Input] != NewStartIdx))
- CanExtract = false;
- // Make sure we always update StartIdx as we use it to track if all
- // elements are undef.
- StartIdx[Input] = NewStartIdx;
+ if (Idx >= (int)SrcNumElts) {
+ Input = 1;
+ Idx -= SrcNumElts;
}
- if (StartIdx[0] < 0 && StartIdx[1] < 0) {
- setValue(&I, DAG.getUNDEF(VT)); // Vectors are not used.
- return;
- }
- if (CanExtract) {
- // Extract appropriate subvector and generate a vector shuffle
- for (unsigned Input = 0; Input < 2; ++Input) {
- SDValue &Src = Input == 0 ? Src1 : Src2;
- if (StartIdx[Input] < 0)
- Src = DAG.getUNDEF(VT);
- else {
- Src = DAG.getNode(ISD::EXTRACT_SUBVECTOR, DL, VT, Src,
- DAG.getVectorIdxConstant(StartIdx[Input], DL));
- }
- }
+ // If all the indices come from the same MaskNumElts sized portion of
+ // the sources we can use extract. Also make sure the extract wouldn't
+ // extract past the end of the source.
+ int NewStartIdx = alignDown(Idx, MaskNumElts);
+ if (NewStartIdx + MaskNumElts > SrcNumElts ||
+ (StartIdx[Input] >= 0 && StartIdx[Input] != NewStartIdx))
+ CanExtract = false;
+ // Make sure we always update StartIdx as we use it to track if all
+ // elements are undef.
+ StartIdx[Input] = NewStartIdx;
+ }
- // Calculate new mask.
- SmallVector<int, 8> MappedOps(Mask);
- for (int &Idx : MappedOps) {
- if (Idx >= (int)SrcNumElts)
- Idx -= SrcNumElts + StartIdx[1] - MaskNumElts;
- else if (Idx >= 0)
- Idx -= StartIdx[0];
+ if (StartIdx[0] < 0 && StartIdx[1] < 0) {
+ setValue(&I, DAG.getUNDEF(VT)); // Vectors are not used.
+ return;
+ }
+ if (CanExtract) {
+ // Extract appropriate subvector and generate a vector shuffle
+ for (unsigned Input = 0; Input < 2; ++Input) {
+ SDValue &Src = Input == 0 ? Src1 : Src2;
+ if (StartIdx[Input] < 0)
+ Src = DAG.getUNDEF(VT);
+ else {
+ Src = DAG.getNode(ISD::EXTRACT_SUBVECTOR, DL, VT, Src,
+ DAG.getVectorIdxConstant(StartIdx[Input], DL));
}
+ }
- setValue(&I, DAG.getVectorShuffle(VT, DL, Src1, Src2, MappedOps));
- return;
+ // Calculate new mask.
+ SmallVector<int, 8> MappedOps(Mask);
+ for (int &Idx : MappedOps) {
+ if (Idx >= (int)SrcNumElts)
+ Idx -= SrcNumElts + StartIdx[1] - MaskNumElts;
+ else if (Idx >= 0)
+ Idx -= StartIdx[0];
}
+
+ setValue(&I, DAG.getVectorShuffle(VT, DL, Src1, Src2, MappedOps));
+ return;
}
// We can't use either concat vectors or extract subvectors so fall back to
More information about the llvm-commits
mailing list