[llvm] [MachineLICM] Rematerialize instructions that may be hoisted before LICM (PR #158479)

via llvm-commits llvm-commits at lists.llvm.org
Sun Sep 14 17:54:05 PDT 2025


dianqk wrote:

> Thanks for looking into this.
> 
> The terminology used here is a bit confusing. "Rematerialization" in this context usually implies that a _copy_ of the instruction is generated in the loop. This is something regalloc can do to avoid spills. As far as I can tell, this is not what you are doing here -- this is plain sinking, not rematerialization.
> 
> I'm not particularly familiar with these transforms, so I don't have much to say here. I'm not sure whether this approach of first sinking everything and then trying to hoist again makes sense -- it seems like this would likely end up overshooting in the other direction and end up moving too many calculations into the loop. It's hard to say without seeing how this affects codegen in practice.

Thanks for your explanation. Rematerialization handles the register spills, not the hoisted instructions.
I just found I missed the thing that the hoisted instructions do not always run even in the loop body. This should be an issue to be addressed.

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


More information about the llvm-commits mailing list