I work on a pass that requires as input LLVM code without any phi nodes. For this, I use the reg2mem pass which produces suitable code, the pass runs correctly, but I obtain a significant performance decrease. I expect that this is because there are more reads / writes to memory after running the reg2mem pass.
How can I optimize the code, without inserting any phi nodes? Or is there a better solution to eliminate the phi nodes in the first place?
The solution that comes to my mind is to run a custom version of the mem2reg pass. That would mean, after running the reg2mem pass, to eliminate unnecessary load / store instructions, if this can be done without inserting any phi nodes.
Do you think this can be achieved and is it the right way to go?