2

I am trying to see whether or not the GCC applies partial dead code elimination optimization.

Partial dead code elimination can be considered as the result of the two opt passes: assignment sinking + dead code elimination. For example

x = 3;                                   
y = p + q;                       y = p + q;                       y = p + q;
if(cond) then                    if(cond) then                    if(cond) then
    x = 5;       assn sinking        x = 3;     dead code eln         x = 5;
    p = p*q;     ----------->        x = 5;     ------------->        p = p*q;
else                                 p = p*q;                     else
    q = p*q;                     else                                 x = 3;
end if;                              x = 3;                           q = p*q;
out(x);                              q = p*q;                     end if;
                                 end if;                          out(x)
                                 out(x)

I have tried the following things.

Remark: all of my observations are based on dump files dumped at Gimple level, not at RTL level.

GCC version on my computer: gcc (Ubuntu 7.4.0-1ubuntu1~18.04.1) 7.4.0.

I tried compiling my code with the following command:

gcc -O3 -fdump-tree-all pde.c

I am getting the following dump files. There is one named pde.c.134t.sink where it is expected to see the forward store motion according to GCC 7.4.0 documentation. But I am not able to find any type of code motion at any of the gimple level dump files. I am not sure about whether it is doing the code motion at the RTL level? I have tried a lot of benchmarks and I have never seen assignment sinking/ partial dead code elimination at Gimple level.

Question1: Does GCC apply assignment sinking / partial dead code elimination?

Question2: If yes then where can I see this?

dwijesh522
  • 29
  • 4

1 Answers1

1

It looks like whatever you are using as your reference source does not follow Static Single Assignment (SSA) form. In a very early stage, GCC converts the program to SSA form (in the ssa pass). In SSA form, this kind of assignment sinking is not relevant because the sinking is implicitly represented in the way phi nodes work. If assignment sinking were performed before converting to SSA form, it would just increase the number of SSA names, and thus create more work for later optimizations.

Florian Weimer
  • 32,022
  • 3
  • 48
  • 92
  • Sorry, I am not able to understand what you are saying. I referred to [GCC slides](https://www.cse.iitb.ac.in/grc/gcc-workshop-09/downloads/gccw09-gimple.pdf) (slide-6). Where it says that some optimizations are done after the creation of Gimple files and some optimizations are enabled after creating RTL files. I verified for Gimple files ( whether or not pde/ assn sinking occurs)but it is difficult to verify the same for RTL files. Can you please elaborate your answer? – dwijesh522 Jun 20 '19 at 16:03