[PATCH][PR target/19201] Peephole to improve clearing items in structure for m68k
authorKazu Kirata <kazu@gcc.gnu.org>
Sun, 13 Dec 2015 13:06:12 +0000 (06:06 -0700)
committerJeff Law <law@gcc.gnu.org>
Sun, 13 Dec 2015 13:06:12 +0000 (06:06 -0700)
[PATCH][PR target/19201] Peephole to improve clearing items in structure for m68k
* config/m68k/m68k.md (load feeding clear byte): New peephole2.

* gcc.target/m68k/pr19201.c: New test.

From-SVN: r231597

gcc/ChangeLog
gcc/config/m68k/m68k.md
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.target/m68k/pr19201.c [new file with mode: 0644]

index eee44a7cdda871e7651a0099a6e6fb327c963fdd..730c79f118f764bb19b524ef1f00d49051845016 100644 (file)
@@ -1,3 +1,7 @@
+2015-12-13  Kazu Kirata  <kazu@gcc.gnu.org>
+
+       * config/m68k/m68k.md (load feeding clear byte): New peephole2.
+
 2015-12-13  Tom de Vries  <tom@codesourcery.com>
 
        * tree-ssa-structalias.c (find_func_clobbers): Handle sizes and kinds
index 1eaf58fc334a4e90f6adcf26857b7bf2a40d008f..444515aea682d149bd84eadad3a1a089a1186b39 100644 (file)
 
 (include "cf.md")
 (include "sync.md")
+
+;; Convert
+;;
+;;     move.l 4(%a0),%a0
+;;     clr.b (%a0,%a1.l)
+;;
+;; into
+;;
+;;     add.l 4(%a0),%a1
+;;     clr.b (%a1)
+;;
+;; The latter is smaller.  It is faster on all models except m68060.
+
+(define_peephole2
+  [(set (match_operand:SI 0 "register_operand" "")
+       (mem:SI (plus:SI (match_operand:SI 1 "register_operand" "")
+                        (match_operand:SI 2 "const_int_operand" ""))))
+   (set (mem:QI (plus:SI (match_operand:SI 3 "register_operand" "")
+                        (match_operand:SI 4 "register_operand" "")))
+       (const_int 0))]
+  "(optimize_size || !TUNE_68060)
+   && (operands[0] == operands[3] || operands[0] == operands[4])
+   && ADDRESS_REG_P (operands[1])
+   && ADDRESS_REG_P ((operands[0] == operands[3]) ? operands[4] : operands[3])
+   && peep2_reg_dead_p (2, operands[3])
+   && peep2_reg_dead_p (2, operands[4])"
+  [(set (match_dup 5)
+       (plus:SI (match_dup 5)
+                (mem:SI (plus:SI (match_dup 1)
+                                 (match_dup 2)))))
+   (set (mem:QI (match_dup 5))
+       (const_int 0))]
+  "operands[5] = (operands[0] == operands[3]) ? operands[4] : operands[3];")
index 38d1dbea8d13b4daeee14546bd8313eebe3a0f86..3f0862e3abe8e5bc9d1ca14c069e11502efc46d9 100644 (file)
@@ -1,5 +1,7 @@
 2015-12-13  Jeff Law  <law@redhat.com>
 
+       * gcc.target/m68k/pr19201.c: New test.
+
        * gcc.target/m68k/pr63347.c: Remove #include <stdlib> add -w to
        command line options.
        * gcc.target/m68k/20090709-1.c: Adjust expected output.
diff --git a/gcc/testsuite/gcc.target/m68k/pr19201.c b/gcc/testsuite/gcc.target/m68k/pr19201.c
new file mode 100644 (file)
index 0000000..dd81857
--- /dev/null
@@ -0,0 +1,13 @@
+/* { dg-options "-w -O2 -fomit-frame-pointer" } */
+/* { dg-final { scan-assembler-not "%a.,%\[ad\]..l" } } */
+
+struct X { 
+  char *a; 
+  /* other members */ 
+  int b; 
+}; 
+void f (struct X *x) 
+{ 
+  x->a[x->b] = 0; 
+}