Skip to content

Commit 6409c21

Browse files
committed
[SCEVExpander] Use PoisoningVH for OrigFlags
It's common to delete some instructions after using SCEVExpander, while it is still live (but will not be used afterwards). In that case, the AssertingVH may trigger. Replace it with a PoisoningVH so that we only detect the case where the SCEVExpander actually is used in a problematic fashion after the instruction removal. The alternative would be to add clear() calls to more code paths. Fixes #83404.
1 parent a41bcb3 commit 6409c21

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ class SCEVExpander : public SCEVVisitor<SCEVExpander, Value *> {
8585

8686
/// Original flags of instructions for which they were modified. Used
8787
/// by SCEVExpanderCleaner to undo changes.
88-
DenseMap<AssertingVH<Instruction>, PoisonFlags> OrigFlags;
88+
DenseMap<PoisoningVH<Instruction>, PoisonFlags> OrigFlags;
8989

9090
// The induction variables generated.
9191
SmallVector<WeakVH, 2> InsertedIVs;
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 4
2+
; RUN: opt -S -passes=loop-reduce -mtriple=x86_64-unknown-linux-gnu < %s | FileCheck %s
3+
4+
; Make sure this does not assert.
5+
define void @test() {
6+
; CHECK-LABEL: define void @test() {
7+
; CHECK-NEXT: entry:
8+
; CHECK-NEXT: br label [[FOR_BODY:%.*]]
9+
; CHECK: for.body:
10+
; CHECK-NEXT: br label [[FOR_BODY]]
11+
;
12+
entry:
13+
br label %for.body
14+
15+
for.body:
16+
%0 = phi i64 [ %dec, %for.body ], [ 0, %entry ]
17+
%h.18 = phi i32 [ 1, %for.body ], [ 0, %entry ]
18+
%dec = add i64 %0, 1
19+
%rem = urem i64 %0, 5
20+
%1 = trunc i64 %rem to i32
21+
%tobool3.not = icmp eq i32 %h.18, %1
22+
br label %for.body
23+
}

0 commit comments

Comments
 (0)