Skip to content

Commit

Permalink
[IndVars] Set Changed when we delete dead instructions. PR38855
Browse files Browse the repository at this point in the history
IndVars does not set `Changed` flag when it eliminates dead instructions. As result,
it may make IR modifications and report that it has done nothing. It leads to inconsistent
preserved analyzes results.

Differential Revision: https://reviews.llvm.org/D51770
Reviewed By: skatkov

llvm-svn: 341633
  • Loading branch information
Max Kazantsev committed Sep 7, 2018
1 parent 3ab0ee4 commit 9e6845d
Showing 2 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion llvm/lib/Transforms/Scalar/IndVarSimplify.cpp
Original file line number Diff line number Diff line change
@@ -2491,7 +2491,7 @@ bool IndVarSimplify::run(Loop *L) {
while (!DeadInsts.empty())
if (Instruction *Inst =
dyn_cast_or_null<Instruction>(DeadInsts.pop_back_val()))
RecursivelyDeleteTriviallyDeadInstructions(Inst, TLI);
Changed |= RecursivelyDeleteTriviallyDeadInstructions(Inst, TLI);

// The Rewriter may not be used from this point on.

24 changes: 24 additions & 0 deletions llvm/test/Transforms/IndVarSimplify/pr38855.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
; RUN: opt -S -inline -functionattrs -indvars < %s | FileCheck %s

; Check that the invalidation happens correctly and the test does not crash.
define void @f2() {
; CHECK-LABEL: @f2(
; CHECK-NEXT: entry:
; CHECK-NEXT: br label [[FOR_COND:%.*]]
; CHECK: for.cond:
; CHECK-NEXT: br label [[FOR_COND]]
;
entry:
br label %for.cond

for.cond: ; preds = %for.cond, %entry
%a.0 = phi i32 [ 1, %entry ], [ 0, %for.cond ]
call void @f1(i32 %a.0)
br label %for.cond
}

define internal void @f1(i32 %p1) noinline {
entry:
ret void
}

0 comments on commit 9e6845d

Please sign in to comment.