This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Off-by-one error in ARM's thumb_jump pattern


Hi Guys,

  We recently uncovered an off-by-one error in the code in the
  thumb_jump pattern to decide if a regular thumb branch instruction
  can be used or if a long-jump has to be used.  The constants used to
  check the range were slightly off, as demonstrated by the test
  program attached.  (Remember to compile it with -mthumb).

  I am proposing applying the patch below to fix this bug, and also to
  slightly extend the forward-branch range, since it was a little
  paranoid and the test file shows that a few bytes will work.

  Does anyone have any objections ?  (I would also be adding the test
  code to the gcc testsuite).

Cheers
        Nick

gcc/ChangeLog        
2004-03-29  Nick Clifton  <nickc@redhat.com>

	* config/arm/arm.md (thumb_jump): Reduce the backward branch
	range, and increase the forward branch range, to allow for
	the fact that the PC will be off by 4.

Index: config/arm/arm.md
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config/arm/arm.md,v
retrieving revision 1.162
diff -c -3 -p -r1.162 arm.md
*** config/arm/arm.md	24 Mar 2004 17:20:14 -0000	1.162
--- config/arm/arm.md	29 Mar 2004 17:05:04 -0000
***************
*** 7350,7357 ****
  	    (const_string "no")))
     (set (attr "length") 
          (if_then_else
! 	    (and (ge (minus (match_dup 0) (pc)) (const_int -2048))
! 		 (le (minus (match_dup 0) (pc)) (const_int 2044)))
    	    (const_int 2)
  	    (const_int 4)))]
  )
--- 7350,7357 ----
  	    (const_string "no")))
     (set (attr "length") 
          (if_then_else
! 	    (and (ge (minus (match_dup 0) (pc)) (const_int -2044))
! 		 (le (minus (match_dup 0) (pc)) (const_int 2048)))
    	    (const_int 2)
  	    (const_int 4)))]
  )


gcc/testsuite/ChangeLog        
2004-03-29  Nick Clifton  <nickc@redhat.com>

	* gcc.c-torture/compile/thumb_jump.c: New file to exercise the
	thumb_jump pattern in arm.md.

Attachment: thumb_jump.c
Description: Test file to exercise the thumb_jump pattern


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]