Patchwork RL78 - minor size optimization

login
register
mail settings
Submitter Richard Hulme
Date March 27, 2014, 9:33 p.m.
Message ID <5334991A.4090609@yahoo.com>
Download mbox | patch
Permalink /patch/334469/
State New
Headers show

Comments

Richard Hulme - March 27, 2014, 9:33 p.m.
Hi,

This patch is a small optimization for the RL78 target that uses the 
'clrb' instruction where possible when performing a zero-extend instead 
of 'mov'ing a literal #0.  This saves a byte on each operation.

Regards,

Richard

2014-03-27  Richard Hulme  <peper03@yahoo.com>

	* config/rl78/rl78-real.md (zero_extendqihi2_real):
	Minor optimization to use clrb instruction where possible,
	which is 1 byte shorter than 'mov'ing #0.

---
  gcc/config/rl78/rl78-real.md |    7 ++++---
  1 file changed, 4 insertions(+), 3 deletions(-)

  (define_insn "*extendqihi2_real"
DJ Delorie - March 27, 2014, 11:20 p.m.
This is OK after 4.9 branches (i.e. stage1).  I suspect we could add
AX to the first alternative, although I don't know if it will get
used.  We could add HL to the second alternative to complete the
replacement of the 'r' constraint.

Patch

diff --git a/gcc/config/rl78/rl78-real.md b/gcc/config/rl78/rl78-real.md
index 27ff60f..3503a02 100644
--- a/gcc/config/rl78/rl78-real.md
+++ b/gcc/config/rl78/rl78-real.md
@@ -77,12 +77,13 @@ 
  ;;---------- Conversions ------------------------

  (define_insn "*zero_extendqihi2_real"
-  [(set (match_operand:HI                 0 "nonimmediate_operand" "=rv,A")
-       (zero_extend:HI (match_operand:QI 1 "general_operand" "0,a")))]
+  [(set (match_operand:HI                 0 "nonimmediate_operand" 
"=Bv,DT,A")
+       (zero_extend:HI (match_operand:QI 1 "general_operand" "0,0,a")))]
    "rl78_real_insns_ok ()"
    "@
+   clrb\t%Q0
     mov\t%Q0, #0
-   mov\tx, a \;mov\ta, #0"
+   mov\tx, a \;clrb\ta"
    )