@@ -834,9 +834,8 @@ struct MemoryLocationWrapper {
834834// A memory def wrapper that represents a MemoryDef and the MemoryLocation(s)
835835// defined by this MemoryDef.
836836struct MemoryDefWrapper {
837- MemoryDefWrapper (
838- MemoryDef *MemDef,
839- const SmallVectorImpl<std::pair<MemoryLocation, bool >> &MemLocations) {
837+ MemoryDefWrapper (MemoryDef *MemDef,
838+ ArrayRef<std::pair<MemoryLocation, bool >> MemLocations) {
840839 DefInst = MemDef->getMemoryInst ();
841840 for (auto &[MemLoc, DefByInitializesAttr] : MemLocations)
842841 DefinedLocations.push_back (
@@ -866,17 +865,16 @@ struct ArgumentInitInfo {
866865// Return the intersected range list of the initializes attributes of "Args".
867866// "Args" are call arguments that alias to each other.
868867// If any argument in "Args" doesn't have dead_on_unwind attr and
869- // "FuncHasNoUnwindAttr" is false, return empty.
870- ConstantRangeList
871- getIntersectedInitRangeList (const SmallVectorImpl<ArgumentInitInfo> &Args,
872- bool FuncHasNoUnwindAttr) {
868+ // "CallHasNoUnwindAttr" is false, return empty.
869+ ConstantRangeList getIntersectedInitRangeList (ArrayRef<ArgumentInitInfo> Args,
870+ bool CallHasNoUnwindAttr) {
873871 if (Args.empty ())
874872 return {};
875873
876874 // To address unwind, the function should have nounwind attribute or the
877875 // arguments have dead_on_unwind attribute. Otherwise, return empty.
878876 for (const auto &Arg : Args) {
879- if (!FuncHasNoUnwindAttr && !Arg.HasDeadOnUnwindAttr )
877+ if (!CallHasNoUnwindAttr && !Arg.HasDeadOnUnwindAttr )
880878 return {};
881879 if (Arg.Inits .empty ())
882880 return {};
@@ -885,14 +883,14 @@ getIntersectedInitRangeList(const SmallVectorImpl<ArgumentInitInfo> &Args,
885883 if (Args.size () == 1 )
886884 return Args[0 ].Inits ;
887885
888- ConstantRangeList IntersectedIntervals = Args[ 0 ] .Inits ;
889- for (size_t I = 1 , Count = Args.size (); I < Count; ++I )
890- IntersectedIntervals = IntersectedIntervals.intersectWith (Args[I] .Inits );
886+ ConstantRangeList IntersectedIntervals = Args. front () .Inits ;
887+ for (auto &Arg : Args.drop_front () )
888+ IntersectedIntervals = IntersectedIntervals.intersectWith (Arg .Inits );
891889
892890 return IntersectedIntervals;
893891}
894892
895- // Return the locations wrote by the initializes attribute.
893+ // Return the locations written by the initializes attribute.
896894// Note that this function considers:
897895// 1. Unwind edge: apply "initializes" attribute only if the callee has
898896// "nounwind" attribute or the argument has "dead_on_unwind" attribute.
@@ -908,19 +906,20 @@ getInitializesArgMemLoc(const Instruction *I, BatchAAResults &BatchAA) {
908906 SmallMapVector<Value *, SmallVector<ArgumentInitInfo, 2 >, 2 > Arguments;
909907 for (unsigned Idx = 0 , Count = CB->arg_size (); Idx < Count; ++Idx) {
910908 ConstantRangeList Inits;
911- if ( CB->paramHasAttr (Idx, Attribute::Initializes))
912- Inits = CB-> getParamAttr (Idx, Attribute::Initializes )
913- .getValueAsConstantRangeList ();
909+ Attribute InitializesAttr = CB->getParamAttr (Idx, Attribute::Initializes);
910+ if (InitializesAttr. isValid () )
911+ Inits = InitializesAttr .getValueAsConstantRangeList ();
914912
915913 bool HasDeadOnUnwindAttr = CB->paramHasAttr (Idx, Attribute::DeadOnUnwind);
916914 ArgumentInitInfo InitInfo{Idx, HasDeadOnUnwindAttr, Inits};
917915 Value *CurArg = CB->getArgOperand (Idx);
918916 bool FoundAliasing = false ;
919917 for (auto &[Arg, AliasList] : Arguments) {
920- if (BatchAA.isMustAlias (Arg, CurArg)) {
921- FoundAliasing = true ;
922- AliasList.push_back (InitInfo);
923- }
918+ if (BatchAA.isNoAlias (Arg, CurArg))
919+ continue ;
920+ // Conservatively consider must/may/partial-alias as aliasing.
921+ FoundAliasing = true ;
922+ AliasList.push_back (InitInfo);
924923 }
925924 if (!FoundAliasing)
926925 Arguments[CurArg] = {InitInfo};
@@ -929,7 +928,7 @@ getInitializesArgMemLoc(const Instruction *I, BatchAAResults &BatchAA) {
929928 SmallVector<MemoryLocation, 1 > Locations;
930929 for (const auto &[_, Args] : Arguments) {
931930 auto IntersectedRanges =
932- getIntersectedInitRangeList (Args, CB->hasFnAttr (Attribute::NoUnwind ));
931+ getIntersectedInitRangeList (Args, CB->doesNotThrow ( ));
933932 if (IntersectedRanges.empty ())
934933 continue ;
935934
@@ -1736,9 +1735,8 @@ struct DSEState {
17361735 bool IsKillingDefFromInitAttr = false ;
17371736 if (IsInitializesAttrMemLoc) {
17381737 if (KillingI == UseInst &&
1739- KillingUndObj == getUnderlyingObject (MaybeDeadLoc.Ptr )) {
1738+ KillingUndObj == getUnderlyingObject (MaybeDeadLoc.Ptr ))
17401739 IsKillingDefFromInitAttr = true ;
1741- }
17421740 }
17431741
17441742 if (isReadClobber (MaybeDeadLoc, UseInst) && !IsKillingDefFromInitAttr) {
0 commit comments