@@ -5928,8 +5928,8 @@ struct AAPointerInfo : public AbstractAttribute {
59285928 insert (AA::RangeTy{AA::RangeTy::Unknown, AA::RangeTy::Unknown}, V);
59295929 }
59305930
5931- // Increment all ranges by Inc.
5932- // Add an origin V to all offsets.
5931+ // We need to increment all ranges by Inc and add an origin V to all
5932+ // offsets.
59335933 void addToAll (int64_t Inc, Value &V) {
59345934 for (auto &Range : Ranges)
59355935 Range.Offset += Inc;
@@ -5955,13 +5955,20 @@ struct AAPointerInfo : public AbstractAttribute {
59555955 // /
59565956 // / Ideally all lists should be strictly ascending, but we defer that to the
59575957 // / actual use of the list. So we just blindly append here.
5958-
59595958 bool merge (const OffsetInfo &R) {
5959+ bool Changed = false ;
59605960
5961- SmallSet<AA::RangeTy, 2 > Set1 (Ranges.begin (), Ranges.end ());
5962- SmallSet<AA::RangeTy, 2 > Set2 (R.Ranges .begin (), R.Ranges .end ());
5961+ for (const auto &Range : R.Ranges ) {
5962+ if (!is_contained (Ranges, Range)) {
5963+ Changed = true ;
5964+ break ;
5965+ }
5966+ }
5967+
5968+ // No need to merge if the Ranges did not change.
5969+ if (!Changed)
5970+ return Changed;
59635971
5964- bool Changed = set_union (Set1, Set2);
59655972 Ranges.append (R.Ranges );
59665973 // ensure elements are unique.
59675974 sort (Ranges.begin (), Ranges.end ());
@@ -5974,15 +5981,21 @@ struct AAPointerInfo : public AbstractAttribute {
59745981 return Changed;
59755982 }
59765983
5977- // Merge two OffsetInfo structs.
5978- // takes an additional origin argument
5979- // and adds it to the corresponding offset in the
5980- // origins map.
5984+ // Merge two OffsetInfo structs. The function takes an additional origin
5985+ // argument (CurPtr) and adds it to the corresponding offset in the origins
5986+ // map.
59815987 bool mergeWithOffset (const OffsetInfo &R, Value &CurPtr) {
5982- SmallSet<AA::RangeTy, 2 > Set1 (Ranges.begin (), Ranges.end ());
5983- SmallSet<AA::RangeTy, 2 > Set2 (R.Ranges .begin (), R.Ranges .end ());
5988+ bool Changed = false ;
5989+
5990+ // We cannot return if nothing changed since we might still be adding a
5991+ // new Origin.
5992+ for (const auto &Range : Ranges) {
5993+ if (!is_contained (Ranges, Range)) {
5994+ Changed = true ;
5995+ break ;
5996+ }
5997+ }
59845998
5985- bool Changed = set_union (Set1, Set2);
59865999 Ranges.append (R.Ranges );
59876000 // ensure elements are unique.
59886001 sort (Ranges.begin (), Ranges.end ());
@@ -6330,8 +6343,7 @@ struct AAPointerInfo : public AbstractAttribute {
63306343
63316344 // Check if the chain exists in the AccessPathsSet.
63326345 bool existsChain (const AccessPathTy *NewPath) const {
6333-
6334- if (AccessPaths == nullptr )
6346+ if (!AccessPaths)
63356347 return false ;
63366348
63376349 for (auto *OldPath : *AccessPaths)
@@ -6342,18 +6354,17 @@ struct AAPointerInfo : public AbstractAttribute {
63426354 }
63436355
63446356 void dumpAccessPaths (raw_ostream &O) const {
6345- O << " Print all access paths found:"
6346- << " \n " ;
6357+ O << " Print all access paths found:\n " ;
63476358
6348- if (AccessPaths == nullptr ) {
6359+ if (! AccessPaths) {
63496360 O << " Could not find any access paths!\n " ;
6361+ return ;
63506362 }
63516363
63526364 for (auto *It : *AccessPaths) {
63536365 O << " Backtrack a unique access path:\n " ;
6354- for (Value *Ins : *It) {
6366+ for (Value *Ins : *It)
63556367 O << *Ins << " \n " ;
6356- }
63576368 }
63586369 }
63596370
0 commit comments