fix OP_PHI usage in try_to_simplify_bb()

In try_to_simplify_bb(), simplification is attempted when a constant
phisrc whose corresponding phi-node control a conditional branch.
In this case, for the path between the phisrc and the conditional
branch, the following OP_PHI is sort of unneeded since the constant
determine which branch will be taken.

If this simplification can be made, it means that the OP_PHI
doesn't depend anymore on the constant phisrc. In fact the OP_PHI's bb
won't be anymore reachable from the constant phisrc's bb.
But currently, the OP_PHI usage is not adjusted and this leads to all
sort of oddities and causes to miss further simplifications.

The situation can be more concretly seen on test-linearize's output,
here an extract of Linux's kernel/futex.c:get_futex_key().
	.L594:
		...
		br          %r1294, .L651, .L656
	.L651:
		phisrc.32   %phi85 <- $1
		br          .L649
	.L656:
		...
		and.64      %r1340 <- %r1339, $1
		phisrc.32   %phi87 <- %r1340
		phi.32      %r1343 <- %phi85, %phi87
		br          %r1343, .L649, .L648

The constant phisrc is %phi85 in .L651, the OP_PHI and the conditional
branch are .L656's last instructions (which have been packed with its
now unique parent which is sign of a problem). One can see that the
OP_PHi seems to depend on %phi85 (it's in its phi_list) but in fact
depends only on %phi87 (.L656 can't be reached from .L651 where %phi85
is defined since after the simplification .L651 directly branches to
one of the .L656's children, here .L649).

The fix consists in adjusting the OP_PHI's usage when the
simplification is made.

On the same code extract we can now see that the situation is more
"normal". In fact the OP_PHI have now been able to be optimized away
together, as well as .L651:
	.L594:
		...
		br          %r1294, .L649, .L656
	.L656:
		...
		and.64      %r1340 <- %r1339, $1
		br          %r1340, .L649, .L648

Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
Signed-off-by: Christopher Li <sparse@chrisli.org>
2 files changed