@@ -2261,37 +2261,17 @@ struct DSEState {
22612261 bool eliminateDeadDefs (const MemoryDefWrapper &KillingDefWrapper);
22622262};
22632263
2264- // Return true if "Arg" is an Alloca or GEP from Alloca, and the alloca ptr
2265- // doesn't escape.
2266- bool ValidFromAlloca (Value *Arg) {
2267- const auto *AI = dyn_cast<AllocaInst>(Arg);
2264+ // Return true if "Arg" is function local and isn't captured before "CB" or
2265+ // if "Arg" is GEP whose base pointer is function local and isn't captured
2266+ // before "CB".
2267+ bool IsFuncLocalAndNotCaptured (Value *Arg, const CallBase *CB,
2268+ EarliestEscapeAnalysis &EA) {
2269+ if (isIdentifiedFunctionLocal (Arg))
2270+ return EA.isNotCapturedBefore (Arg, CB, /* OrAt*/ true );
22682271 const auto *GEP = dyn_cast<GetElementPtrInst>(Arg);
2269- if (!AI) {
2270- if (!GEP || !dyn_cast<AllocaInst>(GEP->getPointerOperand ()))
2271- return false ;
2272- }
2273-
2274- // No need for a visited set as we don't look through phis.
2275- SmallVector<Use *, 4 > Worklist;
2276- for (Use &U : Arg->uses ())
2277- Worklist.push_back (&U);
2278-
2279- while (!Worklist.empty ()) {
2280- Use *U = Worklist.pop_back_val ();
2281- Instruction *I = cast<Instruction>(U->getUser ());
2282-
2283- if (auto *GEP = dyn_cast<GetElementPtrInst>(I)) {
2284- for (Use &U : GEP->uses ())
2285- Worklist.push_back (&U);
2286- } else if (auto *CB = dyn_cast<CallBase>(I)) {
2287- if (CB->isArgOperand (U)) {
2288- unsigned ArgNo = CB->getArgOperandNo (U);
2289- if (!CB->paramHasAttr (ArgNo, Attribute::NoCapture))
2290- return false ;
2291- }
2292- }
2293- }
2294- return true ;
2272+ if (GEP && isIdentifiedFunctionLocal (GEP->getPointerOperand ()))
2273+ return EA.isNotCapturedBefore (GEP->getPointerOperand (), CB, /* OrAt*/ true );
2274+ return false ;
22952275}
22962276
22972277SmallVector<MemoryLocation, 1 >
@@ -2310,9 +2290,9 @@ DSEState::getInitializesArgMemLoc(const Instruction *I) {
23102290
23112291 Value *CurArg = CB->getArgOperand (Idx);
23122292 // Check whether "CurArg" could alias with global variables. We require
2313- // either it's an Alloca that doesn 't escape or the "CB" only accesses arg
2314- // or inaccessible mem.
2315- if (!Inits.empty () && !ValidFromAlloca (CurArg) &&
2293+ // either it's function local and isn 't captured before or the "CB" only
2294+ // accesses arg or inaccessible mem.
2295+ if (!Inits.empty () && !IsFuncLocalAndNotCaptured (CurArg, CB, EA ) &&
23162296 !CB->onlyAccessesInaccessibleMemOrArgMem ())
23172297 Inits = ConstantRangeList ();
23182298
0 commit comments