[PATCH] D51770: [IndVars] Set Changed when we delete dead instructions. PR38855
Max Kazantsev via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Sep 6 22:55:07 PDT 2018
mkazantsev created this revision.
mkazantsev added reviewers: etherzhhb, uabelho, skatkov, sanjoy.
IndVars does not set `Changed` flag when it eliminates dead instructions. As result,
it may made IR modifications and report that it has done nothing. It leads to inconsistent
preservedanalyzes results.
https://reviews.llvm.org/D51770
Files:
lib/Transforms/Scalar/IndVarSimplify.cpp
test/Transforms/IndVarSimplify/pr38855.ll
Index: test/Transforms/IndVarSimplify/pr38855.ll
===================================================================
--- test/Transforms/IndVarSimplify/pr38855.ll
+++ test/Transforms/IndVarSimplify/pr38855.ll
@@ -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
+}
Index: lib/Transforms/Scalar/IndVarSimplify.cpp
===================================================================
--- lib/Transforms/Scalar/IndVarSimplify.cpp
+++ lib/Transforms/Scalar/IndVarSimplify.cpp
@@ -2490,8 +2490,10 @@
// which are now dead.
while (!DeadInsts.empty())
if (Instruction *Inst =
- dyn_cast_or_null<Instruction>(DeadInsts.pop_back_val()))
+ dyn_cast_or_null<Instruction>(DeadInsts.pop_back_val())) {
+ Changed = true;
RecursivelyDeleteTriviallyDeadInstructions(Inst, TLI);
+ }
// The Rewriter may not be used from this point on.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D51770.164354.patch
Type: text/x-patch
Size: 1518 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180907/af5670c9/attachment.bin>
More information about the llvm-commits
mailing list