[llvm] r296069 - Fix an iterator invalidation bug when simplifying LIC user.
Xin Tong via llvm-commits
llvm-commits at lists.llvm.org
Thu Feb 23 17:43:36 PST 2017
Date: Thu Feb 23 19:43:36 2017
New Revision: 296069
Fix an iterator invalidation bug when simplifying LIC user.
LoopUnswitch/simplify-with-nonvalness.ll is the test case for this.
The LIC has 2 users and deleting the 1st user when it can be simplified
invalidated the iterator for the 2nd user.
--- llvm/trunk/lib/Transforms/Scalar/LoopUnswitch.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/LoopUnswitch.cpp Thu Feb 23 19:43:36 2017
@@ -1231,7 +1231,13 @@ void LoopUnswitch::RewriteLoopBodyWithCo
// This in-loop instruction has been simplified w.r.t. its context,
// i.e. LIC != Val, make sure we propagate its replacement value to
// all its users.
- ReplaceUsesOfWith(UI, Replacement, Worklist, L, LPM);
+ // We can not yet delete UI, the LIC user, yet, because that would invalidate
+ // the LIC->users() iterator !. However, we can make this instruction
+ // dead by replacing all its users and push it onto the worklist so that
+ // it can be properly deleted and its operands simplified.
More information about the llvm-commits