Skip to content

Commit

Permalink
[GVN] reportMayClobberedLoad - avoid repeated cast<> calls. NFCI.
Browse files Browse the repository at this point in the history
Just perform each cast<Instruction> once - we can make OtherAccess a Instruction* type as we only ever assign it from a known LoadInst/StoreInst
  • Loading branch information
RKSimon committed Dec 15, 2022
1 parent 98550df commit d46f6cd
Showing 1 changed file with 29 additions and 29 deletions.
58 changes: 29 additions & 29 deletions llvm/lib/Transforms/Scalar/GVN.cpp
Expand Up @@ -1060,48 +1060,48 @@ static void reportMayClobberedLoad(LoadInst *Load, MemDepResult DepInfo,
OptimizationRemarkEmitter *ORE) {
using namespace ore;

User *OtherAccess = nullptr;
Instruction *OtherAccess = nullptr;

OptimizationRemarkMissed R(DEBUG_TYPE, "LoadClobbered", Load);
R << "load of type " << NV("Type", Load->getType()) << " not eliminated"
<< setExtraArgs();

for (auto *U : Load->getPointerOperand()->users()) {
if (U != Load && (isa<LoadInst>(U) || isa<StoreInst>(U)) &&
cast<Instruction>(U)->getFunction() == Load->getFunction() &&
DT->dominates(cast<Instruction>(U), Load)) {
// Use the most immediately dominating value
if (OtherAccess) {
if (DT->dominates(cast<Instruction>(OtherAccess), cast<Instruction>(U)))
OtherAccess = U;
else
assert(U == OtherAccess || DT->dominates(cast<Instruction>(U),
cast<Instruction>(OtherAccess)));
} else
OtherAccess = U;
if (U != Load && (isa<LoadInst>(U) || isa<StoreInst>(U))) {
auto *I = cast<Instruction>(U);
if (I->getFunction() == Load->getFunction() && DT->dominates(I, Load)) {
// Use the most immediately dominating value
if (OtherAccess) {
if (DT->dominates(OtherAccess, I))
OtherAccess = I;
else
assert(U == OtherAccess || DT->dominates(I, OtherAccess));
} else
OtherAccess = I;
}
}
}

if (!OtherAccess) {
// There is no dominating use, check if we can find a closest non-dominating
// use that lies between any other potentially available use and Load.
for (auto *U : Load->getPointerOperand()->users()) {
if (U != Load && (isa<LoadInst>(U) || isa<StoreInst>(U)) &&
cast<Instruction>(U)->getFunction() == Load->getFunction() &&
isPotentiallyReachable(cast<Instruction>(U), Load, nullptr, DT)) {
if (OtherAccess) {
if (liesBetween(cast<Instruction>(OtherAccess), cast<Instruction>(U),
Load, DT)) {
OtherAccess = U;
} else if (!liesBetween(cast<Instruction>(U),
cast<Instruction>(OtherAccess), Load, DT)) {
// These uses are both partially available at Load were it not for
// the clobber, but neither lies strictly after the other.
OtherAccess = nullptr;
break;
} // else: keep current OtherAccess since it lies between U and Load
} else {
OtherAccess = U;
if (U != Load && (isa<LoadInst>(U) || isa<StoreInst>(U))) {
auto *I = cast<Instruction>(U);
if (I->getFunction() == Load->getFunction() &&
isPotentiallyReachable(I, Load, nullptr, DT)) {
if (OtherAccess) {
if (liesBetween(OtherAccess, I, Load, DT)) {
OtherAccess = I;
} else if (!liesBetween(I, OtherAccess, Load, DT)) {
// These uses are both partially available at Load were it not for
// the clobber, but neither lies strictly after the other.
OtherAccess = nullptr;
break;
} // else: keep current OtherAccess since it lies between U and Load
} else {
OtherAccess = I;
}
}
}
}
Expand Down

0 comments on commit d46f6cd

Please sign in to comment.