RL78 bswaphi improvement

Message ID 000101d373ff$88935cd0$99ba1670$@renesas.com
State New
Headers show
Series
  • RL78 bswaphi improvement
Related show

Commit Message

Sebastian Perta Dec. 13, 2017, 10:45 a.m.
Hello,

The following patch helps GCC to generate xch instruction.

The patch is being useful in many test cases from c-torture, for example in
gcc.c-torture/execute/pr52760.c 
xch is being generated 4 times in foo and the code size for foo is being
reduced from 94 to 58 bytes.

Regression test is OK, tested with the following command:
make -k check-gcc RUNTESTFLAGS=--target_board=rl78-sim

Please let me know if this is OK, Thank you!
Sebastian

Patch

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 255581)
+++ ChangeLog	(working copy)
@@ -1,3 +1,9 @@ 
+2017-12-12  Sebastian Perta  <sebastian.perta@renesas.com>
+
+	* config/rl78/rl78-expand.md: New define_expand "bswaphi2"
+	* config/rl78/rl78-virt.md: New define_insn "*bswaphi2_virt"
+	* config/rl78/rl78-real.md: New define_insn "*bswaphi2_real"
+	
 2017-12-12  Richard Biener  <rguenther@suse.de>
 
 	PR tree-optimization/83385
Index: config/rl78/rl78-expand.md
===================================================================
--- config/rl78/rl78-expand.md	(revision 255581)
+++ config/rl78/rl78-expand.md	(working copy)
@@ -105,6 +105,14 @@ 
   [(set_attr "valloc" "op1")]
 )
 
+(define_expand "bswaphi2"
+  [(set (match_operand:HI           0 "nonimmediate_operand")
+        (bswap:HI (match_operand:HI 1 "general_operand")))]
+  ""
+  "if (rl78_force_nonfar_2 (operands, gen_bswaphi2))
+     DONE;"
+)
+
 ;;---------- Conversions ------------------------
 
 (define_expand "zero_extendqihi2"
Index: config/rl78/rl78-real.md
===================================================================
--- config/rl78/rl78-real.md	(revision 255581)
+++ config/rl78/rl78-real.md	(working copy)
@@ -90,6 +90,15 @@ 
    movw\t%0, %1"
 )
 
+(define_insn "*bswaphi2_real"
+  [(set (match_operand:HI           0 "rl78_nonfar_nonimm_operand" "=A,A")
+        (bswap:HI (match_operand:HI 1 "general_operand"  "0,viU")))]
+  "rl78_real_insns_ok ()"
+  "@
+   xch\ta, x
+   movw\tax, %1\n\txch\ta, x"
+)
+
 ;;---------- Conversions ------------------------
 
 (define_insn "*zero_extendqihi2_real"
Index: config/rl78/rl78-virt.md
===================================================================
--- config/rl78/rl78-virt.md	(revision 255581)
+++ config/rl78/rl78-virt.md	(working copy)
@@ -65,6 +65,14 @@ 
   [(set_attr "valloc" "op1")]
 )
 
+(define_insn "*bswaphi2_virt"
+  [(set (match_operand:HI           0 "rl78_nonfar_nonimm_operand" "=vm")
+        (bswap:HI (match_operand:HI 1 "general_operand"  "vim")))]
+  "rl78_virt_insns_ok ()"
+  "v.bswaphi\t%0, %1"
+  [(set_attr "valloc" "op1")]
+)
+
 ;;---------- Conversions ------------------------
 
 (define_insn "*zero_extendqihi2_virt"