Skip to content

Commit

Permalink
[Attributor] Simplify assumptions "stores"
Browse files Browse the repository at this point in the history
When we add an assumption about memory to the AAPointerInfo bins, we
should simplify the assumed value, like we do for stores.
  • Loading branch information
jdoerfert committed Aug 23, 2023
1 parent 010e3b8 commit 9a80ebe
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 18 deletions.
9 changes: 7 additions & 2 deletions llvm/lib/Transforms/IPO/AttributorAttributes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1823,9 +1823,14 @@ ChangeStatus AAPointerInfoFloating::updateImpl(Attributor &A) {
LLVM_DEBUG(dbgs() << "[AAPointerInfo] Assumption found "
<< *Assumption.second << ": " << *LoadI
<< " == " << *Assumption.first << "\n");

bool UsedAssumedInformation = false;
std::optional<Value *> Content = nullptr;
if (Assumption.first)
Content =
A.getAssumedSimplified(*Assumption.first, *this,
UsedAssumedInformation, AA::Interprocedural);
return handleAccess(
A, *Assumption.second, Assumption.first, AccessKind::AK_ASSUMPTION,
A, *Assumption.second, Content, AccessKind::AK_ASSUMPTION,
OffsetInfoMap[CurPtr].Offsets, Changed, *LoadI->getType());
}

Expand Down
19 changes: 3 additions & 16 deletions llvm/test/Transforms/Attributor/value-simplify-pointer-info.ll
Original file line number Diff line number Diff line change
Expand Up @@ -3146,16 +3146,11 @@ define i32 @recSimplify(i32 %v, i1 %cond) {
; TUNIT-SAME: (i32 [[V:%.*]], i1 noundef [[COND:%.*]]) #[[ATTR14]] {
; TUNIT-NEXT: br i1 [[COND]], label [[REC:%.*]], label [[COMP:%.*]]
; TUNIT: rec:
; TUNIT-NEXT: [[RV:%.*]] = call i32 @recSimplify(i32 [[V]], i1 noundef false) #[[ATTR14]]
; TUNIT-NEXT: ret i32 [[RV]]
; TUNIT-NEXT: [[RV:%.*]] = call i32 @recSimplify(i32 undef, i1 noundef false) #[[ATTR14]]
; TUNIT-NEXT: ret i32 1
; TUNIT: comp:
; TUNIT-NEXT: store i32 [[V]], ptr @GRS, align 4
; TUNIT-NEXT: store i32 1, ptr @GRS2, align 4
; TUNIT-NEXT: [[L:%.*]] = load i32, ptr @GRS, align 4
; TUNIT-NEXT: [[C:%.*]] = icmp eq i32 [[L]], 1
; TUNIT-NEXT: call void @llvm.assume(i1 noundef [[C]]) #[[ATTR23:[0-9]+]]
; TUNIT-NEXT: [[R:%.*]] = call i32 @recSimplify2() #[[ATTR24:[0-9]+]]
; TUNIT-NEXT: ret i32 [[R]]
; TUNIT-NEXT: ret i32 1
;
; CGSCC: Function Attrs: nofree nosync nounwind
; CGSCC-LABEL: define {{[^@]+}}@recSimplify
Expand Down Expand Up @@ -3190,12 +3185,6 @@ comp:
}

define internal i32 @recSimplify2() {
; TUNIT: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(read)
; TUNIT-LABEL: define {{[^@]+}}@recSimplify2
; TUNIT-SAME: () #[[ATTR6]] {
; TUNIT-NEXT: [[R:%.*]] = load i32, ptr @GRS, align 4
; TUNIT-NEXT: ret i32 [[R]]
;
; CGSCC: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(read)
; CGSCC-LABEL: define {{[^@]+}}@recSimplify2
; CGSCC-SAME: () #[[ATTR7]] {
Expand Down Expand Up @@ -3268,8 +3257,6 @@ declare void @llvm.assume(i1 noundef)
; TUNIT: attributes #[[ATTR20]] = { norecurse }
; TUNIT: attributes #[[ATTR21]] = { nounwind }
; TUNIT: attributes #[[ATTR22]] = { nofree nosync nounwind willreturn }
; TUNIT: attributes #[[ATTR23]] = { nofree }
; TUNIT: attributes #[[ATTR24]] = { nofree nosync nounwind memory(read) }
;.
; CGSCC: attributes #[[ATTR0]] = { mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: write) }
; CGSCC: attributes #[[ATTR1]] = { mustprogress nofree nosync nounwind willreturn memory(argmem: readwrite) }
Expand Down

0 comments on commit 9a80ebe

Please sign in to comment.