OK.
I was initially a little surprised you didn't just delete the call from
the IL and emit the trivial constant assignment. Then I realized you
probably would need to update the vuse/vdefs that were on the original
call. Using update_call_from_tree seems to take care of that for you.
I didn't see a negative test -- ie one that you shouldn't transform.
Could you extract the one from c#0 in the referenced bz and add it as a
negative test. You can do that as a separate patch which you should
consider pre-approved.
Thanks, that was a great catch! I thought I had this covered but as
it turned out, I hadn't. What's more, in the process of developing
the new test I uncovered a couple of gaps in the pass. I opened bug
78521 to track them and posted a patch with a fix and a new test to
exercise both the absence of the optimization and that the newly
uncovered bugs are fixed:
https://gcc.gnu.org/ml/gcc-patches/2016-11/msg02730.html
Martin