On 5/21/19 7:44 AM, Jiufu Guo wrote: > Hi, > > This patch implements a new opportunity of jump threading for PR77820. > In this optimization, conditional jumps are merged with unconditional jump. > And then moving CMP result to GPR is eliminated. > > It looks like below: > > <P0> > p0 = a CMP b > goto <X>; > > <P1> > p1 = c CMP d > goto <X>; > > <X> > # phi = PHI <p0 (P0), p1 (P1)> > if (phi != 0) goto <Y>; else goto <Z>; > > Could be transformed to: > > <P0> > p0 = a CMP b > if (p0 != 0) goto <Y>; else goto <Z>; > > <P1> > p1 = c CMP d > if (p1 != 0) goto <Y>; else goto <Z>; A few high level notes.
I think LLVM does this in their jump threading pass as well, mostly because it enables discovering additional jump threading opportunities IIRC. But it appears to me to be inherently good on its own as well as it eliminates a dynamic unconditional jump. It's also the case that after this transformation we may be able to combine the assignment and test resulting in something like this: > <P0> > if (a CMP b) goto <Y>; else goto <Z>; > > <P1> > if (c CMP d) goto <Y>; else goto <Z>; Which is inherently good *and* the blocks no longer have side effects which can have secondary positive effects in the jump threader. I wouldn't be surprised if this was particularly useful for chained boolean logical tests where some of the arms collapse down to single tests. Jeff