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]

[PATCH ARM] PR 40327: Improve code for some thumb additions


This patch fixes PR 40327 for Thumb1 code on ARM.  It works by allowing
slightly more complex constants with the thumb1_addsi pattern and then
splitting these into a pair of adds.

Tested on an arm-eabi cross toolchain.

2009-06-13  Richard Earnshaw  <rearnsha@arm.com>

	PR target/40327
	* arm/constraints.md (Pa, Pb): New constraints.
	* arm/arm.md (thumb1_addsi3): Support more complex additions.  Add a 
	split pattern to deal with them.


*** gcc/config/arm/arm.md	(revision 148488)
--- gcc/config/arm/arm.md	(local)
*************** (define_insn_and_split "*arm_addsi3"
*** 640,649 ****
  ;; register.  Trying to reload it will always fail catastrophically,
  ;; so never allow those alternatives to match if reloading is needed.
  
! (define_insn "*thumb1_addsi3"
!   [(set (match_operand:SI          0 "register_operand" "=l,l,l,*rk,*hk,l,!k")
! 	(plus:SI (match_operand:SI 1 "register_operand" "%0,0,l,*0,*0,!k,!k")
! 		 (match_operand:SI 2 "nonmemory_operand" "I,J,lL,*hk,*rk,!M,!O")))]
    "TARGET_THUMB1"
    "*
     static const char * const asms[] = 
--- 640,649 ----
  ;; register.  Trying to reload it will always fail catastrophically,
  ;; so never allow those alternatives to match if reloading is needed.
  
! (define_insn_and_split "*thumb1_addsi3"
!   [(set (match_operand:SI          0 "register_operand" "=l,l,l,*rk,*hk,l,!k,l,l")
! 	(plus:SI (match_operand:SI 1 "register_operand" "%0,0,l,*0,*0,!k,!k,0,l")
! 		 (match_operand:SI 2 "nonmemory_operand" "I,J,lL,*hk,*rk,!M,!O,Pa,Pb")))]
    "TARGET_THUMB1"
    "*
     static const char * const asms[] = 
*************** (define_insn "*thumb1_addsi3"
*** 654,660 ****
       \"add\\t%0, %0, %2\",
       \"add\\t%0, %0, %2\",
       \"add\\t%0, %1, %2\",
!      \"add\\t%0, %1, %2\"
     };
     if ((which_alternative == 2 || which_alternative == 6)
         && GET_CODE (operands[2]) == CONST_INT
--- 654,662 ----
       \"add\\t%0, %0, %2\",
       \"add\\t%0, %0, %2\",
       \"add\\t%0, %1, %2\",
!      \"add\\t%0, %1, %2\",
!      \"#\",
!      \"#\"
     };
     if ((which_alternative == 2 || which_alternative == 6)
         && GET_CODE (operands[2]) == CONST_INT
*************** (define_insn "*thumb1_addsi3"
*** 662,668 ****
       return \"sub\\t%0, %1, #%n2\";
     return asms[which_alternative];
    "
!   [(set_attr "length" "2")]
  )
  
  ;; Reloading and elimination of the frame pointer can
--- 664,685 ----
       return \"sub\\t%0, %1, #%n2\";
     return asms[which_alternative];
    "
!   "&& reload_completed && CONST_INT_P (operands[2])
!    && operands[1] != stack_pointer_rtx
!    && (INTVAL (operands[2]) > 255 || INTVAL (operands[2]) < -255)"
!   [(set (match_dup 0) (plus:SI (match_dup 1) (match_dup 2)))
!    (set (match_dup 0) (plus:SI (match_dup 0) (match_dup 3)))]
!   {
!     HOST_WIDE_INT offset = INTVAL (operands[2]);
!     if (offset > 255)
!       offset = 255;
!     else if (offset < -255)
!       offset = -255;
!     
!     operands[3] = GEN_INT (offset);
!     operands[2] = GEN_INT (INTVAL (operands[2]) - offset);
!   }
!   [(set_attr "length" "2,2,2,2,2,2,2,4,4")]
  )
  
  ;; Reloading and elimination of the frame pointer can
*** gcc/config/arm/constraints.md	(revision 148488)
--- gcc/config/arm/constraints.md	(local)
***************
*** 30,35 ****
--- 30,36 ----
  
  ;; The following multi-letter normal constraints have been used:
  ;; in ARM/Thumb-2 state: Da, Db, Dc, Dn, Dl, DL, Dv
+ ;; in Thumb-1 state: Pa, Pb
  
  ;; The following memory constraints have been used:
  ;; in ARM/Thumb-2 state: Q, Ut, Uv, Uy, Un, Um, Us
*************** (define_constraint "O"
*** 129,134 ****
--- 130,147 ----
        (match_test "TARGET_THUMB1 && ival >= -508 && ival <= 508
  		   && ((ival & 3) == 0)")))
  
+ (define_constraint "Pa"
+   "@internal In Thumb-1 state a constant in the range -510 to +510"
+   (and (match_code "const_int")
+        (match_test "TARGET_THUMB1 && ival >= -510 && ival <= 510
+ 		    && (ival > 255 || ival < -255)")))
+ 
+ (define_constraint "Pb"
+   "@internal In Thumb-1 state a constant in the range -262 to +262"
+   (and (match_code "const_int")
+        (match_test "TARGET_THUMB1 && ival >= -262 && ival <= 262
+ 		    && (ival > 255 || ival < -255)")))
+ 
  (define_constraint "G"
   "In ARM/Thumb-2 state a valid FPA immediate constant."
   (and (match_code "const_double")

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