Skip to content

Commit 40fdb43

Browse files
committed
[SLP] improve readability in reduction logic; NFC
We had 2 different and ambiguously-named 'I' variables.
1 parent ca13f55 commit 40fdb43

File tree

1 file changed

+16
-14
lines changed

1 file changed

+16
-14
lines changed

llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp

+16-14
Original file line numberDiff line numberDiff line change
@@ -6692,6 +6692,7 @@ class HorizontalReduction {
66926692
/// Expected number of uses for reduction operations/reduced values.
66936693
static bool hasRequiredNumberOfUses(RecurKind Kind, Instruction *I,
66946694
bool IsReductionOp) {
6695+
assert(Kind != RecurKind::None && "Reduction type not set");
66956696
// SelectInst must be used twice while the condition op must have single
66966697
// use only.
66976698
if (isCmpSel(Kind))
@@ -6795,8 +6796,8 @@ class HorizontalReduction {
67956796
if (IsReducedValue)
67966797
ReducedVals.push_back(TreeN);
67976798
else {
6798-
auto I = ExtraArgs.find(TreeN);
6799-
if (I != ExtraArgs.end() && !I->second) {
6799+
auto ExtraArgsIter = ExtraArgs.find(TreeN);
6800+
if (ExtraArgsIter != ExtraArgs.end() && !ExtraArgsIter->second) {
68006801
// Check if TreeN is an extra argument of its parent operation.
68016802
if (Stack.size() <= 1) {
68026803
// TreeN can't be an extra argument as it is a root reduction
@@ -6818,14 +6819,14 @@ class HorizontalReduction {
68186819

68196820
// Visit left or right.
68206821
Value *EdgeVal = TreeN->getOperand(EdgeToVisit);
6821-
auto *I = dyn_cast<Instruction>(EdgeVal);
6822-
if (!I) {
6822+
auto *EdgeInst = dyn_cast<Instruction>(EdgeVal);
6823+
if (!EdgeInst) {
68236824
// Edge value is not a reduction instruction or a leaf instruction.
68246825
// (It may be a constant, function argument, or something else.)
68256826
markExtraArg(Stack.back(), EdgeVal);
68266827
continue;
68276828
}
6828-
RecurKind EdgeRdxKind = getRdxKind(I);
6829+
RecurKind EdgeRdxKind = getRdxKind(EdgeInst);
68296830
// Continue analysis if the next operand is a reduction operation or
68306831
// (possibly) a leaf value. If the leaf value opcode is not set,
68316832
// the first met operation != reduction operation is considered as the
@@ -6834,25 +6835,26 @@ class HorizontalReduction {
68346835
// Each tree node needs to have minimal number of users except for the
68356836
// ultimate reduction.
68366837
const bool IsRdxInst = EdgeRdxKind == RdxKind;
6837-
if (I != Phi && I != B &&
6838-
hasSameParent(RdxKind, I, B->getParent(), IsRdxInst) &&
6839-
hasRequiredNumberOfUses(RdxKind, I, IsRdxInst) &&
6840-
(!LeafOpcode || LeafOpcode == I->getOpcode() || IsRdxInst)) {
6838+
if (EdgeInst != Phi && EdgeInst != B &&
6839+
hasSameParent(RdxKind, EdgeInst, B->getParent(), IsRdxInst) &&
6840+
hasRequiredNumberOfUses(RdxKind, EdgeInst, IsRdxInst) &&
6841+
(!LeafOpcode || LeafOpcode == EdgeInst->getOpcode() || IsRdxInst)) {
68416842
if (IsRdxInst) {
68426843
// We need to be able to reassociate the reduction operations.
6843-
if (!isVectorizable(EdgeRdxKind, I)) {
6844+
if (!isVectorizable(EdgeRdxKind, EdgeInst)) {
68446845
// I is an extra argument for TreeN (its parent operation).
6845-
markExtraArg(Stack.back(), I);
6846+
markExtraArg(Stack.back(), EdgeInst);
68466847
continue;
68476848
}
68486849
} else if (!LeafOpcode) {
6849-
LeafOpcode = I->getOpcode();
6850+
LeafOpcode = EdgeInst->getOpcode();
68506851
}
6851-
Stack.push_back(std::make_pair(I, getFirstOperandIndex(EdgeRdxKind)));
6852+
Stack.push_back(
6853+
std::make_pair(EdgeInst, getFirstOperandIndex(EdgeRdxKind)));
68526854
continue;
68536855
}
68546856
// I is an extra argument for TreeN (its parent operation).
6855-
markExtraArg(Stack.back(), I);
6857+
markExtraArg(Stack.back(), EdgeInst);
68566858
}
68576859
return true;
68586860
}

0 commit comments

Comments
 (0)