[Mesa-dev] [PATCH] nir: remove simple dead if detection from nir_opt_dead_cf()

Ilia Mirkin imirkin at alum.mit.edu
Fri Feb 15 13:11:06 UTC 2019


On Fri, Feb 15, 2019 at 3:55 AM Timothy Arceri <tarceri at itsqueeze.com> wrote:
>
> On 15/2/19 4:12 pm, Jason Ekstrand wrote:
> > I think the primary issue we had with dead ifs before is that we were
> > running dce and dead_cf but maybe not peephole_select because it didn't
> > seem applicable.  In principle, I think I like dead_cf being able to
> > handle if statements as well because it seems like a thing it should
> > do.  However, it's obviously very expensive so I'm happy for us to drop
> > it for now.  One day, maybe we can make the pass less expensive so it
> > doesn't walk the list of instructions nearly as many times and making it
> > handle ifs will be more practical.  For now, however, I think this is
> > the right thing to do.
>
> As far as I understand it all it (and peephole) is really doing is removing:
>
> if (cond) {
>
> } else {
>
> }
>
> Because DCE already removes the dead instructions.
>
> This pass is looking at the instructions in every if it sees. If we
> don't want to depend on peephole we can add a simple check in nir_opt_if
> to look for empty branches. That would be much cheaper.

Careful with that...

x = 1;
y = 2;

if (cond) {
  // block1;
} else {
  // block2;
}

z = phi x (block1), y (block2)

Even though the if/else don't contain any code, the blocks themselves
could still be referenced by a phi node, which is important to program
execution.

  -ilia


More information about the mesa-dev mailing list