public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug target/102793] New: AArch64: sequential comparisons with equal conditional blocks don't use ccmp
@ 2021-10-15 21:07 christophm30 at gmail dot com
  2021-10-15 21:10 ` [Bug tree-optimization/102793] " pinskia at gcc dot gnu.org
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: christophm30 at gmail dot com @ 2021-10-15 21:07 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 102793
           Summary: AArch64: sequential comparisons with equal conditional
                    blocks don't use ccmp
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: christophm30 at gmail dot com
  Target Milestone: ---

The following code:

int ccmp(uint64_t* s1, uint64_t* s2, int(*foo)(void))
{
    uint64_t d1, d2, bar;

    d1 = *s1++;
    d2 = *s2++;
    bar = (d1 ^ d2) & 0xabcd;
    if (bar == 0 || d1 != d2)
      return foo();
    return 0;
}

int noccmp(uint64_t* s1, uint64_t* s2, int(*foo)(void))
{
    uint64_t d1, d2, bar;

    d1 = *s1++;
    d2 = *s2++;
    bar = (d1 ^ d2) & 0xabcd;
    if (bar == 0)
      return foo();
    if (d1 != d2)
      return foo();
    return 0;
}

...produces (GCC master or earlier, ARM64, with -O3):

ccmp:
        ldr     x3, [x0]
        mov     x4, 43981
        ldr     x0, [x1]
        eor     x1, x3, x0
        tst     x1, x4
        ccmp    x3, x0, 0, ne
        bne     .L5
        mov     w0, 0
        ret
.L5:
        mov     x16, x2
        br      x16
noccmp:
        ldr     x3, [x0]
        mov     x4, 43981
        ldr     x0, [x1]
        eor     x1, x3, x0
        tst     x1, x4
        beq     .L8
        cmp     x3, x0
        beq     .L9
.L8:
        mov     x16, x2
        br      x16
.L9:
        mov     w0, 0
        ret

Since both conditional blocks do exactly the same (they call foo()), both
functions could use the ccmp instruction.
I just observed this and have not analysed this any further.

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

end of thread, other threads:[~2024-04-05 12:41 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-15 21:07 [Bug target/102793] New: AArch64: sequential comparisons with equal conditional blocks don't use ccmp christophm30 at gmail dot com
2021-10-15 21:10 ` [Bug tree-optimization/102793] " pinskia at gcc dot gnu.org
2021-10-15 21:19 ` pinskia at gcc dot gnu.org
2021-10-18  6:35 ` rguenth at gcc dot gnu.org
2021-10-18  6:43 ` pinskia at gcc dot gnu.org
2023-08-26  7:27 ` pinskia at gcc dot gnu.org
2024-04-05 12:35 ` manolis.tsamis at vrull dot eu
2024-04-05 12:41 ` manolis.tsamis at vrull dot eu

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).