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]

RFC/RFA: Xstormy16 bit branches range checking


Hi Geoff,

  A customer of ours recently encountered a problem with an old (gcc
  3.4 based) version of the xstormy16 port.  He found that the
  compiler could generate the bit-test-and-branch instructions (BN or
  BP) with a destination label that was too far away (not within a +/-
  12 bit displacement).

  I produced a patch for them, but when I ran their test case through
  the current compiler the problem did not arise.  I think that this
  was because gcc was choosing different code generation strategies
  however, rather than the compiler knowing about the restricted
  displacements in these instructions, so I am submitting the adapted
  patch for your consideration.  The problem is that I do not have a
  way to demonstrate the problem (other than looking at the
  stormy16.md file) nor to demonstrate that my patch fixes it
  properly.  What do you think ?

Cheers
  Nick

gcc/ChangeLog
2006-10-24  Nick Clifton  <nickc@redhat.com>

	* config/stormy16/stormy16.md (bclrx): Do not assume that the
	destination of the branch is in range.  Check, and use a longer
	form if necessary.
	*bclrx2, bclrx3, bclr7, bclr15, bsetx, bsetx2, bset7, bset15):
	Likewise.

Index: gcc/config/stormy16/stormy16.md
===================================================================
--- gcc/config/stormy16/stormy16.md	(revision 118007)
+++ gcc/config/stormy16/stormy16.md	(working copy)
@@ -1249,9 +1249,23 @@
 		      (pc)))
    (clobber (match_operand:BI 3 "" "=y"))]
   ""
-  "bn %1,%B2,%l0"
-  [(set_attr "length" "4")
-   (set_attr "psw_operand" "nop")])
+  "*
+  switch (get_attr_length (insn))
+  {
+  case 4: return \"bn %1,%B2,%l0\";
+  case 8: return \"bp %1,%B2,. + 8 | jmpf %l0\";
+  default: abort ();
+  }
+  "
+  [(set_attr "psw_operand" "nop")
+   (set (attr "length")
+	(if_then_else
+	   (and (ge (minus (match_dup 0) (pc)) (const_int -2048))
+		(le (minus (match_dup 0) (pc)) (const_int 2047)))
+	   (const_int 4)
+	   (const_int 8)))
+  ]
+)
 
 (define_insn "*bclrx2"
   [(set (pc) 
@@ -1265,9 +1279,23 @@
 		      (pc)))
    (clobber (match_operand:BI 4 "" "=y"))]
   ""
-  "bn %1,%B2,%l0"
-  [(set_attr "length" "4")
-   (set_attr "psw_operand" "nop")])
+  "*
+  switch (get_attr_length (insn))
+  {
+  case 4: return \"bn %1,%B2,%l0\";
+  case 8: return \"bp %1,%B2,. + 8 | jmpf %l0\";
+  default: abort ();
+  }
+  "
+  [(set_attr "psw_operand" "nop")
+   (set (attr "length")
+	(if_then_else
+	   (and (ge (minus (match_dup 0) (pc)) (const_int -2048))
+		(le (minus (match_dup 0) (pc)) (const_int 2047)))
+	   (const_int 4)
+	   (const_int 8)))
+  ]
+)
 
 (define_insn "*bclrx3"
   [(set (pc) 
@@ -1278,9 +1306,23 @@
 		      (pc)))
    (clobber (match_operand:BI 3 "" "=y"))]
   ""
-  "bn %1,%B2,%l0"
-  [(set_attr "length" "4")
-   (set_attr "psw_operand" "nop")])
+  "*
+  switch (get_attr_length (insn))
+  {
+  case 4: return \"bn %1,%B2,%l0\";
+  case 8: return \"bp %1,%B2,. + 8 | jmpf %l0\";
+  default: abort ();
+  }
+  "
+  [(set_attr "psw_operand" "nop")
+   (set (attr "length")
+	(if_then_else
+	   (and (ge (minus (match_dup 0) (pc)) (const_int -2048))
+		(le (minus (match_dup 0) (pc)) (const_int 2047)))
+	   (const_int 4)
+	   (const_int 8)))
+  ]
+)
 
 (define_insn "*bclr7"
   [(set (pc) 
@@ -1292,9 +1334,23 @@
 		      (pc)))
    (clobber (match_operand:BI 2 "" "=y"))]
   ""
-  "bn %1,#7,%l0"
-  [(set_attr "length" "4")
-   (set_attr "psw_operand" "nop")])
+  "*
+  switch (get_attr_length (insn))
+  {
+  case 4: return \"bn %1,#7,%l0\";
+  case 8: return \"bp %1,#7,. + 8 | jmpf %l0\";
+  default: abort ();
+  }
+  "
+  [(set_attr "psw_operand" "nop")
+   (set (attr "length")
+	(if_then_else
+	   (and (ge (minus (match_dup 0) (pc)) (const_int -2048))
+		(le (minus (match_dup 0) (pc)) (const_int 2047)))
+	   (const_int 4)
+	   (const_int 8)))
+  ]
+)
 
 (define_insn "*bclr15"
   [(set (pc) 
@@ -1304,9 +1360,23 @@
 		      (pc)))
    (clobber (match_operand:BI 2 "" "=y"))]
   ""
-  "bn %1,#7,%l0"
-  [(set_attr "length" "4")
-   (set_attr "psw_operand" "nop")])
+  "*
+  switch (get_attr_length (insn))
+  {
+  case 4: return \"bn %1,#7,%l0\";
+  case 8: return \"bp %1,#7,. + 8 | jmpf %l0\";
+  default: abort ();
+  }
+  "
+  [(set_attr "psw_operand" "nop")
+   (set (attr "length")
+	(if_then_else
+	   (and (ge (minus (match_dup 0) (pc)) (const_int -2048))
+		(le (minus (match_dup 0) (pc)) (const_int 2047)))
+	   (const_int 4)
+	   (const_int 8)))
+  ]
+)
 
 (define_insn "*bsetx"
   [(set (pc) 
@@ -1317,9 +1387,23 @@
 		      (pc)))
    (clobber (match_operand:BI 3 "" "=y"))]
   ""
-  "bp %1,%B2,%l0"
-  [(set_attr "length" "4")
-   (set_attr "psw_operand" "nop")])
+  "*
+  switch (get_attr_length (insn))
+  {
+  case 4: return \"bp %1,%B2,%l0\";
+  case 8: return \"bn %1,%B2,. + 8 | jmpf %l0\";
+  default: abort ();
+  }
+  "
+  [(set_attr "psw_operand" "nop")
+   (set (attr "length")
+	(if_then_else
+	   (and (ge (minus (match_dup 0) (pc)) (const_int -2048))
+		(le (minus (match_dup 0) (pc)) (const_int 2047)))
+	   (const_int 4)
+	   (const_int 8)))
+  ]
+)
 
 (define_insn "*bsetx2"
   [(set (pc) 
@@ -1330,9 +1414,23 @@
 		      (pc)))
    (clobber (match_operand:BI 3 "" "=y"))]
   ""
-  "bp %1,%b2,%l0"
-  [(set_attr "length" "4")
-   (set_attr "psw_operand" "nop")])
+  "*
+  switch (get_attr_length (insn))
+  {
+  case 4: return \"bp %1,%b2,%l0\";
+  case 8: return \"bn %1,%b2,. + 8 | jmpf %l0\";
+  default: abort ();
+  }
+  "
+  [(set_attr "psw_operand" "nop")
+   (set (attr "length")
+	(if_then_else
+	   (and (ge (minus (match_dup 0) (pc)) (const_int -2048))
+		(le (minus (match_dup 0) (pc)) (const_int 2047)))
+	   (const_int 4)
+	   (const_int 8)))
+  ]
+)
 
 (define_insn "*bsetx3"
   [(set (pc) 
@@ -1343,9 +1441,23 @@
 		      (pc)))
    (clobber (match_operand:BI 3 "" "=y"))]
   ""
-  "bp %1,%B2,%l0"
-  [(set_attr "length" "4")
-   (set_attr "psw_operand" "nop")])
+  "*
+  switch (get_attr_length (insn))
+  {
+  case 4: return \"bp %1,%B2,%l0\";
+  case 8: return \"bn %1,%B2,. + 8 | jmpf %l0\";
+  default: abort ();
+  }
+  "
+  [(set_attr "psw_operand" "nop")
+   (set (attr "length")
+	(if_then_else
+	   (and (ge (minus (match_dup 0) (pc)) (const_int -2048))
+		(le (minus (match_dup 0) (pc)) (const_int 2047)))
+	   (const_int 4)
+	   (const_int 8)))
+  ]
+)
 
 (define_insn "*bset7"
   [(set (pc) 
@@ -1355,9 +1467,23 @@
 		      (pc)))
    (clobber (match_operand:BI 2 "" "=y"))]
   ""
-  "bp %1,#7,%l0"
-  [(set_attr "length" "4")
-   (set_attr "psw_operand" "nop")])
+  "*
+  switch (get_attr_length (insn))
+  {
+  case 4: return \"bp %1,#7,%l0\";
+  case 8: return \"bn %1,#7,. + 8 | jmpf %l0\";
+  default: abort ();
+  }
+  "
+  [(set_attr "psw_operand" "nop")
+   (set (attr "length")
+	(if_then_else
+	   (and (ge (minus (match_dup 0) (pc)) (const_int -2048))
+		(le (minus (match_dup 0) (pc)) (const_int 2047)))
+	   (const_int 4)
+	   (const_int 8)))
+  ]
+)
 
 (define_insn "*bset15"
   [(set (pc) 
@@ -1367,6 +1493,20 @@
 		      (pc)))
    (clobber (match_operand:BI 2 "" "=y"))]
   ""
-  "bp %1,#7,%l0"
-  [(set_attr "length" "4")
-   (set_attr "psw_operand" "nop")])
+  "*
+  switch (get_attr_length (insn))
+  {
+  case 4: return \"bp %1,#7,%l0\";
+  case 8: return \"bn %1,#7,. + 8 | jmpf %l0\";
+  default: abort ();
+  }
+  "
+  [(set_attr "psw_operand" "nop")
+   (set (attr "length")
+	(if_then_else
+	   (and (ge (minus (match_dup 0) (pc)) (const_int -2048))
+		(le (minus (match_dup 0) (pc)) (const_int 2047)))
+	   (const_int 4)
+	   (const_int 8)))
+  ]
+)

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