[llvm] [SimplifyCFG] Preserve common TBAA metadata when hoisting instructions. (PR #97158)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Sun Jun 30 09:20:34 PDT 2024


nikic wrote:

> > This would get automatically handled if it used the actual hoisting logic -- why doesn't it?
> 
> Do you mean `hoistCommonCodeFromSuccessors`? The code in `FoldTwoEntryPHINode` hoist any code, not just common code. The current logic however only preserves TBAA metadata across common instructions for now

Right. My point here is that if hoisting is possible, we should hoist instead of performing this transform. What you are proposing here is an odd middle ground where we keep the metadata as if we were hoisting, but still have two separate instructions for the two branches.

I assume the motivation here is that FoldTwoEntryPHINode is performed in early SimplifyCFG runs that do not enable hoisting -- I think the correct way to address this issue is to perform hoisting in the cases where it is possible and where FoldTwoEntryPHINode thinks its profitable, as what hoisting does is strictly better.

The lazy way to do that would be to try calling hoistCommonCodeFromSuccessors() after FoldTwoEntryPHINode's profitability checks. The proper way to do it would be something like allowing early hoisting if it will hoist out all instructions including terminator (we already have an exception to allow early hoisting of just terminators).

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


More information about the llvm-commits mailing list