Lines Matching full:load
10 // instructions. It also performs simple dead load elimination.
109 static cl::opt<bool> GVNEnableLoadPRE("enable-load-pre", cl::init(true));
110 static cl::opt<bool> GVNEnableLoadInLoopPRE("enable-load-in-loop-pre",
113 GVNEnableSplitBackedgeInLoadPRE("enable-split-backedge-in-load-pre",
119 cl::desc("Max number of dependences to attempt Load PRE (default = 100)"));
194 LoadVal, // A value produced by a load.
198 SelectVal, // A pointer select which is loaded from and for which the load
207 /// Offset - The byte offset in Val that is interesting for the load query.
228 static AvailableValue getLoad(LoadInst *Load, unsigned Offset = 0) {
230 Res.Val = Load;
282 Value *MaterializeAdjustedValue(LoadInst *Load, Instruction *InsertPt,
318 Value *MaterializeAdjustedValue(LoadInst *Load, GVNPass &gvn) const {
319 return AV.MaterializeAdjustedValue(Load, BB->getTerminator(), gvn);
514 // For masked load/store intrinsics, the local_dep may actually be
515 // a normal load or store instruction.
852 OS << (*Options.AllowLoadPRE ? "" : "no-") << "load-pre;";
855 << "split-backedge-load-pre;";
1024 /// construct SSA form, allowing us to eliminate Load. This returns the value
1025 /// that should be used at Load's definition site.
1027 ConstructSSAForLoadSet(LoadInst *Load,
1030 // Check for the fully redundant, dominating load case. In this case, we can
1034 Load->getParent())) {
1037 return ValuesPerBlock[0].MaterializeAdjustedValue(Load, gvn);
1043 SSAUpdate.Initialize(Load->getType(), Load->getName());
1054 // If the value is the load that we will be eliminating, and the block it's
1055 // available in is the block that the load is in, then don't add it as
1058 if (BB == Load->getParent() &&
1059 ((AV.AV.isSimpleValue() && AV.AV.getSimpleValue() == Load) ||
1060 (AV.AV.isCoercedLoadValue() && AV.AV.getCoercedLoadValue() == Load)))
1063 SSAUpdate.AddAvailableValue(BB, AV.MaterializeAdjustedValue(Load, gvn));
1067 return SSAUpdate.GetValueInMiddleOfBlock(Load->getParent());
1070 Value *AvailableValue::MaterializeAdjustedValue(LoadInst *Load,
1074 Type *LoadTy = Load->getType();
1075 const DataLayout &DL = Load->getDataLayout();
1090 combineMetadataForCSE(CoercedLoad, Load, false);
1093 // We are adding a new user for this load, for which the original
1094 // metadata may not hold. Additionally, the new load may have a different
1098 // unless the load has !noundef, in which case all metadata violations
1101 // independent of the load type.
1107 LLVM_DEBUG(dbgs() << "GVN COERCED NONLOCAL LOAD:\nOffset: " << Offset
1120 // Introduce a new value select for a load from an eligible pointer select.
1150 /// load-elimination case that is due to an intervening store.
1151 static void reportMayClobberedLoad(LoadInst *Load, MemDepResult DepInfo,
1158 OptimizationRemarkMissed R(DEBUG_TYPE, "LoadClobbered", Load);
1159 R << "load of type " << NV("Type", Load->getType()) << " not eliminated"
1162 for (auto *U : Load->getPointerOperand()->users()) {
1163 if (U != Load && (isa<LoadInst>(U) || isa<StoreInst>(U))) {
1165 if (I->getFunction() == Load->getFunction() && DT->dominates(I, Load)) {
1180 // use that lies between any other potentially available use and Load.
1181 for (auto *U : Load->getPointerOperand()->users()) {
1182 if (U != Load && (isa<LoadInst>(U) || isa<StoreInst>(U))) {
1184 if (I->getFunction() == Load->getFunction() &&
1185 isPotentiallyReachable(I, Load, nullptr, DT)) {
1187 if (liesBetween(OtherAccess, I, Load, DT)) {
1189 } else if (!liesBetween(I, OtherAccess, Load, DT)) {
1190 // These uses are both partially available at Load were it not for
1194 } // else: keep current OtherAccess since it lies between U and Load
1234 GVNPass::AnalyzeLoadAvailability(LoadInst *Load, MemDepResult DepInfo,
1236 assert(Load->isUnordered() && "rules below are incorrect for ordered access");
1241 const DataLayout &DL = Load->getDataLayout();
1244 // read by the load, we can extract the bits we need for the load from the
1248 if (Address && Load->isAtomic() <= DepSI->isAtomic()) {
1250 analyzeLoadFromClobberingStore(Load->getType(), Address, DepSI, DL);
1257 // load i32* P
1258 // load i8* (P+1)
1264 if (DepLoad != Load && Address &&
1265 Load->isAtomic() <= DepLoad->isAtomic()) {
1266 Type *LoadType = Load->getType();
1289 if (Address && !Load->isAtomic()) {
1290 int Offset = analyzeLoadFromClobberingMemInst(Load->getType(), Address,
1300 dbgs() << "GVN: load "; Load->printAsOperand(dbgs());
1303 reportMayClobberedLoad(Load, DepInfo, DT, ORE);
1312 return AvailableValue::get(UndefValue::get(Load->getType()));
1315 getInitialValueOfAllocation(DepInst, TLI, Load->getType()))
1322 if (!canCoerceMustAliasedValueToLoad(S->getValueOperand(), Load->getType(),
1327 if (S->isAtomic() < Load->isAtomic())
1334 // If the types mismatch and we can't handle it, reject reuse of the load.
1337 if (!canCoerceMustAliasedValueToLoad(LD, Load->getType(), DL))
1341 if (LD->isAtomic() < Load->isAtomic())
1347 // Check if load with Addr dependent from select can be converted to select
1348 // between load values. There must be no instructions between the found
1351 assert(Sel->getType() == Load->getPointerOperandType());
1352 auto Loc = MemoryLocation::get(Load);
1355 Load->getType(), DepInst, getAliasAnalysis());
1360 Load->getType(), DepInst, getAliasAnalysis());
1369 dbgs() << "GVN: load "; Load->printAsOperand(dbgs());
1374 void GVNPass::AnalyzeLoadAvailability(LoadInst *Load, LoadDepVect &Deps,
1379 // dependencies that produce an unknown value for the load (such as a call
1380 // that could potentially clobber the load).
1386 // Dead dependent mem-op disguise as a load evaluating the same value
1387 // as the load in question.
1398 // the pointer operand of the load if PHI translation occurs. Make sure
1400 if (auto AV = AnalyzeLoadAvailability(Load, DepInfo, Dep.getAddress())) {
1417 /// another identical load in the other successor of PredBB.
1419 /// v0 = load %addr
1423 /// v1 = load %addr
1431 /// v2 = load %addr
1435 LoadInst *Load) {
1453 if (!Inst.isIdenticalTo(Load))
1457 // If an identical load doesn't depends on any local instructions, it can
1465 // move this and later load to PredBB.
1473 LoadInst *Load, AvailValInBlkVect &ValuesPerBlock,
1481 Load->getType(), LoadPtr, Load->getName() + ".pre", Load->isVolatile(),
1482 Load->getAlign(), Load->getOrdering(), Load->getSyncScopeID(),
1484 NewLoad->setDebugLoc(Load->getDebugLoc());
1494 // Transfer the old load's AA tags to the new load.
1495 AAMDNodes Tags = Load->getAAMetadata();
1499 if (auto *MD = Load->getMetadata(LLVMContext::MD_invariant_load))
1501 if (auto *InvGroupMD = Load->getMetadata(LLVMContext::MD_invariant_group))
1503 if (auto *RangeMD = Load->getMetadata(LLVMContext::MD_range))
1505 if (auto *AccessMD = Load->getMetadata(LLVMContext::MD_access_group))
1506 if (LI->getLoopFor(Load->getParent()) == LI->getLoopFor(UnavailableBlock))
1509 // We do not propagate the old load's debug location, because the new
1510 // load now lives in a different BB, and we want to avoid a jumpy line
1515 // Add the newly created load.
1522 // load instruction with the new created load instruction.
1541 Value *V = ConstructSSAForLoadSet(Load, ValuesPerBlock, *this);
1543 ICF->removeUsersOf(Load);
1544 Load->replaceAllUsesWith(V);
1546 V->takeName(Load);
1548 I->setDebugLoc(Load->getDebugLoc());
1551 markInstructionForDeletion(Load);
1553 return OptimizationRemark(DEBUG_TYPE, "LoadPRE", Load)
1554 << "load eliminated by PRE";
1558 bool GVNPass::PerformLoadPRE(LoadInst *Load, AvailValInBlkVect &ValuesPerBlock,
1562 // doing PRE of this load. This will involve inserting a new load into the
1565 // that we only have to insert *one* load (which means we're basically moving
1566 // the load, not inserting a new one).
1573 BasicBlock *LoadBB = Load->getParent();
1576 // Check that there is no implicit control flow instructions above our load in
1592 ICF->isDominatedByICFIFromSameBlock(Load);
1603 // block along which the load may not be anticipated. Hoisting the load
1604 // above this block would be adding the load to execution paths along
1629 // contains a load can be moved to Pred. This data structure maps the Pred to
1630 // the movable load.
1634 // instructions before the terminator, we can't PRE the load.
1637 dbgs() << "COULD NOT PRE LOAD BECAUSE OF AN EH PAD PREDECESSOR '"
1638 << Pred->getName() << "': " << *Load << '\n');
1649 dbgs() << "COULD NOT PRE LOAD BECAUSE OF INDBR CRITICAL EDGE '"
1650 << Pred->getName() << "': " << *Load << '\n');
1656 dbgs() << "COULD NOT PRE LOAD BECAUSE OF AN EH PAD CRITICAL EDGE '"
1657 << Pred->getName() << "': " << *Load << '\n');
1666 << "COULD NOT PRE LOAD BECAUSE OF A BACKEDGE CRITICAL EDGE '"
1667 << Pred->getName() << "': " << *Load << '\n');
1671 if (LoadInst *LI = findLoadToHoistIntoPred(Pred, LoadBB, Load))
1681 // Decide whether PRE is profitable for this load.
1689 // If we need to insert new load in multiple predecessors, reject it.
1691 // all the preds that don't have an available Load and insert a new load into
1696 // Now we know where we will insert load. We must ensure that it is safe
1697 // to speculatively execute the load at that points.
1700 if (!isSafeToSpeculativelyExecute(Load, LoadBB->getFirstNonPHI(), AC, DT))
1703 if (!isSafeToSpeculativelyExecute(Load, PL.first->getTerminator(), AC,
1707 if (!isSafeToSpeculativelyExecute(Load, CEP.first->getTerminator(), AC,
1724 // Check if the load can safely be moved to all the unavailable predecessors.
1726 const DataLayout &DL = Load->getDataLayout();
1733 // We do the translation for each edge we skipped by going from Load's block
1737 // the load on the pred (?!?), so we can insert code to materialize the
1739 Value *LoadPtr = Load->getPointerOperand();
1740 BasicBlock *Cur = Load->getParent();
1761 << *Load->getPointerOperand() << "\n");
1783 // Okay, we can eliminate this load by inserting a reload in the predecessor
1786 LLVM_DEBUG(dbgs() << "GVN REMOVING PRE LOAD: " << *Load << '\n');
1794 // the load address do not retain their original debug locations. Doing
1805 eliminatePartiallyRedundantLoad(Load, ValuesPerBlock, PredLoads,
1811 bool GVNPass::performLoopLoadPRE(LoadInst *Load,
1814 const Loop *L = LI->getLoopFor(Load->getParent());
1816 if (!L || L->getHeader() != Load->getParent())
1824 Value *LoadPtr = Load->getPointerOperand();
1829 // We plan to hoist the load to preheader without introducing a new fault.
1831 // once loop header is first entered before execution of the load.
1832 if (ICF->isDominatedByICFIFromSameBlock(Load))
1881 LLVM_DEBUG(dbgs() << "GVN REMOVING PRE LOOP LOAD: " << *Load << '\n');
1882 eliminatePartiallyRedundantLoad(Load, ValuesPerBlock, AvailableLoads,
1888 static void reportLoadElim(LoadInst *Load, Value *AvailableValue,
1893 return OptimizationRemark(DEBUG_TYPE, "LoadElim", Load)
1894 << "load of type " << NV("Type", Load->getType()) << " eliminated"
1900 /// Attempt to eliminate a load whose dependencies are
1902 bool GVNPass::processNonLocalLoad(LoadInst *Load) {
1904 if (Load->getParent()->getParent()->hasFnAttribute(
1906 Load->getParent()->getParent()->hasFnAttribute(
1910 // Step 1: Find the non-local dependencies of the load.
1912 MD->getNonLocalPointerDependency(Load, Deps);
1915 // dependencies, this load isn't worth worrying about. Optimizing
1925 LLVM_DEBUG(dbgs() << "GVN: non-local load "; Load->printAsOperand(dbgs());
1931 // If this load follows a GEP, see if we can PRE the indices before analyzing.
1933 dyn_cast<GetElementPtrInst>(Load->getOperand(0))) {
1939 // Step 2: Analyze the availability of the load
1942 AnalyzeLoadAvailability(Load, Deps, ValuesPerBlock, UnavailableBlocks);
1944 // If we have no predecessors that produce a known value for this load, exit
1952 // load, then it is fully redundant and we can use PHI insertion to compute
1955 LLVM_DEBUG(dbgs() << "GVN REMOVING NONLOCAL LOAD: " << *Load << '\n');
1958 Value *V = ConstructSSAForLoadSet(Load, ValuesPerBlock, *this);
1960 ICF->removeUsersOf(Load);
1961 Load->replaceAllUsesWith(V);
1964 V->takeName(Load);
1968 // to propagate Load's DebugLoc because Load may not post-dominate I.
1969 if (Load->getDebugLoc() && Load->getParent() == I->getParent())
1970 I->setDebugLoc(Load->getDebugLoc());
1973 markInstructionForDeletion(Load);
1975 reportLoadElim(Load, V, ORE);
1982 if (!isLoadInLoopPREEnabled() && LI->getLoopFor(Load->getParent()))
1985 if (performLoopLoadPRE(Load, ValuesPerBlock, UnavailableBlocks) ||
1986 PerformLoadPRE(Load, ValuesPerBlock, UnavailableBlocks))
2059 // Insert a new store to null instruction before the load to indicate that
2141 // %load = load float, float* %addr
2142 // %cmp = fcmp oeq float %load, %0
2144 // ret float %load ; will change it to ret float %0
2197 /// Attempt to eliminate a load, first by eliminating it
2224 dbgs() << "GVN: load "; L->printAsOperand(dbgs());
2649 if (LoadInst *Load = dyn_cast<LoadInst>(I)) {
2650 if (processLoad(Load))
2653 unsigned Num = VN.lookupOrAdd(Load);
2654 LeaderTable.insert(Num, Load, Load->getParent());
2957 // This doesn't prevent Load PRE. PHI translation will make the GEP available
2958 // to the load by moving it to the predecessor block if necessary.