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]

Re: [PATCH, ARM] Work around out-of-range branch error for Thumb-2


On Fri, 27 Nov 2009 17:05:31 +0000
Richard Earnshaw <rearnsha@arm.com> wrote:

> On Fri, 2009-11-27 at 16:58 +0000, Julian Brown wrote:
> >     gcc/
> >     * config/arm/thumb2.md (thumb2_addsi_short): Change length to 4.
> 
> This seems wrong to me; and it's just papering over a bug elsewhere.
> Why is regrename not verifying the constraints properly?

Probably because the constraints are too permissive (as Andrew Pinski
pointed out).

This version splits the constraints into two parts, corresponding to
the two different short-add-immediate instructions. I've added new
constraints to cover the represented immediates exactly too, just to be
safe ("Ps" for 8-bit immediates for addition or subtraction, "Pt"
similar for 3-bit immediates), since such constraints weren't available
in Thumb-2 mode.

I've verified that this patch still fixes the original test case, and
re-tested with a cross-compiler to ARM EABI. OK now?

Julian

ChangeLog

    * gcc/config/arm/constraints.md (Ps, Pt): New constraint letters.
    (*thumb2_addsi_short): Tighten constraints.
commit 0365c5ae611e9c3a9401c09dffb36c4f4f020752
Author: Julian Brown <julian@henry1.codesourcery.com>
Date:   Fri Dec 4 11:02:14 2009 -0800

    Fix thumb2_addsi_short length

diff --git a/gcc/config/arm/constraints.md b/gcc/config/arm/constraints.md
index c40d695..cb75558 100644
--- a/gcc/config/arm/constraints.md
+++ b/gcc/config/arm/constraints.md
@@ -31,6 +31,7 @@
 ;; The following multi-letter normal constraints have been used:
 ;; in ARM/Thumb-2 state: Da, Db, Dc, Dn, Dl, DL, Dv, Dy
 ;; in Thumb-1 state: Pa, Pb
+;; in Thumb-2 state: Ps, Pt
 
 ;; The following memory constraints have been used:
 ;; in ARM/Thumb-2 state: Q, Ut, Uv, Uy, Un, Um, Us
@@ -147,6 +148,16 @@
        (match_test "TARGET_THUMB1 && ival >= -262 && ival <= 262
 		    && (ival > 255 || ival < -255)")))
 
+(define_constraint "Ps"
+  "@internal In Thumb-2 state a constant in the range -255 to +255"
+  (and (match_code "const_int")
+       (match_test "TARGET_THUMB2 && ival >= -255 && ival <= 255")))
+
+(define_constraint "Pt"
+  "@internal In Thumb-2 state a constant in the range -7 to +7"
+  (and (match_code "const_int")
+       (match_test "TARGET_THUMB2 && ival >= -7 && ival <= 7")))
+
 (define_constraint "G"
  "In ARM/Thumb-2 state a valid FPA immediate constant."
  (and (match_code "const_double")
diff --git a/gcc/config/arm/thumb2.md b/gcc/config/arm/thumb2.md
index 82f75f9..bcd9bed 100644
--- a/gcc/config/arm/thumb2.md
+++ b/gcc/config/arm/thumb2.md
@@ -1197,9 +1197,9 @@
 )
 
 (define_insn "*thumb2_addsi_short"
-  [(set (match_operand:SI 0 "low_register_operand" "=l")
-	(plus:SI (match_operand:SI 1 "low_register_operand" "l")
-		 (match_operand:SI 2 "low_reg_or_int_operand" "lIL")))
+  [(set (match_operand:SI 0 "low_register_operand" "=l,l")
+	(plus:SI (match_operand:SI 1 "low_register_operand" "l,0")
+		 (match_operand:SI 2 "low_reg_or_int_operand" "lPt,Ps")))
    (clobber (reg:CC CC_REGNUM))]
   "TARGET_THUMB2 && reload_completed"
   "*
@@ -1217,7 +1217,7 @@
       return \"add%!\\t%0, %1, %2\";
   "
   [(set_attr "predicable" "yes")
-   (set_attr "length" "2")]
+   (set_attr "length" "2,2")]
 )
 
 (define_insn "divsi3"

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