Skip to content

Commit 3fae904

Browse files
jdoerferttstellar
authored andcommitted
[OpenMP][FIX] Properly check assume only uses
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)
1 parent 8d650ca commit 3fae904

File tree

3 files changed

+138
-86
lines changed

3 files changed

+138
-86
lines changed

llvm/lib/Transforms/IPO/AttributorAttributes.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4161,12 +4161,14 @@ struct AAIsDeadFloating : public AAIsDeadValueImpl {
41614161
return true;
41624162
if (auto *LI = dyn_cast<LoadInst>(V)) {
41634163
if (llvm::all_of(LI->uses(), [&](const Use &U) {
4164-
return InfoCache.isOnlyUsedByAssume(
4165-
cast<Instruction>(*U.getUser())) ||
4166-
A.isAssumedDead(U, this, nullptr, UsedAssumedInformation);
4164+
auto &UserI = cast<Instruction>(*U.getUser());
4165+
if (InfoCache.isOnlyUsedByAssume(UserI)) {
4166+
if (AssumeOnlyInst)
4167+
AssumeOnlyInst->insert(&UserI);
4168+
return true;
4169+
}
4170+
return A.isAssumedDead(U, this, nullptr, UsedAssumedInformation);
41674171
})) {
4168-
if (AssumeOnlyInst)
4169-
AssumeOnlyInst->insert(LI);
41704172
return true;
41714173
}
41724174
}

llvm/test/Transforms/Attributor/value-simplify-assume.ll

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,12 +390,14 @@ define void @assume_2b_nr(i1 %arg, i1 %cond) norecurse {
390390
; CHECK: Function Attrs: nofree norecurse nosync nounwind willreturn memory(inaccessiblemem: readwrite)
391391
; CHECK-LABEL: define {{[^@]+}}@assume_2b_nr
392392
; CHECK-SAME: (i1 [[ARG:%.*]], i1 noundef [[COND:%.*]]) #[[ATTR3]] {
393+
; CHECK-NEXT: [[STACK:%.*]] = alloca i1, align 1
393394
; CHECK-NEXT: br i1 [[COND]], label [[T:%.*]], label [[F:%.*]]
394395
; CHECK: t:
395396
; CHECK-NEXT: br label [[M:%.*]]
396397
; CHECK: f:
397398
; CHECK-NEXT: br label [[M]]
398399
; CHECK: m:
400+
; CHECK-NEXT: [[L:%.*]] = load i1, ptr [[STACK]], align 1
399401
; CHECK-NEXT: ret void
400402
;
401403
%stack = alloca i1
@@ -1005,12 +1007,14 @@ define void @assume_2b(i1 %arg, i1 %cond) {
10051007
; CHECK: Function Attrs: nofree norecurse nosync nounwind willreturn memory(inaccessiblemem: readwrite)
10061008
; CHECK-LABEL: define {{[^@]+}}@assume_2b
10071009
; CHECK-SAME: (i1 [[ARG:%.*]], i1 noundef [[COND:%.*]]) #[[ATTR3]] {
1010+
; CHECK-NEXT: [[STACK:%.*]] = alloca i1, align 1
10081011
; CHECK-NEXT: br i1 [[COND]], label [[T:%.*]], label [[F:%.*]]
10091012
; CHECK: t:
10101013
; CHECK-NEXT: br label [[M:%.*]]
10111014
; CHECK: f:
10121015
; CHECK-NEXT: br label [[M]]
10131016
; CHECK: m:
1017+
; CHECK-NEXT: [[L:%.*]] = load i1, ptr [[STACK]], align 1
10141018
; CHECK-NEXT: ret void
10151019
;
10161020
%stack = alloca i1

0 commit comments

Comments
 (0)