[PATCH] D46422: [LCSSA] Iteratively remove unused PHI nodes in formLCSSAForInstructions

Michael Zolotukhin via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri May 4 17:30:43 PDT 2018


mzolotukhin added a comment.

I looked deeper into this, and I think you exposed several issues here:

- The entire thing is triggered by the fact that the value we're rewriting is used in an unreachable block. We might just ignore such cases (see the loop on lines 102-110).
- The loops in this test are not in simplified form. While they are not guaranteed to be in it, it might indicate that we have a bug in some other pass that fails to preserve the loop in a simplified form. Whatever fix for the current issue we choose, it would be interesting to understand what led to this situation.

Returning back to the issue in question, here is my understanding of what happens in this case. LCSSA adds a phi-node for the `%value`. The phi-nodes it creates in the process happen to land into another loop, and thus we need to build LCSSA for those loop too (that's why we iterate several times in the worklist loop). When we add LCSSA phi-nodes for the second loop, we again insert phi-nodes into yet another loop. This continues until we convert all touched loops to LCSSA form. What happens in this process is that a PHI-node might have 0 uses at the time it was inserted first time, but as we keep inserting new phis, it might happen to be used in some of the latter phis - which is why the assertion fails. I think the fix should be to just replace the assert with the check (+add a comment about it). After this some redundant phi-nodes might remain in the program, but that could be fixed by adding operands of the phi to `PHIsToRemove` if they are not used anywhere except the phi, which we're removing.

Thanks,
Michael


Repository:
  rL LLVM

https://reviews.llvm.org/D46422





More information about the llvm-commits mailing list