We’ve noticed the function “isOnlyCopiedFromConstantGlobal” showing up in VTune on an example with slow compilation time (inside a JIT) and I was trying to see if I could simplify it. Although, I suspect the real problem is that it is being called quadratically from InstCombine - we’re looking in that as well. More on that later, hopefully.
In order to understand the code more easily I restructured it to use the InstVisitor instead of a mix of early returns and continues. This version passes all of the unit tests. I left the old code there in comments to try to make it easier to reason about if the two implementations should have the same behavior.
To me, the old code was hard to reason about due to the interleaved “return false” and “continue” - this version tries to tame that control flow a bit. One thing I was not super confident about is “I.isLifetimeStartOrEnd” - is my reasoning correct that you only really need to check that on Call instructions?
Thanks for any thoughts on the topic.