Skip to content

Commit ba57ff6

Browse files
authored
[LAA] Improve code in findForkedSCEVs (NFC) (#140384)
1 parent 0838bd6 commit ba57ff6

File tree

1 file changed

+19
-26
lines changed

1 file changed

+19
-26
lines changed

llvm/lib/Analysis/LoopAccessAnalysis.cpp

Lines changed: 19 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1001,24 +1001,22 @@ static void findForkedSCEVs(
10011001
break;
10021002
}
10031003

1004-
// Find the pointer type we need to extend to.
1005-
Type *IntPtrTy = SE->getEffectiveSCEVType(
1006-
SE->getSCEV(GEP->getPointerOperand())->getType());
1004+
Type *IntPtrTy = SE->getEffectiveSCEVType(GEP->getPointerOperandType());
10071005

10081006
// Find the size of the type being pointed to. We only have a single
10091007
// index term (guarded above) so we don't need to index into arrays or
10101008
// structures, just get the size of the scalar value.
10111009
const SCEV *Size = SE->getSizeOfExpr(IntPtrTy, SourceTy);
10121010

1013-
// Scale up the offsets by the size of the type, then add to the bases.
1014-
const SCEV *Scaled1 = SE->getMulExpr(
1015-
Size, SE->getTruncateOrSignExtend(get<0>(OffsetScevs[0]), IntPtrTy));
1016-
const SCEV *Scaled2 = SE->getMulExpr(
1017-
Size, SE->getTruncateOrSignExtend(get<0>(OffsetScevs[1]), IntPtrTy));
1018-
ScevList.emplace_back(SE->getAddExpr(get<0>(BaseScevs[0]), Scaled1),
1019-
NeedsFreeze);
1020-
ScevList.emplace_back(SE->getAddExpr(get<0>(BaseScevs[1]), Scaled2),
1021-
NeedsFreeze);
1011+
for (auto [B, O] : zip(BaseScevs, OffsetScevs)) {
1012+
const SCEV *Base = get<0>(B);
1013+
const SCEV *Offset = get<0>(O);
1014+
1015+
// Scale up the offsets by the size of the type, then add to the bases.
1016+
const SCEV *Scaled =
1017+
SE->getMulExpr(Size, SE->getTruncateOrSignExtend(Offset, IntPtrTy));
1018+
ScevList.emplace_back(SE->getAddExpr(Base, Scaled), NeedsFreeze);
1019+
}
10221020
break;
10231021
}
10241022
case Instruction::Select: {
@@ -1028,10 +1026,9 @@ static void findForkedSCEVs(
10281026
// then we just bail out and return the generic SCEV.
10291027
findForkedSCEVs(SE, L, I->getOperand(1), ChildScevs, Depth);
10301028
findForkedSCEVs(SE, L, I->getOperand(2), ChildScevs, Depth);
1031-
if (ChildScevs.size() == 2) {
1032-
ScevList.push_back(ChildScevs[0]);
1033-
ScevList.push_back(ChildScevs[1]);
1034-
} else
1029+
if (ChildScevs.size() == 2)
1030+
append_range(ScevList, ChildScevs);
1031+
else
10351032
ScevList.emplace_back(Scev, !isGuaranteedNotToBeUndefOrPoison(Ptr));
10361033
break;
10371034
}
@@ -1044,10 +1041,9 @@ static void findForkedSCEVs(
10441041
findForkedSCEVs(SE, L, I->getOperand(0), ChildScevs, Depth);
10451042
findForkedSCEVs(SE, L, I->getOperand(1), ChildScevs, Depth);
10461043
}
1047-
if (ChildScevs.size() == 2) {
1048-
ScevList.push_back(ChildScevs[0]);
1049-
ScevList.push_back(ChildScevs[1]);
1050-
} else
1044+
if (ChildScevs.size() == 2)
1045+
append_range(ScevList, ChildScevs);
1046+
else
10511047
ScevList.emplace_back(Scev, !isGuaranteedNotToBeUndefOrPoison(Ptr));
10521048
break;
10531049
}
@@ -1074,12 +1070,9 @@ static void findForkedSCEVs(
10741070
break;
10751071
}
10761072

1077-
ScevList.emplace_back(
1078-
GetBinOpExpr(Opcode, get<0>(LScevs[0]), get<0>(RScevs[0])),
1079-
NeedsFreeze);
1080-
ScevList.emplace_back(
1081-
GetBinOpExpr(Opcode, get<0>(LScevs[1]), get<0>(RScevs[1])),
1082-
NeedsFreeze);
1073+
for (auto [L, R] : zip(LScevs, RScevs))
1074+
ScevList.emplace_back(GetBinOpExpr(Opcode, get<0>(L), get<0>(R)),
1075+
NeedsFreeze);
10831076
break;
10841077
}
10851078
default:

0 commit comments

Comments
 (0)