public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/112521] New: __float128 miscompilation: assignment as an aggregate field
@ 2023-11-13 21:15 andrew at ziglang dot org
  2023-11-13 21:27 ` [Bug middle-end/112521] " pinskia at gcc dot gnu.org
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: andrew at ziglang dot org @ 2023-11-13 21:15 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 112521
           Summary: __float128 miscompilation: assignment as an aggregate
                    field
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: andrew at ziglang dot org
  Target Milestone: ---

https://godbolt.org/z/3hfrTxvE3

typedef signed char i8;
typedef unsigned char u8;
typedef signed short int i16;
typedef unsigned short int u16;
typedef signed int i32;
typedef unsigned int u32;
typedef signed long int isize;
typedef unsigned long int usize;
typedef signed long long int i64;
typedef unsigned long long int u64;
typedef signed __int128 i128;
typedef unsigned __int128 u128;

typedef _Float16 f16;
typedef float f32;
typedef double f64;
typedef long double f80;
typedef __float128 f128;

extern void *memcpy(void *restrict, void const *restrict, usize);

struct Storage {
  union {
    f16 flt16;
    f32 flt32;
    f64 flt64;
    f80 flt80;
    f128 flt128;
  } flt;
  enum {
    flt16,
    flt32,
    flt64,
    flt80,
    flt128,
  } tag;
};

struct Storage readFromMemory(const u8 *buffer, u32 bits);
[[gnu::noinline]] struct Storage readFromMemory(const u8 *buffer, u32 bits) {
  struct Storage storage1, storage2;
  switch (bits) {
  case 16: {
    f16 flt;
    memcpy(&flt, buffer, 2);
    storage1.flt.flt16 = flt;
    storage1.tag = flt16;
    storage2 = storage1;
    break;
  }
  case 32: {
    f32 flt;
    memcpy(&flt, buffer, 4);
    storage1.flt.flt32 = flt;
    storage1.tag = flt32;
    storage2 = storage1;
    break;
  }
  case 64: {
    f64 flt;
    memcpy(&flt, buffer, 8);
    storage1.flt.flt64 = flt;
    storage1.tag = flt64;
    storage2 = storage1;
    break;
  }
  case 80: {
    f80 flt;
    memcpy(&flt, buffer, 10);
    storage1.flt.flt80 = flt;
    storage1.tag = flt80;
    storage2 = storage1;
    break;
  }
  case 128: {
    f128 flt;
    memcpy(&flt, buffer, 16);
    storage1.flt.flt128 = flt;
    storage1.tag = flt128;
    storage2 = storage1;
    break;
  }
  default:
    __builtin_unreachable();
  }
  return storage2;
}

extern int printf(const char *restrict format, ...);

int main() {
    u8 buffer[16] =
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0x3F};
    struct Storage storage = readFromMemory(buffer, 128);
    u64 repr[2];
    memcpy(repr, &storage.flt.flt128, 16);
    printf("0x%016llX%016llX\n", repr[1], repr[0]);
}


compile with gcc -O1. it prints 0x00000000004000000000000000000000 however the
correct answer is 0x3FFF0000000000000000000000000000 which is what clang
prints.

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

* [Bug middle-end/112521] __float128 miscompilation: assignment as an aggregate field
  2023-11-13 21:15 [Bug c/112521] New: __float128 miscompilation: assignment as an aggregate field andrew at ziglang dot org
@ 2023-11-13 21:27 ` pinskia at gcc dot gnu.org
  2023-11-13 22:00 ` pinskia at gcc dot gnu.org
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-11-13 21:27 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
          Component|c                           |middle-end
           Keywords|                            |alias

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
I suspect there is a dup of this one.

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

* [Bug middle-end/112521] __float128 miscompilation: assignment as an aggregate field
  2023-11-13 21:15 [Bug c/112521] New: __float128 miscompilation: assignment as an aggregate field andrew at ziglang dot org
  2023-11-13 21:27 ` [Bug middle-end/112521] " pinskia at gcc dot gnu.org
@ 2023-11-13 22:00 ` pinskia at gcc dot gnu.org
  2023-11-13 22:03 ` [Bug tree-optimization/112521] [11/12/13/14 Regression] " pinskia at gcc dot gnu.org
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-11-13 22:00 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Created attachment 56577
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=56577&action=edit
Testcase that is compatiable going back to at least GCC 6

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

* [Bug tree-optimization/112521] [11/12/13/14 Regression] __float128 miscompilation: assignment as an aggregate field
  2023-11-13 21:15 [Bug c/112521] New: __float128 miscompilation: assignment as an aggregate field andrew at ziglang dot org
  2023-11-13 21:27 ` [Bug middle-end/112521] " pinskia at gcc dot gnu.org
  2023-11-13 22:00 ` pinskia at gcc dot gnu.org
@ 2023-11-13 22:03 ` pinskia at gcc dot gnu.org
  2023-11-13 22:04 ` pinskia at gcc dot gnu.org
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-11-13 22:03 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|alias                       |wrong-code
             Target|                            |x86_64-linux-gnu
   Target Milestone|---                         |11.5
            Summary|__float128 miscompilation:  |[11/12/13/14 Regression]
                   |assignment as an aggregate  |__float128 miscompilation:
                   |field                       |assignment as an aggregate
                   |                            |field
      Known to work|                            |6.4.0, 7.5.0
      Known to fail|                            |8.1.0
          Component|middle-end                  |tree-optimization

--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
The problem is SRA related.

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

* [Bug tree-optimization/112521] [11/12/13/14 Regression] __float128 miscompilation: assignment as an aggregate field
  2023-11-13 21:15 [Bug c/112521] New: __float128 miscompilation: assignment as an aggregate field andrew at ziglang dot org
                   ` (2 preceding siblings ...)
  2023-11-13 22:03 ` [Bug tree-optimization/112521] [11/12/13/14 Regression] " pinskia at gcc dot gnu.org
@ 2023-11-13 22:04 ` pinskia at gcc dot gnu.org
  2023-11-13 22:06 ` pinskia at gcc dot gnu.org
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-11-13 22:04 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |needs-bisection
   Last reconfirmed|                            |2023-11-13
     Ever confirmed|0                           |1
             Status|UNCONFIRMED                 |NEW

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

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

* [Bug tree-optimization/112521] [11/12/13/14 Regression] __float128 miscompilation: assignment as an aggregate field
  2023-11-13 21:15 [Bug c/112521] New: __float128 miscompilation: assignment as an aggregate field andrew at ziglang dot org
                   ` (3 preceding siblings ...)
  2023-11-13 22:04 ` pinskia at gcc dot gnu.org
@ 2023-11-13 22:06 ` pinskia at gcc dot gnu.org
  2023-11-13 22:16 ` pinskia at gcc dot gnu.org
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-11-13 22:06 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Depends on|                            |93271

--- Comment #5 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Most likely a dup of bug 93271 even though GCC 7 works for this testcase but
that bug fails for GCC 6.


Referenced Bugs:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93271
[Bug 93271] [11/12/13/14 regression] SRA producing wrong code on denormals

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

* [Bug tree-optimization/112521] [11/12/13/14 Regression] __float128 miscompilation: assignment as an aggregate field
  2023-11-13 21:15 [Bug c/112521] New: __float128 miscompilation: assignment as an aggregate field andrew at ziglang dot org
                   ` (4 preceding siblings ...)
  2023-11-13 22:06 ` pinskia at gcc dot gnu.org
@ 2023-11-13 22:16 ` pinskia at gcc dot gnu.org
  2023-11-13 22:16 ` andrew at ziglang dot org
  2023-11-13 22:26 ` pinskia at gcc dot gnu.org
  7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-11-13 22:16 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |DUPLICATE
             Status|NEW                         |RESOLVED

--- Comment #6 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Yes this is a dup in the end, basically SRA is messing up by using a float
(long double) type here when float types load/stores do change the values
sometimes due to denormals, padding bits/bytes and others.

*** This bug has been marked as a duplicate of bug 93271 ***

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

* [Bug tree-optimization/112521] [11/12/13/14 Regression] __float128 miscompilation: assignment as an aggregate field
  2023-11-13 21:15 [Bug c/112521] New: __float128 miscompilation: assignment as an aggregate field andrew at ziglang dot org
                   ` (5 preceding siblings ...)
  2023-11-13 22:16 ` pinskia at gcc dot gnu.org
@ 2023-11-13 22:16 ` andrew at ziglang dot org
  2023-11-13 22:26 ` pinskia at gcc dot gnu.org
  7 siblings, 0 replies; 9+ messages in thread
From: andrew at ziglang dot org @ 2023-11-13 22:16 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #7 from Andrew Kelley <andrew at ziglang dot org> ---
Thank you for looking into it!

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

* [Bug tree-optimization/112521] [11/12/13/14 Regression] __float128 miscompilation: assignment as an aggregate field
  2023-11-13 21:15 [Bug c/112521] New: __float128 miscompilation: assignment as an aggregate field andrew at ziglang dot org
                   ` (6 preceding siblings ...)
  2023-11-13 22:16 ` andrew at ziglang dot org
@ 2023-11-13 22:26 ` pinskia at gcc dot gnu.org
  7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-11-13 22:26 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #8 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to Andrew Kelley from comment #7)
> Thank you for looking into it!

By the way the workaround is to use -fno-tree-sra to disable SRA. But that
might cause other missed optimizations.

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

end of thread, other threads:[~2023-11-13 22:26 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-11-13 21:15 [Bug c/112521] New: __float128 miscompilation: assignment as an aggregate field andrew at ziglang dot org
2023-11-13 21:27 ` [Bug middle-end/112521] " pinskia at gcc dot gnu.org
2023-11-13 22:00 ` pinskia at gcc dot gnu.org
2023-11-13 22:03 ` [Bug tree-optimization/112521] [11/12/13/14 Regression] " pinskia at gcc dot gnu.org
2023-11-13 22:04 ` pinskia at gcc dot gnu.org
2023-11-13 22:06 ` pinskia at gcc dot gnu.org
2023-11-13 22:16 ` pinskia at gcc dot gnu.org
2023-11-13 22:16 ` andrew at ziglang dot org
2023-11-13 22:26 ` 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).