problem in jump.c

Herman ten Brugge
Thu Nov 5 17:07:00 GMT 1998


I discovered a bug in jump.c. The if/then/else transformations is not
working anymore because the patch Jim Wilson made was a bit over
productive. The patch checked with the aid off modified_between_p
if a register was modified. The result of this call was allways '1'
because the 'pc' was included in the insn passed to modified_between_p.
The insn passed is something like: (c4x example)

(jump_insn 94 93 96 (set (pc)
        (if_then_else (ge (reg:CC 21 st)
                (const_int 0))
            (label_ref 99)
            (pc))) 198 {*b} (nil)

The actual test should only test the if/then/else part of the insn:

(ge (reg:CC 21 st)
    (const_int 0))

I contacted Jim Wilson and he agreed that he only wanted to test the
registers in the if/then/else part.
It is save to use 'XEXP (SET_SRC (PATTERN (temp)), 0)' in the patch below
because we checked that temp is a condjump_p before we arive here.
The previous patch disabled code like:

	x = a > b ? a : b;

Normally this would result in an if/then/else. This will be rewritten by
jump into:

	if (...) x = a; else x = b;  ---> x = b; if (...) x = a;

After this a conditional load can be performed and all jumps are gone.
This is a big win on a c4x and other platforms that have conditional
loads. The patch below enables this transformation again.


Wed Nov  4 16:24:51 1998 Herman A.J. ten Brugge <>

	* jump.c (jump_optimize): In if/then/else transformations. Only check
	registers in if/then/else part when calling modified_between_p.

---	Wed Nov  4 16:11:06 1998
+++ jump.c	Wed Nov  4 16:38:40 1998
@@ -860,7 +860,8 @@ jump_optimize (f, cross_jump, noop_moves
 		      || ! modified_between_p (SET_SRC (temp4), p, temp2))
 		  /* Verify that registers used by the jump are not clobbered
 		     by the instruction being moved.  */
-		  && ! modified_between_p (PATTERN (temp), temp2,
+		  && ! modified_between_p (XEXP (SET_SRC (PATTERN (temp)), 0),
+					   temp2,
 					   NEXT_INSN (temp2)))
 		  emit_insn_after_with_line_notes (PATTERN (temp2), p, temp2);

Herman ten Brugge			Email:

More information about the Gcc-bugs mailing list