diff options
author | Simon Pilgrim <llvm-dev@redking.me.uk> | 2022-12-15 15:44:27 +0000 |
---|---|---|
committer | Simon Pilgrim <llvm-dev@redking.me.uk> | 2022-12-15 15:44:35 +0000 |
commit | d46f6cd7673790168376c52bf383746816630e41 (patch) | |
tree | a92e869d61b971dcbb846681a2cb965fb71510e1 /llvm/lib/Transforms | |
parent | 98550df7b7bbce0e38a1ec558287d759163c64ba (diff) | |
download | llvm-d46f6cd7673790168376c52bf383746816630e41.zip llvm-d46f6cd7673790168376c52bf383746816630e41.tar.gz llvm-d46f6cd7673790168376c52bf383746816630e41.tar.bz2 |
[GVN] reportMayClobberedLoad - avoid repeated cast<> calls. NFCI.
Just perform each cast<Instruction> once - we can make OtherAccess a Instruction* type as we only ever assign it from a known LoadInst/StoreInst
Diffstat (limited to 'llvm/lib/Transforms')
-rw-r--r-- | llvm/lib/Transforms/Scalar/GVN.cpp | 58 |
1 files changed, 29 insertions, 29 deletions
diff --git a/llvm/lib/Transforms/Scalar/GVN.cpp b/llvm/lib/Transforms/Scalar/GVN.cpp index 96c0aa1..1d13157 100644 --- a/llvm/lib/Transforms/Scalar/GVN.cpp +++ b/llvm/lib/Transforms/Scalar/GVN.cpp @@ -1060,25 +1060,25 @@ 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; + } } } @@ -1086,22 +1086,22 @@ static void reportMayClobberedLoad(LoadInst *Load, MemDepResult DepInfo, // 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; + } } } } |