public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/110067] New: [14 Regression] Wrong code on pixman-0.42.2
@ 2023-05-31 22:42 slyfox at gcc dot gnu.org
  2023-05-31 22:46 ` [Bug tree-optimization/110067] " pinskia at gcc dot gnu.org
                   ` (12 more replies)
  0 siblings, 13 replies; 14+ messages in thread
From: slyfox at gcc dot gnu.org @ 2023-05-31 22:42 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 110067
           Summary: [14 Regression] Wrong code on pixman-0.42.2
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: slyfox at gcc dot gnu.org
  Target Milestone: ---

This week's gcc r14-1423-gfefa7db2c31fee started failing pixman-0.42.2 test
suite:

pixman> FAIL: scaling-crash-test
pixman> FAIL: cover-test
pixman> FAIL: affine-test
pixman> FAIL: filter-reduction-test
pixman> FAIL: scaling-test

I think it's a gcc bug.

Extracted example from scaling-test:

// $ cat bug.c
#include <stdint.h>
#include <stdio.h>

#define BILINEAR_INTERPOLATION_BITS 7

#define force_inline __inline__ __attribute__ ((__always_inline__))

__attribute__((noipa))
static void
fetch_pixel_no_alpha_32_bug (void *out)
{
    uint32_t *ret = out;

    *ret = 0xff499baf;
}


static force_inline uint32_t
bilinear_interpolation_local (uint32_t tl, uint32_t tr,
                        uint32_t bl, uint32_t br,
                        int distx, int disty)
{
    uint64_t distxy, distxiy, distixy, distixiy;
    uint64_t tl64, tr64, bl64, br64;
    uint64_t f, r;

    distx <<= (8 - BILINEAR_INTERPOLATION_BITS);
    disty <<= (8 - BILINEAR_INTERPOLATION_BITS);

    distxy = distx * disty;
    distxiy = distx * (256 - disty);
    distixy = (256 - distx) * disty;
    distixiy = (256 - distx) * (256 - disty);

    /* Alpha and Blue */
    tl64 = tl & 0xff0000ff;
    tr64 = tr & 0xff0000ff;
    bl64 = bl & 0xff0000ff;
    br64 = br & 0xff0000ff;

    f = tl64 * distixiy + tr64 * distxiy + bl64 * distixy + br64 * distxy;
    r = f & 0x0000ff0000ff0000ull;

    /* Red and Green */
    tl64 = tl;
    tl64 = ((tl64 << 16) & 0x000000ff00000000ull) | (tl64 & 0x0000ff00ull);

    tr64 = tr;
    tr64 = ((tr64 << 16) & 0x000000ff00000000ull) | (tr64 & 0x0000ff00ull);

    bl64 = bl;
    bl64 = ((bl64 << 16) & 0x000000ff00000000ull) | (bl64 & 0x0000ff00ull);

    br64 = br;
    br64 = ((br64 << 16) & 0x000000ff00000000ull) | (br64 & 0x0000ff00ull);

    f = tl64 * distixiy + tr64 * distxiy + bl64 * distixy + br64 * distxy;
    r |= ((f >> 16) & 0x000000ff00000000ull) | (f & 0xff000000ull);

    return (uint32_t)(r >> 16);
}

__attribute__((noipa))
static void
bits_image_fetch_pixel_bilinear_32_bug (void *out)
{
    uint32_t br;
    uint32_t *ret = out;

    fetch_pixel_no_alpha_32_bug (&br);

    *ret = bilinear_interpolation_local (0, 0, 0, br, 0x41, 0x42);
}

int main() {
    uint32_t r;
    bits_image_fetch_pixel_bilinear_32_bug (&r);
    printf("r=%08x\n", r);
}

Triggering:

  $ gcc-14 -O2 -fno-strict-aliasing bug.c -o bug14 && ./bug14
  r=4200282d

  $ gcc-13 -O2 -fno-strict-aliasing bug.c -o bug13 && ./bug13
  r=4213282d

Note that returned values are not identical.

$ gcc-14 -v |& unnix
Using built-in specs.
COLLECT_GCC=/<<NIX>>/gcc-14.0.0/bin/gcc
COLLECT_LTO_WRAPPER=/<<NIX>>/gcc-14.0.0/libexec/gcc/x86_64-unknown-linux-gnu/14.0.0/lto-wrapper
Target: x86_64-unknown-linux-gnu
Configured with:
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 14.0.0 99999999 (experimental) (GCC)

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

end of thread, other threads:[~2023-06-05  1:01 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-05-31 22:42 [Bug tree-optimization/110067] New: [14 Regression] Wrong code on pixman-0.42.2 slyfox at gcc dot gnu.org
2023-05-31 22:46 ` [Bug tree-optimization/110067] " pinskia at gcc dot gnu.org
2023-05-31 23:28 ` slyfox at gcc dot gnu.org
2023-06-01  1:42 ` crazylht at gmail dot com
2023-06-01  1:55 ` crazylht at gmail dot com
2023-06-01  1:55 ` crazylht at gmail dot com
2023-06-01  9:46 ` slyfox at gcc dot gnu.org
2023-06-02  7:38 ` rguenth at gcc dot gnu.org
2023-06-02  7:55 ` crazylht at gmail dot com
2023-06-03  0:09 ` cvs-commit at gcc dot gnu.org
2023-06-03  0:10 ` crazylht at gmail dot com
2023-06-03  7:33 ` slyfox at gcc dot gnu.org
2023-06-04  5:08 ` sjames at gcc dot gnu.org
2023-06-05  1:01 ` crazylht at gmail dot com

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