public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH, AVR ] Fix PR19154 Bit Test patch
@ 2009-09-28  1:39 Andy H
  2009-10-17  3:39 ` PING " Andy H
  2009-10-18 12:16 ` Anatoly Sokolov
  0 siblings, 2 replies; 3+ messages in thread
From: Andy H @ 2009-09-28  1:39 UTC (permalink / raw)
  To: gcc-patches, Anatoly Sokolov, Weddington, Eric

[-- Attachment #1: Type: text/plain, Size: 1340 bytes --]

The attached patch creates a full set of patterns to match common bit 
test and jump for AVR target.

These are typically creted by expressions such as

if (x & 0x4000) ...

The expanded can be  picked up by combine pass and turned into single 
sbxx instructions.
The existing patterns failed to match due to limited coverage of modes 
producing sub-optimal code.

Zero extract patterns are provide for all modes up to DI. Similar AND 
patterns are provided upto SI mode
The latter are used by older peephole patterns and historically matched 
to some RTL for bit test.

Tested with no regressions on todays HEAD  rev 152226

Ok to comit to 4.5 HEAD?


Target is avr-unknown-none
Host   is i686-pc-linux-gnu

        === gcc Summary ===

# of expected passes        49145
# of unexpected failures    167
# of unexpected successes    12
# of expected failures        99
# of unresolved testcases    39
# of untested testcases        8
# of unsupported tests        1806

(SAME BEFORE AFTER PATCH)

2009-09-27  Andy Hutchinson <hutchinsonandy@gcc.gnu.org>

    PR mid/19154
    * avr.md (QIDI): Add new mode iterator.
    (sbrx_branch<mode>): Create new zero extract bit, test and jump
    patterns for all QI thru DI modes combinations.
    (sbrx_and_branch<mode>): Create new and based bit test and jump
    patterns for QI thru SI modes.


[-- Attachment #2: bittest.patch --]
[-- Type: text/plain, Size: 3881 bytes --]

Index: avr.c
===================================================================
--- avr.c	(revision 152217)
+++ avr.c	(working copy)
@@ -5890,12 +5890,12 @@
   return 1;
 }
 
-/* Output a branch that tests a single bit of a register (QI, HI or SImode)
+/* Output a branch that tests a single bit of a register (QI, HI, SI or DImode)
    or memory location in the I/O space (QImode only).
 
    Operand 0: comparison operator (must be EQ or NE, compare bit to zero).
    Operand 1: register operand to test, or CONST_INT memory address.
-   Operand 2: bit number (for QImode operand) or mask (HImode, SImode).
+   Operand 2: bit number.
    Operand 3: label to jump to if the test is true.  */
 
 const char *
@@ -5943,9 +5943,7 @@
       else  /* HImode or SImode */
 	{
 	  static char buf[] = "sbrc %A1,0";
-	  int bit_nr = exact_log2 (INTVAL (operands[2])
-				   & GET_MODE_MASK (GET_MODE (operands[1])));
-
+	  int bit_nr = INTVAL (operands[2]);
 	  buf[3] = (comp == EQ) ? 's' : 'c';
 	  buf[6] = 'A' + (bit_nr >> 3);
 	  buf[9] = '0' + (bit_nr & 7);
Index: avr.md
===================================================================
--- avr.md	(revision 152217)
+++ avr.md	(working copy)
@@ -118,6 +118,7 @@
 
 ;; Define mode iterator
 (define_mode_iterator QISI [(QI "") (HI "") (SI "")])
+(define_mode_iterator QIDI [(QI "") (HI "") (SI "") (DI "")])
 
 ;;========================================================================
 ;; The following is used by nonlocal_goto and setjmp.
@@ -2448,12 +2449,15 @@
 
 
 ;; Test a single bit in a QI/HI/SImode register.
-(define_insn "*sbrx_branch"
+;; Combine will create zero extract patterns for single bit tests.
+;; permit any mode in source pattern by using VOIDmode.
+
+(define_insn "*sbrx_branch<mode>"
   [(set (pc)
         (if_then_else
 	 (match_operator 0 "eqne_operator"
-			 [(zero_extract:HI
-			   (match_operand:QI 1 "register_operand" "r")
+			 [(zero_extract:QIDI
+			   (match_operand:VOID 1 "register_operand" "r")
 			   (const_int 1)
 			   (match_operand 2 "const_int_operand" "n"))
 			  (const_int 0)])
@@ -2470,39 +2474,27 @@
 				    (const_int 4))))
    (set_attr "cc" "clobber")])
 
-(define_insn "*sbrx_and_branchhi"
-  [(set (pc)
-        (if_then_else
-	 (match_operator 0 "eqne_operator"
-			 [(and:HI
-			   (match_operand:HI 1 "register_operand" "r")
-			   (match_operand:HI 2 "single_one_operand" "n"))
-			  (const_int 0)])
-	 (label_ref (match_operand 3 "" ""))
-	 (pc)))]
-  ""
-  "* return avr_out_sbxx_branch (insn, operands);"
-  [(set (attr "length")
-	(if_then_else (and (ge (minus (pc) (match_dup 3)) (const_int -2046))
-			   (le (minus (pc) (match_dup 3)) (const_int 2046)))
-		      (const_int 2)
-		      (if_then_else (eq_attr "mcu_mega" "no")
-				    (const_int 2)
-				    (const_int 4))))
-   (set_attr "cc" "clobber")])
+;; Same test based on Bitwise AND RTL. Keep this incase gcc changes patterns.
+;; or for old peepholes.
+;; Fixme - bitwise Mask will not work for DImode
 
-(define_insn "*sbrx_and_branchsi"
+(define_insn "*sbrx_and_branch<mode>"
   [(set (pc)
         (if_then_else
 	 (match_operator 0 "eqne_operator"
-			 [(and:SI
-			   (match_operand:SI 1 "register_operand" "r")
-			   (match_operand:SI 2 "single_one_operand" "n"))
+			 [(and:QISI
+			   (match_operand:QISI 1 "register_operand" "r")
+			   (match_operand:QISI 2 "single_one_operand" "n"))
 			  (const_int 0)])
 	 (label_ref (match_operand 3 "" ""))
 	 (pc)))]
   ""
-  "* return avr_out_sbxx_branch (insn, operands);"
+{
+    HOST_WIDE_INT bitnumber;
+    bitnumber = exact_log2 (GET_MODE_MASK (<MODE>mode) & INTVAL (operands[2]));
+    operands[2] = GEN_INT (bitnumber);
+    return avr_out_sbxx_branch (insn, operands);
+}
   [(set (attr "length")
 	(if_then_else (and (ge (minus (pc) (match_dup 3)) (const_int -2046))
 			   (le (minus (pc) (match_dup 3)) (const_int 2046)))

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: PING  [PATCH, AVR ] Fix PR19154 Bit Test patch
  2009-09-28  1:39 [PATCH, AVR ] Fix PR19154 Bit Test patch Andy H
@ 2009-10-17  3:39 ` Andy H
  2009-10-18 12:16 ` Anatoly Sokolov
  1 sibling, 0 replies; 3+ messages in thread
From: Andy H @ 2009-10-17  3:39 UTC (permalink / raw)
  To: gcc-patches, Anatoly Sokolov, Weddington, Eric

Anatoly,

could you  post your  approval of this patch

Andy


Andy H wrote:
> The attached patch creates a full set of patterns to match common bit 
> test and jump for AVR target.
>
> These are typically creted by expressions such as
>
> if (x & 0x4000) ...
>
> The expanded can be  picked up by combine pass and turned into single 
> sbxx instructions.
> The existing patterns failed to match due to limited coverage of modes 
> producing sub-optimal code.
>
> Zero extract patterns are provide for all modes up to DI. Similar AND 
> patterns are provided upto SI mode
> The latter are used by older peephole patterns and historically 
> matched to some RTL for bit test.
>
> Tested with no regressions on todays HEAD  rev 152226
>
> Ok to comit to 4.5 HEAD?
>
>
> Target is avr-unknown-none
> Host   is i686-pc-linux-gnu
>
>        === gcc Summary ===
>
> # of expected passes        49145
> # of unexpected failures    167
> # of unexpected successes    12
> # of expected failures        99
> # of unresolved testcases    39
> # of untested testcases        8
> # of unsupported tests        1806
>
> (SAME BEFORE AFTER PATCH)
>
> 2009-09-27  Andy Hutchinson <hutchinsonandy@gcc.gnu.org>
>
>    PR mid/19154
>    * avr.md (QIDI): Add new mode iterator.
>    (sbrx_branch<mode>): Create new zero extract bit, test and jump
>    patterns for all QI thru DI modes combinations.
>    (sbrx_and_branch<mode>): Create new and based bit test and jump
>    patterns for QI thru SI modes.
>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH, AVR ] Fix PR19154 Bit Test patch
  2009-09-28  1:39 [PATCH, AVR ] Fix PR19154 Bit Test patch Andy H
  2009-10-17  3:39 ` PING " Andy H
@ 2009-10-18 12:16 ` Anatoly Sokolov
  1 sibling, 0 replies; 3+ messages in thread
From: Anatoly Sokolov @ 2009-10-18 12:16 UTC (permalink / raw)
  To: Andy H, gcc-patches, Weddington, Eric

Hello.

> 
>    PR mid/19154
>    * avr.md (QIDI): Add new mode iterator.
>    (sbrx_branch<mode>): Create new zero extract bit, test and jump
>    patterns for all QI thru DI modes combinations.
>    (sbrx_and_branch<mode>): Create new and based bit test and jump
>    patterns for QI thru SI modes.
> 


Ok.

Anatoly.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2009-10-18 11:58 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-09-28  1:39 [PATCH, AVR ] Fix PR19154 Bit Test patch Andy H
2009-10-17  3:39 ` PING " Andy H
2009-10-18 12:16 ` Anatoly Sokolov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).