[Bug target/67675] [SH] Improve __builtin_strcmp alignment test

2015-09-25 Thread olegendo at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67675

Oleg Endo  changed:

   What|Removed |Added

 Status|NEW |RESOLVED
 Resolution|--- |FIXED

--- Comment #4 from Oleg Endo  ---
Fixed on trunk.


[Bug target/67675] [SH] Improve __builtin_strcmp alignment test

2015-09-25 Thread olegendo at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67675

--- Comment #3 from Oleg Endo  ---
Author: olegendo
Date: Fri Sep 25 13:09:04 2015
New Revision: 228118

URL: https://gcc.gnu.org/viewcvs?rev=228118=gcc=rev
Log:
gcc/
PR target/67675
* config/sh/sh-mem.cc (sh_expand_cmpstr): Check alignment of addr1 and
addr2 individually.  Don't emit logical or insn if one is known to
be aligned approriately.
(sh_expand_cmpnstr): Likewise.

gcc/testsuite/
PR target/67675
* gcc.target/sh/pr67675.c: New.

Added:
trunk/gcc/testsuite/gcc.target/sh/pr67675.c
Modified:
trunk/gcc/ChangeLog
trunk/gcc/config/sh/sh-mem.cc
trunk/gcc/testsuite/ChangeLog


[Bug target/67675] [SH] Improve __builtin_strcmp alignment test

2015-09-21 Thread olegendo at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67675

Oleg Endo  changed:

   What|Removed |Added

 Status|UNCONFIRMED |NEW
   Last reconfirmed||2015-09-22
 Ever confirmed|0   |1

--- Comment #1 from Oleg Endo  ---
This fixes it:

Index: gcc/config/sh/sh-mem.cc
===
--- gcc/config/sh/sh-mem.cc (revision 227970)
+++ gcc/config/sh/sh-mem.cc (working copy)
@@ -224,11 +224,10 @@
   rtx_code_label *L_loop_long = gen_label_rtx ();
   rtx_code_label *L_end_loop_long = gen_label_rtx ();

-  int align = INTVAL (operands[3]);
+  const unsigned int addr1_alignment = MEM_ALIGN (operands[1]) /
BITS_PER_UNIT;
+  const unsigned int addr2_alignment = MEM_ALIGN (operands[2]) /
BITS_PER_UNIT;

-  emit_move_insn (tmp0, const0_rtx);
-
-  if (align < 4)
+  if (addr1_alignment < 4 && addr2_alignment < 4)
 {
   emit_insn (gen_iorsi3 (tmp1, s1_addr, s2_addr));
   emit_insn (gen_tstsi_t (tmp1, GEN_INT (3)));
@@ -235,6 +234,18 @@
   jump = emit_jump_insn (gen_branch_false (L_loop_byte));
   add_int_reg_note (jump, REG_BR_PROB, prob_likely);
 }
+  else if (addr1_alignment < 4 && addr2_alignment >= 4)
+{
+  emit_insn (gen_tstsi_t (s1_addr, GEN_INT (3)));
+  jump = emit_jump_insn (gen_branch_false (L_loop_byte));
+  add_int_reg_note (jump, REG_BR_PROB, prob_likely);
+}
+  else if (addr1_alignment >= 4 && addr2_alignment < 4)
+{
+  emit_insn (gen_tstsi_t (s2_addr, GEN_INT (3)));
+  jump = emit_jump_insn (gen_branch_false (L_loop_byte));
+  add_int_reg_note (jump, REG_BR_PROB, prob_likely);
+}

   addr1 = adjust_automodify_address (addr1, SImode, s1_addr, 0);
   addr2 = adjust_automodify_address (addr2, SImode, s2_addr, 0);


[Bug target/67675] [SH] Improve __builtin_strcmp alignment test

2015-09-21 Thread olegendo at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67675

--- Comment #2 from Oleg Endo  ---
(In reply to Oleg Endo from comment #0)
> struct S
> {
>   int a, b, c;
>   char s[64];// this array will be always 4 byte aligned.
> };

Currently this doesn't work, see PR 67676.