public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug target/67675] New: [SH] Improve __builtin_strcmp alignment test
@ 2015-09-22  1:22 olegendo at gcc dot gnu.org
  2015-09-22  1:57 ` [Bug target/67675] " olegendo at gcc dot gnu.org
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: olegendo at gcc dot gnu.org @ 2015-09-22  1:22 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67675

            Bug ID: 67675
           Summary: [SH] Improve __builtin_strcmp alignment test
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: olegendo at gcc dot gnu.org
  Target Milestone: ---
            Target: sh*-*-*

If the alignments of both input pointers to __builtin_strcmp are not at least 4
bytes, code is emitted to do a run-time check:

int foo1 (const char* x, const char* y)
{
  return __builtin_strcmp (x, y);
}

_foo1:
        mov     r4,r0
        or      r5,r0      // OR pointers
        tst     #3,r0      // check if both are 4 byte aligned
        bf.s    .L9

If one of the pointers is 4 byte aligned, the OR can be omitted, because we
need to check only one pointer's alignement.  For example:

int foo2 (const char* x, const char* y)
{
  return __builtin_strcmp (__builtin_assume_aligned (x, 4), y);
}

or also:

struct S
{
  int a, b, c;
  char s[64];    // this array will be always 4 byte aligned.
};

int foo4 (struct S* x)
{
  return __builtin_strcmp (x->s, "1234");
}


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug target/67675] [SH] Improve __builtin_strcmp alignment test
  2015-09-22  1:22 [Bug target/67675] New: [SH] Improve __builtin_strcmp alignment test olegendo at gcc dot gnu.org
@ 2015-09-22  1:57 ` olegendo at gcc dot gnu.org
  2015-09-22  2:07 ` olegendo at gcc dot gnu.org
  2015-09-25 13:09 ` olegendo at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: olegendo at gcc dot gnu.org @ 2015-09-22  1:57 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67675

Oleg Endo <olegendo at gcc dot gnu.org> changed:

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

--- Comment #1 from Oleg Endo <olegendo at gcc dot gnu.org> ---
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);


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug target/67675] [SH] Improve __builtin_strcmp alignment test
  2015-09-22  1:22 [Bug target/67675] New: [SH] Improve __builtin_strcmp alignment test olegendo at gcc dot gnu.org
  2015-09-22  1:57 ` [Bug target/67675] " olegendo at gcc dot gnu.org
@ 2015-09-22  2:07 ` olegendo at gcc dot gnu.org
  2015-09-25 13:09 ` olegendo at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: olegendo at gcc dot gnu.org @ 2015-09-22  2:07 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67675

--- Comment #2 from Oleg Endo <olegendo at gcc dot gnu.org> ---
(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.


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug target/67675] [SH] Improve __builtin_strcmp alignment test
  2015-09-22  1:22 [Bug target/67675] New: [SH] Improve __builtin_strcmp alignment test olegendo at gcc dot gnu.org
  2015-09-22  1:57 ` [Bug target/67675] " olegendo at gcc dot gnu.org
  2015-09-22  2:07 ` olegendo at gcc dot gnu.org
@ 2015-09-25 13:09 ` olegendo at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: olegendo at gcc dot gnu.org @ 2015-09-25 13:09 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67675

--- Comment #3 from Oleg Endo <olegendo at gcc dot gnu.org> ---
Author: olegendo
Date: Fri Sep 25 13:09:04 2015
New Revision: 228118

URL: https://gcc.gnu.org/viewcvs?rev=228118&root=gcc&view=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


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2015-09-25 13:09 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-09-22  1:22 [Bug target/67675] New: [SH] Improve __builtin_strcmp alignment test olegendo at gcc dot gnu.org
2015-09-22  1:57 ` [Bug target/67675] " olegendo at gcc dot gnu.org
2015-09-22  2:07 ` olegendo at gcc dot gnu.org
2015-09-25 13:09 ` olegendo at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).