public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/64622] New: convoluted loop codegen for __strcspn_c1
@ 2015-01-16  1:57 hubicka at gcc dot gnu.org
  2015-01-16  3:25 ` [Bug tree-optimization/64622] " pinskia at gcc dot gnu.org
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: hubicka at gcc dot gnu.org @ 2015-01-16  1:57 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 64622
           Summary: convoluted loop codegen for __strcspn_c1
           Product: gcc
           Version: 5.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: hubicka at gcc dot gnu.org

Compiling
extern __inline long                                                          
__strcspn_c1 (__const char *__s, int __reject)                                  
{                                                                               
  register long __result = 0;                                                 
  while (__s[__result] != '\0' && __s[__result] != __reject)                    
    ++__result;                                                                 
  return __result;                                                              
}                                                                               

With -O2 gives:
__strcspn_c1:
.LFB0:
        .cfi_startproc
        movsbl  (%rdi), %eax
        testb   %al, %al
        je      .L4
        cmpl    %eax, %esi
        movl    $0, %eax
        jne     .L3
        jmp     .L2
        .p2align 4,,10
        .p2align 3
.L12:
        cmpl    %esi, %edx
        je      .L11
.L3:
        addq    $1, %rax
        movsbl  (%rdi,%rax), %edx
        testb   %dl, %dl
        jne     .L12
.L2:
        rep ret
        .p2align 4,,10
        .p2align 3
.L11:
        rep ret
.L4:
        xorl    %eax, %eax
        ret


Whilie clang produces:
__strcspn_c1:                           # @__strcspn_c1
        .cfi_startproc
# BB#0:
        movq    $-1, %rax
        .align  16, 0x90
.LBB0_1:                                # =>This Inner Loop Header: Depth=1
        movsbl  1(%rdi,%rax), %ecx
        incq    %rax
        testl   %ecx, %ecx
        je      .LBB0_3
# BB#2:                                 #   in Loop: Header=BB0_1 Depth=1
        cmpl    %esi, %ecx
        jne     .LBB0_1
.LBB0_3:                                # %.critedge
        retq


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

* [Bug tree-optimization/64622] convoluted loop codegen for __strcspn_c1
  2015-01-16  1:57 [Bug tree-optimization/64622] New: convoluted loop codegen for __strcspn_c1 hubicka at gcc dot gnu.org
@ 2015-01-16  3:25 ` pinskia at gcc dot gnu.org
  2015-01-16  9:10 ` rguenth at gcc dot gnu.org
  2022-12-12 20:22 ` pinskia at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu.org @ 2015-01-16  3:25 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |missed-optimization

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
This is what LLVM translates it to:
long
__strcspn_c1 (__const char *__s, int __reject)
{
  register long __result = -1;
  do {
    ++__result;
  }  while (__s[__result] != '\0' && __s[__result] != __reject);
  return __result;
}

I wonder how they do it though in a reasonable way.


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

* [Bug tree-optimization/64622] convoluted loop codegen for __strcspn_c1
  2015-01-16  1:57 [Bug tree-optimization/64622] New: convoluted loop codegen for __strcspn_c1 hubicka at gcc dot gnu.org
  2015-01-16  3:25 ` [Bug tree-optimization/64622] " pinskia at gcc dot gnu.org
@ 2015-01-16  9:10 ` rguenth at gcc dot gnu.org
  2022-12-12 20:22 ` pinskia at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: rguenth at gcc dot gnu.org @ 2015-01-16  9:10 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Richard Biener <rguenth at gcc dot gnu.org> ---
without loop header copyign we generate

__strcspn_c1:
.LFB0:
        .cfi_startproc
        xorl    %eax, %eax
        jmp     .L2
        .p2align 4,,10
        .p2align 3
.L8:
        cmpl    %esi, %edx
        je      .L6
        addq    $1, %rax
.L2:
        movsbl  (%rdi,%rax), %edx
        testb   %dl, %dl
        jne     .L8
.L6:
        rep ret

so it would be interesting to investigate how they do this (if it's a special
hack or some systematic fix).  The loop header contains just the IV increment
here.


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

* [Bug tree-optimization/64622] convoluted loop codegen for __strcspn_c1
  2015-01-16  1:57 [Bug tree-optimization/64622] New: convoluted loop codegen for __strcspn_c1 hubicka at gcc dot gnu.org
  2015-01-16  3:25 ` [Bug tree-optimization/64622] " pinskia at gcc dot gnu.org
  2015-01-16  9:10 ` rguenth at gcc dot gnu.org
@ 2022-12-12 20:22 ` pinskia at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-12-12 20:22 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
           Severity|normal                      |enhancement
   Last reconfirmed|                            |2022-12-12
     Ever confirmed|0                           |1

--- Comment #4 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Confirmed.

I wonder if they see the body has no side effects except on the IV trans form
the IV to start one before ...

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

end of thread, other threads:[~2022-12-12 20:22 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-01-16  1:57 [Bug tree-optimization/64622] New: convoluted loop codegen for __strcspn_c1 hubicka at gcc dot gnu.org
2015-01-16  3:25 ` [Bug tree-optimization/64622] " pinskia at gcc dot gnu.org
2015-01-16  9:10 ` rguenth at gcc dot gnu.org
2022-12-12 20:22 ` pinskia 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).