llvm-project/llvm/test/Transforms/LoopDeletion
Max Kazantsev ad3b1fe472 [SCEV] Do not erase LoopUsers. PR53969
This patch fixes a logical error in how we work with `LoopUsers` map.
It maps a loop onto a set of AddRecs that depend on it. The Addrecs
are added to this map only once when they are created and put to
the UniqueSCEVs` map.

The only purpose of this map is to make sure that, whenever we forget
a loop, all (directly or indirectly) dependent SCEVs get forgotten too.

Current code erases SCEVs from dependent set of a given loop whenever
we forget this loop. This is not a correct behavior due to the following scenario:

1. We have a loop `L` and an AddRec `AR` that depends on it;
2. We modify something in the loop, but don't destroy it. We still call forgetLoop on it;
3. `AR` is no longer dependent on `L` according to `LoopUsers`. It is erased from
    ValueExprMap` and `ExprValue map, but still exists in UniqueSCEVs;
4. We can later request the very same AddRec for the very same loop again, and get existing
    SCEV `AR`.
5. Now, `AR` exists and is used again, but its notion that it depends on `L` is lost;
6. Then we decide to delete `L`. `AR` will not be forgotten because we have lost it;
7. Just you wait when you run into a dangling pointer problem, or any other kind of problem
   because an active SCEV is now referecing a non-existent loop.

The solution to this is to stop erasing values from `LoopUsers`. Yes, we will maybe forget something
that is already not used, but it's cheap.

This fixes a functional bug and potentially may have negative compile time impact on methods with
huge or numerous loops.

Differential Revision: https://reviews.llvm.org/D120303
Reviewed By: nikic
2022-02-22 17:24:39 +07:00
..
2007-07-23-InfiniteLoop.ll
2008-05-06-Phi.ll
2011-06-21-phioperands.ll
2017-07-11-incremental-dt.ll [test] Fixup tests with -analyze in llvm/test/Transforms 2021-09-04 16:45:51 -07:00
D108848-regression.ll [LoopDeletion] Revert 3af8a11 and add test coverage for breakage 2022-01-17 11:44:03 -08:00
assume.ll [AsmParser] Unify parsing of attributes 2021-07-15 17:51:11 +02:00
basic-remark.ll
bbi-59728.ll Fix a missing MemorySSA update in breakLoopBackedge 2021-09-01 16:59:01 -07:00
crashbc.ll
dcetest.ll
diundef.ll
eval_first_iteration.ll [LoopDeletion] Support selects when symbolically evaluating 1st iteration 2021-10-09 14:47:44 +07:00
invalidation.ll
irreducible-cfg.ll
loops-with-irreducible-subloops.ll Special case common branch patterns in breakLoopBackedge (try 2) 2021-08-27 10:27:16 -07:00
multiple-exit-conditions.ll
multiple-exits.ll
mustprogress.ll
no-exit-blocks.ll
noop-loops-with-subloops.ll Special case common branch patterns in breakLoopBackedge (try 2) 2021-08-27 10:27:16 -07:00
pr49967.ll Special case common branch patterns in breakLoopBackedge (try 2) 2021-08-27 10:27:16 -07:00
pr53969.ll [SCEV] Do not erase LoopUsers. PR53969 2022-02-22 17:24:39 +07:00
simplify-then-delete.ll [SimplifyCFG] SimplifyCondBranchToTwoReturns(): really only deal with different ret blocks 2021-07-23 00:36:59 +03:00
switch.ll [LoopDeletion] Use max trip count to break backedge in addition to exact one 2021-08-27 14:19:44 -07:00
two-predecessors.ll [llvm][test] rewrite callbr to use i rather than X constraint NFC 2022-01-11 11:31:08 -08:00
unreachable-loops.ll Special case common branch patterns in breakLoopBackedge (try 2) 2021-08-27 10:27:16 -07:00
update-scev.ll [test] Fixup tests with -analyze in llvm/test/Transforms 2021-09-04 16:45:51 -07:00
use-in-unreachable.ll
zero-btc.ll [LoopDeletion] Use max trip count to break backedge in addition to exact one 2021-08-27 14:19:44 -07:00