[PATCH] Correctly determine implicit sets in postreload

Richard Earnshaw rearnsha@gcc.gnu.org
Fri Aug 20 10:38:00 GMT 2004


This bug was uncovered while trying to get gcc to bootstrap targeting
the Thumb instruction set on ARM.

The Thumb compiler has a condjump instruction of the form

(define_insn "cbranchsi4_scratch"
  [(set (pc) (if_then_else
	      (match_operator 4 "arm_comparison_operator"
	       [(match_operand:SI 1 "s_register_operand" "l,0")
	        (match_operand:SI 2 "thumb_cmpneg_operand" "L,J")])
	      (label_ref (match_operand 3 "" ""))
	      (pc)))
   (clobber (match_scratch:SI 0 "=l,l"))]

which can be used to compare and branch using some constants that aren't
available for the normal cmp instruction (which doesn't take negative
values).

However, this pattern matches onlyjump_p because it has exactly one set
of the PC.

We've been using onlyjump_p in reload_cse_move2add to determine if we
could extract an implicit set from a jump instruction, but we were
missing the fact that the clobber might alter the value we had.

The patch below fixes this by removing onlyjump_p from the guarding
condition, but then verifying that the register in the comparison isn't
modified elsewhere in the pattern.

An added benefit of this change is that we can now extract an implicit
set from condjumps with real side-effects, such as

(parallel [(set (pc) (if_then_else
			(ne (reg X) (const_int 0))
			(label)
			(pc)))
	   (set (reg Y) (reg X))])

which copies X into Y and branches if the result was non-zero (so we
know X is zero if the branch wasn't taken).

Bootstrapped on arm-netbsd targeting the Thumb instruction set.

2004-08-20  Richard Earnshaw  <rearnsha@arm.com>

	* postreload.c (reload_cse_move2add): Allow any condjump, but check
	that the implicit set isn't clobbered in the jump insn.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: pr-impset.patch
Type: text/x-patch
Size: 1339 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20040820/2397adc1/attachment.bin>


More information about the Gcc-patches mailing list