4747#include < llvm/IR/Function.h>
4848#include < llvm/IR/Instructions.h>
4949#include < llvm/IR/InstIterator.h>
50+ #include < llvm/IR/Operator.h>
5051#include < llvm/Support/Debug.h>
5152#include < functional>
5253
@@ -276,8 +277,7 @@ std::pair<MemoryLocationRange, bool> aggregate(
276277 auto ArrayPtr = LocInfo.first ;
277278 if (!ArrayPtr || !ArrayPtr->isDelinearized () || !LocInfo.second ->isValid ()) {
278279 LLVM_DEBUG (dbgs () << " [AGGREGATE] Failed to delinearize location.\n " );
279- ResLoc.Kind = LocKind::Default;
280- return std::make_pair (ResLoc, true );
280+ return std::make_pair (Loc, true );
281281 }
282282 LLVM_DEBUG (dbgs () << " [AGGREGATE] Array info: " << *ArrayPtr->getBase () <<
283283 " , IsAddress: " << ArrayPtr->isAddressOfVariable () << " .\n " );
@@ -292,7 +292,6 @@ std::pair<MemoryLocationRange, bool> aggregate(
292292 auto ArraySizeInfo = arraySize (ArrayType);
293293 if (ArraySizeInfo == std::make_tuple (0 , 1 , ArrayType) &&
294294 ArrayPtr->getNumberOfDims () != 1 ) {
295- LLVM_DEBUG (dbgs () << " [AGGREGATE] Failed to get array size.\n " );
296295 ResLoc.Kind = LocKind::NonCollapsable;
297296 return std::make_pair (ResLoc, true );
298297 }
@@ -550,7 +549,11 @@ std::pair<MemoryLocationRange, bool> aggregate(
550549 ResLoc.DimList .push_back (DimInfo);
551550 ResLoc.Kind = LocKind::Collapsed;
552551 } else {
553- break ;
552+ DimInfo.Start = DimInfo.End = SCEV;
553+ DimInfo.Step = SE->getOne (Int64Ty);
554+ ResLoc.DimList .push_back (DimInfo);
555+ ResLoc.Kind = LocKind::Collapsed;
556+ ++ConstMatchCount;
554557 }
555558 ++DimensionN;
556559 }
@@ -615,7 +618,7 @@ class AddKnownAccessFunctor :
615618 auto AR = aliasRelation (this ->mAA , this ->mDL , mLoc , ALoc);
616619 if (AR.template is_any <trait::CoverAlias, trait::CoincideAlias>()) {
617620 MemoryLocationRange Loc (ALoc);
618- if (mEM ->getParent () = = &EM)
621+ if (mEM ->isDescendantOf (EM) && mEM ! = &EM)
619622 Loc.Kind |= MemoryLocationRange::LocKind::Auxiliary;
620623 addMust (Loc);
621624 } else if (AR.template is <trait::ContainedAlias>()) {
@@ -644,14 +647,14 @@ class AddKnownAccessFunctor :
644647 } else {
645648 Range = MemoryLocationRange{ALoc.Ptr , 0 , mLoc .Size , ALoc.AATags };
646649 }
647- if (mEM ->getParent () = = &EM)
650+ if (mEM ->isDescendantOf (EM) && mEM ! = &EM)
648651 Range.Kind |= MemoryLocationRange::LocKind::Auxiliary;
649652 if (this ->mDU .hasDef (Range))
650653 continue ;
651654 addMust (Range);
652655 } else if (!AR.template is <trait::NoAlias>()) {
653656 MemoryLocationRange Loc (ALoc);
654- if (mEM ->getParent () = = &EM)
657+ if (mEM ->isDescendantOf (EM) && mEM ! = &EM)
655658 Loc.Kind |= MemoryLocationRange::LocKind::Auxiliary;
656659 addMay (Loc);
657660 }
@@ -802,8 +805,19 @@ void DataFlowTraits<ReachDFFwk*>::initialize(
802805 if (isMemoryMarkerIntrinsic (II->getIntrinsicID ()) ||
803806 isDbgInfoIntrinsic (II->getIntrinsicID ()))
804807 continue ;
805- if (I.getType () && I.getType ()->isPointerTy ())
806- DU->addAddressAccess (&I);
808+ if (I.getType () && I.getType ()->isPointerTy ()) {
809+ if (isa<GEPOperator>(I)) {
810+ auto IsOnlyGEPUsers{true };
811+ for_each_user_insts (I,
812+ [&IsOnlyGEPUsers](auto *U) {
813+ IsOnlyGEPUsers &= isa<GEPOperator>(U);
814+ });
815+ if (!IsOnlyGEPUsers)
816+ DU->addAddressAccess (&I);
817+ } else {
818+ DU->addAddressAccess (&I);
819+ }
820+ }
807821 auto isAddressAccess = [&F](const Value *V) {
808822 if (const ConstantPointerNull *CPN = dyn_cast<ConstantPointerNull>(V)) {
809823 if (!NullPointerIsDefined (F, CPN->getType ()->getAddressSpace ()))
@@ -818,6 +832,13 @@ void DataFlowTraits<ReachDFFwk*>::initialize(
818832 } else if (auto *GV{dyn_cast<GlobalValue>(V)};
819833 GV && GV->hasGlobalUnnamedAddr ()) {
820834 return false ;
835+ } else if (isa<GEPOperator>(V)) {
836+ auto IsOnlyGEPUsers{true };
837+ for_each_user_insts (const_cast <Value &>(*V),
838+ [&IsOnlyGEPUsers](auto *U) {
839+ IsOnlyGEPUsers &= isa<GEPOperator>(U);
840+ });
841+ return !IsOnlyGEPUsers;
821842 }
822843 return true ;
823844 };
@@ -1136,11 +1157,15 @@ void ReachDFFwk::collapse(DFRegion *R) {
11361157 const LocationSet &LS) -> bool {
11371158 bool AreAllCollapsedOrAuxiliary = true ;
11381159 bool HasCollapsed = false ;
1160+ bool HasOtherGV = false ;
11391161 auto *GV{dyn_cast<GlobalValue>(getUnderlyingObject (Loc.Ptr , 0 ))};
11401162 for (auto &OtherLoc : LS) {
1163+ if (&Loc == &OtherLoc)
1164+ continue ;
11411165 auto *OtherGV{dyn_cast<GlobalValue>(
11421166 getUnderlyingObject (OtherLoc.Ptr , 0 ))};
11431167 if (GV == OtherGV) {
1168+ HasOtherGV = true ;
11441169 if ((OtherLoc.Kind & MemoryLocationRange::LocKind::Collapsed) &&
11451170 !(OtherLoc.Kind & MemoryLocationRange::LocKind::Auxiliary))
11461171 HasCollapsed = true ;
@@ -1151,7 +1176,7 @@ void ReachDFFwk::collapse(DFRegion *R) {
11511176 }
11521177 }
11531178 }
1154- if (AreAllCollapsedOrAuxiliary && HasCollapsed)
1179+ if (AreAllCollapsedOrAuxiliary && HasCollapsed || !HasOtherGV )
11551180 return true ;
11561181 return false ;
11571182 };
@@ -1229,7 +1254,9 @@ void ReachDFFwk::collapse(DFRegion *R) {
12291254 }
12301255 }
12311256 }
1232- if (AreAllCollapsed && SameUnderlyingObjCount > 1 )
1257+ if (AreAllCollapsed && SameUnderlyingObjCount > 1 ||
1258+ Loc.Kind == MemoryLocationRange::LocKind::Auxiliary &&
1259+ SameUnderlyingObjCount == 1 && AreAllCollapsed)
12331260 SkipExcessUse = true ;
12341261 } else if (Loc.Kind & MemoryLocationRange::LocKind::Auxiliary) {
12351262 SkipExcessUse = MaySkipAuxiliaryLocation (Loc, NewUses);
0 commit comments