Skip to content

Commit b19cd27

Browse files
author
Johannes Doerfert
committedSep 3, 2019
[Attributor] Use the delete API for liveness
Reviewers: uenoku, sstefan1 Subscribers: hiraditya, bollu, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D66833 llvm-svn: 370818
1 parent 7516a5e commit b19cd27

File tree

3 files changed

+24
-16
lines changed

3 files changed

+24
-16
lines changed
 

‎llvm/lib/Transforms/IPO/Attributor.cpp

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1868,7 +1868,7 @@ struct AAIsDeadImpl : public AAIsDead {
18681868
Function &F = *getAssociatedFunction();
18691869

18701870
if (AssumedLiveBlocks.empty()) {
1871-
F.replaceAllUsesWith(UndefValue::get(F.getType()));
1871+
A.deleteAfterManifest(F);
18721872
return ChangeStatus::CHANGED;
18731873
}
18741874

@@ -1918,6 +1918,9 @@ struct AAIsDeadImpl : public AAIsDead {
19181918
}
19191919
}
19201920
}
1921+
1922+
if (SplitPos == &NormalDestBB->front())
1923+
AssumedLiveBlocks.insert(NormalDestBB);
19211924
}
19221925

19231926
BB = SplitPos->getParent();
@@ -1926,6 +1929,10 @@ struct AAIsDeadImpl : public AAIsDead {
19261929
HasChanged = ChangeStatus::CHANGED;
19271930
}
19281931

1932+
for (BasicBlock &BB : F)
1933+
if (!AssumedLiveBlocks.count(&BB))
1934+
A.deleteAfterManifest(BB);
1935+
19291936
return HasChanged;
19301937
}
19311938

@@ -3309,14 +3316,18 @@ ChangeStatus Attributor::run() {
33093316
<< " blocks and " << ToBeDeletedInsts.size()
33103317
<< " instructions\n");
33113318
for (Instruction *I : ToBeDeletedInsts) {
3312-
if (I->hasNUsesOrMore(1))
3319+
if (!I->use_empty())
33133320
I->replaceAllUsesWith(UndefValue::get(I->getType()));
33143321
I->eraseFromParent();
33153322
}
3316-
for (BasicBlock *BB : ToBeDeletedBlocks) {
3317-
// TODO: Check if we need to replace users (PHIs, indirect branches?)
3318-
BB->eraseFromParent();
3323+
3324+
if (unsigned NumDeadBlocks = ToBeDeletedBlocks.size()) {
3325+
SmallVector<BasicBlock *, 8> ToBeDeletedBBs;
3326+
ToBeDeletedBBs.reserve(NumDeadBlocks);
3327+
ToBeDeletedBBs.append(ToBeDeletedBlocks.begin(), ToBeDeletedBlocks.end());
3328+
DeleteDeadBlocks(ToBeDeletedBBs);
33193329
}
3330+
33203331
for (Function *Fn : ToBeDeletedFunctions) {
33213332
Fn->replaceAllUsesWith(UndefValue::get(Fn->getType()));
33223333
Fn->eraseFromParent();

‎llvm/test/Transforms/FunctionAttrs/arg_returned.ll

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -804,10 +804,8 @@ attributes #0 = { noinline nounwind uwtable }
804804
; BOTH-DAG: attributes #{{[0-9]*}} = { nofree noinline nosync nounwind readnone uwtable }
805805
; BOTH-DAG: attributes #{{[0-9]*}} = { nofree noinline noreturn nosync nounwind readonly uwtable }
806806
; BOTH-DAG: attributes #{{[0-9]*}} = { noinline nounwind uwtable }
807-
; BOTH-DAG: attributes #{{[0-9]*}} = { nofree noinline nosync nounwind readnone uwtable willreturn }
808-
; BOTH-DAG: attributes #{{[0-9]*}} = { nofree noinline nosync nounwind uwtable willreturn }
807+
; BOTH-DAG: attributes #{{[0-9]*}} = { noreturn }
809808
; BOTH-DAG: attributes #{{[0-9]*}} = { nofree nosync willreturn }
810809
; BOTH-DAG: attributes #{{[0-9]*}} = { nofree nosync }
811810
; BOTH-DAG: attributes #{{[0-9]*}} = { nofree noreturn nosync }
812-
; BOTH-DAG: attributes #{{[0-9]*}} = { noreturn }
813811
; BOTH-NOT: attributes #

‎llvm/test/Transforms/FunctionAttrs/liveness.ll

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ declare i32 @bar() nosync readnone
1515
; This internal function has no live call sites, so all its BBs are considered dead,
1616
; and nothing should be deduced for it.
1717

18-
; CHECK: define internal i32 @dead_internal_func(i32 %0)
18+
; CHECK-NOT: define internal i32 @dead_internal_func(i32 %0)
1919
define internal i32 @dead_internal_func(i32 %0) {
2020
%2 = icmp slt i32 %0, 1
2121
br i1 %2, label %3, label %5
@@ -56,14 +56,13 @@ entry:
5656
call void @no_return_call()
5757
; CHECK: call void @no_return_call()
5858
; CHECK-NEXT: unreachable
59+
; CHECK-NEXT: }
5960
call i32 @dead_internal_func(i32 10)
60-
; CHECK call i32 undef(i32 10)
6161
%cmp = icmp eq i32 %a, 0
6262
br i1 %cmp, label %cond.true, label %cond.false
6363

6464
cond.true: ; preds = %entry
6565
call i32 @internal_load(i32* %ptr2)
66-
; CHECK: call i32 @internal_load(i32* %ptr2)
6766
%load = call i32 @volatile_load(i32* %ptr1)
6867
call void @normal_call()
6968
%call = call i32 @foo()
@@ -104,6 +103,8 @@ cond.false: ; preds = %entry
104103
br label %cond.end
105104

106105
cond.end: ; preds = %cond.false, %cond.true
106+
; CHECK: cond.end:
107+
; CHECK-NEXT: ret i32 %call1
107108
%cond = phi i32 [ %call, %cond.true ], [ %call1, %cond.false ]
108109
ret i32 %cond
109110
}
@@ -120,7 +121,7 @@ cond.true: ; preds = %entry
120121
; CHECK: call void @no_return_call()
121122
; CHECK-NEXT: unreachable
122123
call i32 @dead_internal_func(i32 10)
123-
; CHECK call i32 undef(i32 10)
124+
; CHECK-NOT: call
124125
%call = call i32 @foo()
125126
br label %cond.end
126127

@@ -129,7 +130,7 @@ cond.false: ; preds = %entry
129130
; CHECK: call void @no_return_call()
130131
; CHECK-NEXT: unreachable
131132
call i32 @dead_internal_func(i32 10)
132-
; CHECK call i32 undef(i32 10)
133+
; CHECK-NEXT: }
133134
%call1 = call i32 @bar()
134135
br label %cond.end
135136

@@ -215,9 +216,7 @@ cond.true: ; preds = %entry
215216
; CHECK-NEXT: call i32 @foo_noreturn_nounwind()
216217
; CHECK-NEXT: unreachable
217218

218-
; We keep the invoke around as other attributes might have references to it.
219-
; CHECK: cond.true.split: ; No predecessors!
220-
; CHECK-NEXT: invoke i32 @foo_noreturn_nounwind()
219+
; CHECK-NOT: @foo_noreturn_nounwind()
221220

222221
cond.false: ; preds = %entry
223222
call void @normal_call()

0 commit comments

Comments
 (0)
Please sign in to comment.