2

I've implemented a program that converts a control flow graph to minimal ssa (and I am pretty sure it is correct (see here)). Now I am trying to implement copy propagation. I've implemented it for the most part, but I am unsure what to do when the variable we are propagating is in a phi function. Suppose I have a variable I am going to propagate:

z_0 = y_1

Also, z_0 is in a phi function:

z_1 = PHI(z_0, z_1)

Now, when propagating, what should I do to z_0 in the phi function (because after propagation is finished, I will remove the definition of z_0)? Should I propagate z_0 to the phi function? Such that the phi function looks like this?:

z_1 = PHI(y_1, z_1)
xilpex
  • 3,097
  • 2
  • 14
  • 45
  • 1
    That's what you would do if you were propagating constants, right? So basically, yes. But iirc there are some corner cases with copy propagation. – rici Jul 22 '20 at 21:53
  • @rici -- If you don't mind, what would those be? – xilpex Jul 22 '20 at 22:01
  • I think the issue I was (vaguely) remembering is the lost copy problem mentioned by Preston Briggs et al in "Practical improvements to the construction and destruction of static single assignment form" (non-paywalled copies are available). You can find probably a lot more than you want to know right now about SSA by reading the SSA book, available on http://ssabook.gforge.inria.fr/latest/book.pdf (last update 2018, I notice).... – rici Jul 24 '20 at 02:15
  • While I was looking for Briggs et al., I stumbled upon "Comparison and Evaluation of Back Translation Algorithms for Static Single Assignment Form" by Masataka Sassa, Yo Ito and Masaki Kohama (2007), which also seems interesting at first glance. Good luck. – rici Jul 24 '20 at 02:16

1 Answers1

1

Yes. All uses of z0 are replaced with y1 in copy propagation. There are multiple edge cases to handle, as @rici hinted at, as copy propagation is uniquely adept at breaking phi nodes / inadvertently altering their semantics.

Some of these problems are encapsulated in the "lost copy problem" and "lost swap problem."

qz-
  • 674
  • 1
  • 4
  • 14
  • Would you mind providing more info on the edge cases and maybe providing some reference material? Thanks! – santamanno Apr 17 '21 at 22:00
  • @santamanno I'm trying to learn more about this myself, https://cs.stackexchange.com/q/139050/135438 – qz- Apr 17 '21 at 23:30
  • Please include the additional info - when you have it - in your answer so it can better help the poster. – santamanno Apr 19 '21 at 00:07