diff mbox

[RFC] RL78 - Add predicates to reduce code bloat when accessing volatile memory.

Message ID 535179B5.6010607@yahoo.com
State New
Headers show

Commit Message

Richard Hulme April 18, 2014, 7:15 p.m. UTC
Hi,

This patch adds predicates (taken and renamed from the MSP430 backend) 
to allow more efficient code generation when accessing volatile memory 
turning this (for example):

movw	r10, #240
movw	ax, r10
movw	hl, ax
mov	a, [hl]
or	a, #32
mov	[hl], a

into this:

mov	a, !240
or	a, #32
mov	!240, a

Regards,

Richard.

2014-04-18  Richard Hulme  <peper03@yahoo.com>

     * config/rl78/predicates.md (rl78_volatile_memory_operand): New
       (rl78_general_operand): New
       (rl78_nonimmediate_operand): New
       (rl78_any_operand): Now includes volatile memory
       (rl78_nonfar_operand): Likewise
       (rl78_nonfar_nonimm_operand): Likewise

---
  gcc/config/rl78/predicates.md |   26 +++++++++++++++++++++++---
  1 file changed, 23 insertions(+), 3 deletions(-)
diff mbox

Patch

diff --git a/gcc/config/rl78/predicates.md b/gcc/config/rl78/predicates.md
index e564f43..29e3922 100644
--- a/gcc/config/rl78/predicates.md
+++ b/gcc/config/rl78/predicates.md
@@ -18,18 +18,38 @@ 
  ;; along with GCC; see the file COPYING3.  If not see
  ;; <http://www.gnu.org/licenses/>.
  
-(define_predicate "rl78_any_operand"
+(define_predicate "rl78_volatile_memory_operand"
+  (and (match_code "mem")
+       (match_test ("memory_address_addr_space_p (GET_MODE (op), XEXP 
(op, 0), MEM_ADDR_SPACE (op))")))
+)
+
+; TRUE for any valid general operand.  We do this because
+; general_operand refuses to match volatile memory refs.
+
+(define_predicate "rl78_general_operand"
    (ior (match_operand 0 "general_operand")
+       (match_operand 0 "rl78_volatile_memory_operand"))
+)
+
+; Likewise for nonimmediate_operand.
+
+(define_predicate "rl78_nonimmediate_operand"
+  (ior (match_operand 0 "nonimmediate_operand")
+       (match_operand 0 "rl78_volatile_memory_operand"))
+)
+
+(define_predicate "rl78_any_operand"
+  (ior (match_operand 0 "rl78_general_operand")
         (match_code "mem,const_int,const_double,reg"))
  )

  (define_predicate "rl78_nonfar_operand"
-  (and (match_operand 0 "general_operand")
+  (and (match_operand 0 "rl78_general_operand")
         (not (match_test "rl78_far_p (op)")))
  )

  (define_predicate "rl78_nonfar_nonimm_operand"
-  (and (match_operand 0 "nonimmediate_operand")
+  (and (match_operand 0 "rl78_nonimmediate_operand")
         (not (match_test "rl78_far_p (op)")))
  )