This patch limits the def-use traversal in forgetValue to defs that have
a value in ValueExprMap, are in the same loop as the starting
instructions or are phis. This should ensure that we invalidate SCEVs as
needed, but avoid traversing instructions for which no SCEVs exist or
which have already been invalidated.
In particular, it should still invalidate
- SCEVs for instructions if any of its operands have a SCEV which is invalidate,
- any add-recs that depend on a given value in the current loop,
- and LCSSA loop exit phis.
There's assertions to try to catch any cases where invalidation is
missed now, which should help to surface any edge-cases, if any.
This can cut down the time spent invalidating SCEVs. For some internal
workloads with very large functions, this reduces the time spent in
passes using SCEV by 2-5x.
For CTmark, there are also some notable improvements, mostly in ClamAV
(-0.91% with -O3):
- NewPM-O3: -0.12%
- NewPM-ReleaseThinLTO: -0.10%
- NewPM-ReleaseLTO-g: -0.07%
Depends on D144848.