Skip to content

Commit e4d5edd

Browse files
committed
Fix Rebase and tests
1 parent 122f3bf commit e4d5edd

File tree

10 files changed

+120
-88
lines changed

10 files changed

+120
-88
lines changed

llvm/include/llvm/Transforms/IPO/Attributor.h

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5957,7 +5957,12 @@ struct AAPointerInfo : public AbstractAttribute {
59575957
/// actual use of the list. So we just blindly append here.
59585958

59595959
bool merge(const OffsetInfo &R) {
5960-
bool Changed = set_union(Ranges, R.Ranges);
5960+
5961+
SmallSet<AA::RangeTy, 2> Set1(Ranges.begin(), Ranges.end());
5962+
SmallSet<AA::RangeTy, 2> Set2(R.Ranges.begin(), R.Ranges.end());
5963+
5964+
bool Changed = set_union(Set1, Set2);
5965+
Ranges.append(R.Ranges);
59615966
// ensure elements are unique.
59625967
sort(Ranges.begin(), Ranges.end());
59635968
Ranges.erase(std::unique(Ranges.begin(), Ranges.end()), Ranges.end());
@@ -5974,7 +5979,11 @@ struct AAPointerInfo : public AbstractAttribute {
59745979
// and adds it to the corresponding offset in the
59755980
// origins map.
59765981
bool mergeWithOffset(const OffsetInfo &R, Value &CurPtr) {
5977-
bool Changed = set_union(Ranges, R.Ranges);
5982+
SmallSet<AA::RangeTy, 2> Set1(Ranges.begin(), Ranges.end());
5983+
SmallSet<AA::RangeTy, 2> Set2(R.Ranges.begin(), R.Ranges.end());
5984+
5985+
bool Changed = set_union(Set1, Set2);
5986+
Ranges.append(R.Ranges);
59785987
// ensure elements are unique.
59795988
sort(Ranges.begin(), Ranges.end());
59805989
Ranges.erase(std::unique(Ranges.begin(), Ranges.end()), Ranges.end());
@@ -6386,7 +6395,7 @@ struct AAPointerInfo : public AbstractAttribute {
63866395
virtual const_bin_iterator end() const = 0;
63876396
virtual int64_t numOffsetBins() const = 0;
63886397
virtual bool reachesReturn() const = 0;
6389-
virtual void addReturnedOffsetsTo(OffsetInfo &) const = 0;
6398+
virtual void addReturnedOffsetsTo(OffsetInfo &, Value &V) const = 0;
63906399
virtual void dumpState(raw_ostream &O) const = 0;
63916400
virtual const Access &getBinAccess(unsigned Index) const = 0;
63926401
virtual const DenseMap<Value *, OffsetInfo> &getOffsetInfoMap() const = 0;

llvm/lib/Transforms/IPO/AttributorAttributes.cpp

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1143,7 +1143,13 @@ struct AAPointerInfoImpl
11431143
(reachesReturn()
11441144
? (" (returned:" +
11451145
join(map_range(ReturnedOffsets,
1146-
[](int64_t O) { return std::to_string(O); }),
1146+
[](AA::RangeTy O) {
1147+
return std::string("(") +
1148+
std::to_string(O.Offset) +
1149+
std::string(",") +
1150+
std::to_string(O.Size) +
1151+
std::string(")");
1152+
}),
11471153
", ") +
11481154
")")
11491155
: "");
@@ -1160,26 +1166,27 @@ struct AAPointerInfoImpl
11601166
bool reachesReturn() const override {
11611167
return !ReturnedOffsets.isUnassigned();
11621168
}
1163-
void addReturnedOffsetsTo(OffsetInfo &OI) const override {
1169+
void addReturnedOffsetsTo(OffsetInfo &OI, Value &Origin) const override {
11641170
if (ReturnedOffsets.isUnknown()) {
1165-
OI.setUnknown();
1171+
OI.setUnknown(Origin);
11661172
return;
11671173
}
11681174

11691175
OffsetInfo MergedOI;
11701176
for (auto Offset : ReturnedOffsets) {
11711177
OffsetInfo TmpOI = OI;
1172-
TmpOI.addToAll(Offset);
1178+
TmpOI.addToAll(Offset.Offset);
11731179
MergedOI.merge(TmpOI);
11741180
}
11751181
OI = std::move(MergedOI);
11761182
}
11771183

1178-
ChangeStatus setReachesReturn(const OffsetInfo &ReachedReturnedOffsets) {
1184+
ChangeStatus setReachesReturn(const OffsetInfo &ReachedReturnedOffsets,
1185+
Value &V) {
11791186
if (ReturnedOffsets.isUnknown())
11801187
return ChangeStatus::UNCHANGED;
11811188
if (ReachedReturnedOffsets.isUnknown()) {
1182-
ReturnedOffsets.setUnknown();
1189+
ReturnedOffsets.setUnknown(V);
11831190
return ChangeStatus::CHANGED;
11841191
}
11851192
if (ReturnedOffsets.merge(ReachedReturnedOffsets))
@@ -1486,7 +1493,7 @@ struct AAPointerInfoImpl
14861493
ChangeStatus Changed = ChangeStatus::UNCHANGED;
14871494
const auto &OtherAAImpl = static_cast<const AAPointerInfoImpl &>(OtherAA);
14881495
bool IsByval = OtherAAImpl.getAssociatedArgument()->hasByValAttr();
1489-
Changed |= setReachesReturn(OtherAAImpl.ReturnedOffsets);
1496+
Changed |= setReachesReturn(OtherAAImpl.ReturnedOffsets, CB);
14901497

14911498
// Combine the accesses bin by bin.
14921499
const auto &State = OtherAAImpl.getState();
@@ -1829,7 +1836,7 @@ ChangeStatus AAPointerInfoFloating::updateImpl(Attributor &A) {
18291836
if (auto *RI = dyn_cast<ReturnInst>(Usr)) {
18301837
if (RI->getFunction() == getAssociatedFunction()) {
18311838
auto &PtrOI = OffsetInfoMap[CurPtr];
1832-
Changed |= setReachesReturn(PtrOI);
1839+
Changed |= setReachesReturn(PtrOI, *CurPtr);
18331840
return true;
18341841
}
18351842
return false;
@@ -2087,7 +2094,7 @@ ChangeStatus AAPointerInfoFloating::updateImpl(Attributor &A) {
20872094
if (!CSRetPI)
20882095
return false;
20892096
OffsetInfo OI = OffsetInfoMap[CurPtr];
2090-
CSArgPI->addReturnedOffsetsTo(OI);
2097+
CSArgPI->addReturnedOffsetsTo(OI, *CurPtr);
20912098
Changed =
20922099
translateAndAddState(A, *CSRetPI, OI, *CB, IsRetMustAcc) | Changed;
20932100
return isValidState();
@@ -13703,8 +13710,9 @@ struct AAAllocationInfoImpl : public AAAllocationInfo {
1370313710
[](DenseMap<Instruction *, DenseMap<AA::RangeTy, AA::RangeTy>> &Map,
1370413711
Instruction *LocalInst, const AA::RangeTy &OldRange,
1370513712
const AA::RangeTy &NewRange) {
13713+
auto [It, Inserted] = Map.try_emplace(LocalInst);
1370613714
DenseMap<AA::RangeTy, AA::RangeTy> &NewBinsForInstruction =
13707-
Map.getOrInsertDefault(LocalInst);
13715+
It->second;
1370813716

1370913717
NewBinsForInstruction.insert(std::make_pair(OldRange, NewRange));
1371013718
};
@@ -14036,11 +14044,12 @@ struct AAAllocationInfoImpl : public AAAllocationInfo {
1403614044
if (OldOffset == NewComputedOffset)
1403714045
return false;
1403814046

14039-
AA::RangeTy &NewRange = NewComputedOffsets.getOrInsertDefault(OldRange);
14047+
auto [It, Inserted] = NewComputedOffsets.try_emplace(OldRange);
14048+
AA::RangeTy &NewRange = It->second;
1404014049
NewRange.Offset = NewComputedOffset;
1404114050
NewRange.Size = Size;
1404214051

14043-
return true;
14052+
return Inserted;
1404414053
}
1404514054

1404614055
// A helper function to check if simplified values exists for the current

llvm/test/Transforms/Attributor/ArgumentPromotion/live_called_from_dead_2.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,9 @@ define internal i32 @caller(ptr %B) {
5252
;
5353
; CGSCC: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: write)
5454
; CGSCC-LABEL: define {{[^@]+}}@caller
55-
; CGSCC-SAME: (ptr noalias nocapture nofree noundef nonnull writeonly align 4 dereferenceable(4) [[B:%.*]]) #[[ATTR0]] {
55+
; CGSCC-SAME: (ptr noalias nofree noundef nonnull writeonly align 4 captures(none) dereferenceable(4) [[B:%.*]]) #[[ATTR0]] {
5656
; CGSCC-NEXT: [[A1:%.*]] = alloca [0 x i8], align 1
57-
; CGSCC-NEXT: [[C:%.*]] = call i32 @test(ptr noalias nocapture nofree noundef nonnull writeonly align 4 dereferenceable(4) [[B]]) #[[ATTR2:[0-9]+]]
57+
; CGSCC-NEXT: [[C:%.*]] = call i32 @test(ptr noalias nofree noundef nonnull writeonly align 4 captures(none) dereferenceable(4) [[B]]) #[[ATTR2:[0-9]+]]
5858
; CGSCC-NEXT: ret i32 0
5959
;
6060
%A = alloca i32

llvm/test/Transforms/Attributor/IPConstantProp/pthreads.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
3434
define dso_local i32 @main() {
3535
; TUNIT-LABEL: define {{[^@]+}}@main() {
3636
; TUNIT-NEXT: entry:
37-
; TUNIT-NEXT: [[ALLOC11:%.*]] = alloca [0 x i8], align 1
38-
; TUNIT-NEXT: [[ALLOC22:%.*]] = alloca [0 x i8], align 1
37+
; TUNIT-NEXT: [[ALLOC1:%.*]] = alloca i8, align 8
38+
; TUNIT-NEXT: [[ALLOC2:%.*]] = alloca i8, align 8
3939
; TUNIT-NEXT: [[THREAD:%.*]] = alloca i64, align 8
4040
; TUNIT-NEXT: [[CALL:%.*]] = call i32 @pthread_create(ptr noundef nonnull align 8 dereferenceable(8) [[THREAD]], ptr noundef null, ptr noundef nonnull @foo, ptr nofree readnone undef)
4141
; TUNIT-NEXT: [[CALL1:%.*]] = call i32 @pthread_create(ptr noundef nonnull align 8 dereferenceable(8) [[THREAD]], ptr noundef null, ptr noundef nonnull @bar, ptr noalias nofree nonnull readnone align 8 captures(none) dereferenceable(8) undef)

0 commit comments

Comments
 (0)