2011/11/7 Richard Guenther <richard.guent...@gmail.com>: > On Mon, Nov 7, 2011 at 5:07 PM, Jeff Law <l...@redhat.com> wrote: >> -----BEGIN PGP SIGNED MESSAGE----- >> Hash: SHA1 >> >> >>> >>> I also wonder if instead of a new pass control-dependent DCE can be >>> taught of this? >> It could. I'm not sure it really buys us anything except maybe being >> able to reuse the pdom & control-dependency analysis. >> >> It actually more naturally belongs in cprop because it's cprop that >> exposes NULL pointers in useful ways (in memory dereferences and as >> PHI args). > > Heh, indeed, that as well. I suppose every pass that handles > unexecutable edges in some way might benefit from this. Like for > > if (i) > j_1 = 1; > else > { > j_2 = 2; > *0 = ...; > } > j_3 = PHI <j_1, j_2> > > we could CCP j_1 = 1 to j_3 ... > > Even without actually removing the edge and the trapping stmt. > > For DCE the most interesting part would be to end the block at > the point of the trap - thus - replace the store with a __builtin_trap () > which then trivially makes all code w/o side-effects on the path > dead. > > Richard.
Well, easiest sample to see effect of if-joining is on patterns like this. As here neither PHI-opt nor tail-merge helps pretty much, as condition chain doesn't get reduced to simple form. The sample above seems to be too less explicit to get the point. Eg: int doo (void); int foo (unsigned int a, unsigned int b) { if (a == 0) rerturn doo (); if (b == 0) return doo (); if (a == 1) return doo (); if (b == 1) return doo (); if (a == 2) return doo (); if (b == 2) return doo (); return -2; } This sample would be the same (in associative form) as int doo (void); int foo (unsigned int a, unsigned int b) { if (a == 0 || b == 0 || a == 1 || b == 1 || a == 2 || b == 2) rerturn doo (); return -2; } (btw both samples won't be folded for IA due current BC). With the first patch doing the transformation to associative truth-bitwise for all simple operands, the second example will be folded by reassoc-pass to ... if (a <= 2 || b <=2) return doo (); return -2; ... With the if-joining also the first example gets optimized to this simple form. Regards, Kai