public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug rtl-optimization/108992] New: Regression: Branch direction canonicalization leads to pointless tail duplication / CSE/sinking by inverting branch
@ 2023-03-02 17:12 nok.raven at gmail dot com
  2023-03-02 19:23 ` [Bug rtl-optimization/108992] " pinskia at gcc dot gnu.org
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: nok.raven at gmail dot com @ 2023-03-02 17:12 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 108992
           Summary: Regression: Branch direction canonicalization leads to
                    pointless tail duplication / CSE/sinking by inverting
                    branch
           Product: gcc
           Version: 6.0
            Status: UNCONFIRMED
          Keywords: missed-optimization
          Severity: normal
          Priority: P3
         Component: rtl-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: nok.raven at gmail dot com
  Target Milestone: ---

There are two regressions, in GCC 7 and in GCC 8. If you invert branch manually
(replace 'cond' with '!cond') - the results were the same previously.

// Regressed since GCC 7: https://godbolt.org/z/h4brz7zG9
void use(int *);
void use2(int *);

void foo(bool cond, int * p)
{
    if (cond) {
        use(p);
    }
    use2(p);
}

// GCC 6
foo(bool, int*):
        test    dil, dil
        push    rbx
        mov     rbx, rsi
        je      .L2
        mov     rdi, rsi
        call    use(int*)
.L2:
        mov     rdi, rbx
        pop     rbx
        jmp     use2(int*)

// GCC 7
foo(bool, int*):
        test    dil, dil
        jne     .L8
        mov     rdi, rsi
        jmp     use2(int*)
.L8:
        sub     rsp, 24
        mov     rdi, rsi
        mov     QWORD PTR [rsp+8], rsi
        call    use2(int*)
        mov     rsi, QWORD PTR [rsp+8]
        add     rsp, 24
        mov     rdi, rsi
        jmp     use2(int*)


// Regressed since GCC 8: https://godbolt.org/z/MjxqTnbKa
void use(int *);
void use2(int *);

void foo(int * p, bool cond)
{
    if (cond) {
        use(p);
    }
    use2(p);
}

// GCC 7
foo(int*, bool):
        test    sil, sil
        push    rbx
        mov     rbx, rdi
        je      .L2
        call    use(int*)
.L2:
        mov     rdi, rbx
        pop     rbx
        jmp     use2(int*)

// GCC 8
foo(int*, bool):
        push    rbx
        mov     rbx, rdi
        test    sil, sil
        jne     .L5
        mov     rdi, rbx
        pop     rbx
        jmp     use2(int*)
.L5:
        call    use(int*)
        mov     rdi, rbx
        pop     rbx
        jmp     use2(int*)

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

end of thread, other threads:[~2023-03-02 23:39 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-02 17:12 [Bug rtl-optimization/108992] New: Regression: Branch direction canonicalization leads to pointless tail duplication / CSE/sinking by inverting branch nok.raven at gmail dot com
2023-03-02 19:23 ` [Bug rtl-optimization/108992] " pinskia at gcc dot gnu.org
2023-03-02 19:48 ` nok.raven at gmail dot com
2023-03-02 22:37 ` pinskia at gcc dot gnu.org
2023-03-02 22:46 ` [Bug middle-end/108992] " pinskia at gcc dot gnu.org
2023-03-02 22:54 ` pinskia at gcc dot gnu.org
2023-03-02 23:24 ` nok.raven at gmail dot com
2023-03-02 23:35 ` pinskia at gcc dot gnu.org
2023-03-02 23:39 ` 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).