Skip to content

Commit

Permalink
[OpenMP][FIX] Properly check assume only uses
Browse files Browse the repository at this point in the history
We improved our simplification and this exposed a bug in the store
elimination. A load that had dead uses and assume uses was thought to be
used by assumes only. Consequently we also deleted the "dead use users".
This was a problem because a dead use just means we will not use the
load there. The user might still be needed.

Exposed by OvO, reported by @ye-luo.

(cherry picked from commit a51ad87)
  • Loading branch information
jdoerfert authored and tstellar committed Feb 6, 2023
1 parent 8d650ca commit 3fae904
Show file tree
Hide file tree
Showing 3 changed files with 138 additions and 86 deletions.
12 changes: 7 additions & 5 deletions llvm/lib/Transforms/IPO/AttributorAttributes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4161,12 +4161,14 @@ struct AAIsDeadFloating : public AAIsDeadValueImpl {
return true;
if (auto *LI = dyn_cast<LoadInst>(V)) {
if (llvm::all_of(LI->uses(), [&](const Use &U) {
return InfoCache.isOnlyUsedByAssume(
cast<Instruction>(*U.getUser())) ||
A.isAssumedDead(U, this, nullptr, UsedAssumedInformation);
auto &UserI = cast<Instruction>(*U.getUser());
if (InfoCache.isOnlyUsedByAssume(UserI)) {
if (AssumeOnlyInst)
AssumeOnlyInst->insert(&UserI);
return true;
}
return A.isAssumedDead(U, this, nullptr, UsedAssumedInformation);
})) {
if (AssumeOnlyInst)
AssumeOnlyInst->insert(LI);
return true;
}
}
Expand Down
4 changes: 4 additions & 0 deletions llvm/test/Transforms/Attributor/value-simplify-assume.ll
Original file line number Diff line number Diff line change
Expand Up @@ -390,12 +390,14 @@ define void @assume_2b_nr(i1 %arg, i1 %cond) norecurse {
; CHECK: Function Attrs: nofree norecurse nosync nounwind willreturn memory(inaccessiblemem: readwrite)
; CHECK-LABEL: define {{[^@]+}}@assume_2b_nr
; CHECK-SAME: (i1 [[ARG:%.*]], i1 noundef [[COND:%.*]]) #[[ATTR3]] {
; CHECK-NEXT: [[STACK:%.*]] = alloca i1, align 1
; CHECK-NEXT: br i1 [[COND]], label [[T:%.*]], label [[F:%.*]]
; CHECK: t:
; CHECK-NEXT: br label [[M:%.*]]
; CHECK: f:
; CHECK-NEXT: br label [[M]]
; CHECK: m:
; CHECK-NEXT: [[L:%.*]] = load i1, ptr [[STACK]], align 1
; CHECK-NEXT: ret void
;
%stack = alloca i1
Expand Down Expand Up @@ -1005,12 +1007,14 @@ define void @assume_2b(i1 %arg, i1 %cond) {
; CHECK: Function Attrs: nofree norecurse nosync nounwind willreturn memory(inaccessiblemem: readwrite)
; CHECK-LABEL: define {{[^@]+}}@assume_2b
; CHECK-SAME: (i1 [[ARG:%.*]], i1 noundef [[COND:%.*]]) #[[ATTR3]] {
; CHECK-NEXT: [[STACK:%.*]] = alloca i1, align 1
; CHECK-NEXT: br i1 [[COND]], label [[T:%.*]], label [[F:%.*]]
; CHECK: t:
; CHECK-NEXT: br label [[M:%.*]]
; CHECK: f:
; CHECK-NEXT: br label [[M]]
; CHECK: m:
; CHECK-NEXT: [[L:%.*]] = load i1, ptr [[STACK]], align 1
; CHECK-NEXT: ret void
;
%stack = alloca i1
Expand Down

0 comments on commit 3fae904

Please sign in to comment.