Index: lib/Transforms/Scalar/LICM.cpp =================================================================== --- lib/Transforms/Scalar/LICM.cpp +++ lib/Transforms/Scalar/LICM.cpp @@ -106,17 +106,20 @@ LICMN2Theshold("licm-n2-threshold", cl::Hidden, cl::init(0), cl::desc("How many instruction to cross product using AA")); -// Experimental option to allow imprecision in LICM (use MemorySSA cap) in -// pathological cases, in exchange for faster compile. This is to be removed -// if MemorySSA starts to address the same issue. This flag applies only when -// LICM uses MemorySSA instead on AliasSetTracker. When the flag is disabled -// (default), LICM calls MemorySSAWalker's getClobberingMemoryAccess, which -// gets perfect accuracy. When flag is enabled, LICM will call into MemorySSA's -// getDefiningAccess, which may not be precise, since optimizeUses is capped. -static cl::opt EnableLicmCap( - "enable-licm-cap", cl::init(false), cl::Hidden, - cl::desc("Enable imprecision in LICM (uses MemorySSA cap) in " - "pathological cases, in exchange for faster compile")); +// Experimental option to allow imprecision in LICM in pathological cases, in +// exchange for faster compile. This is to be removed if MemorySSA starts to +// address the same issue. This flag applies only when LICM uses MemorySSA +// instead on AliasSetTracker. LICM calls MemorySSAWalker's +// getClobberingMemoryAccess, up to the value of the Cap, getting perfect +// accuracy. Afterwards, LICM will call into MemorySSA's getDefiningAccess, +// which may not be precise, since optimizeUses is capped. The result is +// correct, but we may not get as "far up" as possible to get which access is +// clobbering the one queried. +static cl::opt EnableLicmCap( + "enable-licm-cap", cl::init(100), cl::Hidden, + cl::desc("Enable imprecision in LICM in pathological cases, in exchange " + "for faster compile. Caps the MemorySSA clobbering calls.")); +static int EnableLicmCapCounter = 0; static bool LocalDisablePromotion = false; @@ -309,6 +312,7 @@ std::unique_ptr CurAST; std::unique_ptr MSSAU; LocalDisablePromotion = false; + EnableLicmCapCounter = 0; if (!MSSA) { LLVM_DEBUG(dbgs() << "LICM: Using Alias Set Tracker.\n"); @@ -1174,8 +1178,9 @@ } else { // MSSAU if (isOnlyMemoryAccess(SI, CurLoop, MSSAU)) return true; - if (!EnableLicmCap) { + if (EnableLicmCapCounter < EnableLicmCap) { auto *Source = MSSA->getSkipSelfWalker()->getClobberingMemoryAccess(SI); + EnableLicmCapCounter++; // If there are no clobbering Defs in the loop, we still need to check // for interfering Uses. If there are more accesses than the Promotion // cap, give up, we're not walking a list that long. Otherwise, walk the @@ -2196,10 +2201,12 @@ Loop *CurLoop) { MemoryAccess *Source; // See declaration of EnableLicmCap for usage details. - if (EnableLicmCap) + if (EnableLicmCapCounter >= EnableLicmCap) Source = MU->getDefiningAccess(); - else + else { Source = MSSA->getSkipSelfWalker()->getClobberingMemoryAccess(MU); + EnableLicmCapCounter++; + } return !MSSA->isLiveOnEntryDef(Source) && CurLoop->contains(Source->getBlock()); }