[llvm-branch-commits] [llvm] [Passes] Disable code sinking in InstCombine early on. (PR #72567)

Florian Hahn via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Fri Nov 17 01:43:52 PST 2023


fhahn wrote:

>  Is the idea here that if the original code executed these unconditionally, then it's more likely than not that unconditionally executing them is beneficial?

I think the main motivation for the patch is the hypothesis  that sinking early is worse as canonical form early on, because once we sunk we cannot really undo it easily. And once we sunk, we won't be able to consider certain transforms. 

Delaying sinking gives other passes like SimplifyCFG a chance to perform things like if-conversion, if considered profitable. There certainly could be regressions due to SimplifyCFG's cost model taking a wrong decision but I think in those cases it would be better to improve the cost model, rather than preventing it up-front by sinking (which isn't cost-model driven at all in InstCombine IIRC). It should also be possible to undo if-conversion in the backend, if that's more profitable there; at this point, we also arguably have much more accurate information about register pressure, available execution units, accurate latencys to make a more informed decision.

Slightly orthogonal to this, one thing I want to look into at some point is adding a way to specific dereferenceabilty at various program points for pointers (e.g. via an intrinsic or assumption). That would ideally allow us to retain dereferenceabilty information from the original program, even after sinking and would allow if-conversion even after sinking. Avoiding sinking early on would probably still be the preferred early canonical form I think.

https://github.com/llvm/llvm-project/pull/72567


More information about the llvm-branch-commits mailing list