In some loop situations, when the loop blocks become unreachable, JumpThreading would leave dead blocks behind. It could also generate self-referencing instructions (on a dead cfg).
This patch cleans up those blocks.
Differential D138027
Clean up CFG on JumpThreading arkangath on Nov 15 2022, 5:11 AM. Authored by
Details
In some loop situations, when the loop blocks become unreachable, JumpThreading would leave dead blocks behind. It could also generate self-referencing instructions (on a dead cfg). This patch cleans up those blocks.
Diff Detail
Event TimelineComment Actions Note that for unreachable IR, self-referencing, and other forms of invalidity of IR, is legal.
Comment Actions Yup, I'm aware :)
Comment Actions This doesn't really make sense to me. It deletes trivial cycles, but there may be dead cycles that are larger. Comment Actions I don't understand what you mean. Comment Actions Please can you explain the larger goal you are trying to achieve here?
Comment Actions Yes. Doing this in JumpThreading makes sense only if it avoids issues related to self-referential instructions (inside JumpThreading), and it cannot do so unless it removes all unreachable blocks. For example, I don't think it covers the case from https://reviews.llvm.org/D139783. If this is *not* about self-referential instructions breaking JumpThreading itself, then you need to make the motivation for this clearer -- for example, are you addressing a phase ordering problem? (If so, please add a phase ordering test.) Comment Actions I am aware that the IR after the transformation is legal (as I mentioned in a previous comment). In the larger scope of things, LLVm is being used as a compiler toolchain for a commercial project (sorry for being coy, but you know how big corp is... and I'm not particularly happy about it either). As for more complicated inputs, I would welcome an example. I thought that JumpThreading would eventually reduce any unreachable CFG into a self-referencing block. Nevertheless, _some_ clean up is better than no clean up?
Comment Actions Is that an upstream pass, or a downstream one?
Comment Actions Pass correctness cannot depend on their position in the pipeline. If a pass cannot deal with self-referential IR (by skipping unreachable blocks or in some other way), that's a problem with that pass, not whatever produced the IR. Comment Actions
Ok took me a while to figure it out, but it appears to be a downstream pass which does something like for (auto &I : BB) and then infinite-recurses when trying to transform a BinaryOperator. The .ll file I added on the patch is a bugpoint reduced case. Comment Actions This review may be stuck/dead, consider abandoning if no longer relevant. |
Would it not be sufficient to just add the block into Unreachable set?