public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "slyfox at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug target/115161] [15 Regression] highway-1.0.7 miscompilation of some SSE2 intrinsics
Date: Thu, 23 May 2024 10:39:22 +0000	[thread overview]
Message-ID: <bug-115161-4-Xmsr8UYWPl@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-115161-4@http.gcc.gnu.org/bugzilla/>

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

--- Comment #21 from Sergei Trofimovich <slyfox at gcc dot gnu.org> ---
Shrunk the example down to a single simpler function while preserving the
original masking intent:

```c
cat bug.cc
#include <stdint.h>
#include <string.h>
#include <emmintrin.h>

__attribute__((noipa))
static void assert_eq_p(void * l, void * r) {
    char lb[16];
    char rb[16];

    __builtin_memcpy(lb, l, 16);
    __builtin_memcpy(rb, r, 16);

    if (__builtin_memcmp(lb, rb, 16) != 0) __builtin_trap();
}

__attribute__((noipa))
static void assert_eq(__m128i l, __m128i r) { assert_eq_p(&l, &r); }

int main() {
  const __m128i su = _mm_set1_epi32(0x4f800000);
  const __m128  sf = _mm_castsi128_ps(su);

  const __m128  overflow_mask_f32 = _mm_cmpge_ps(sf,
_mm_set1_ps(2147483648.0f));
  const __m128i overflow_mask = _mm_castps_si128(overflow_mask_f32);

  const __m128i conv = _mm_cvttps_epi32(sf); // overflows
  const __m128i yes = _mm_set1_epi32(INT32_MAX);

  const __m128i a = _mm_and_si128(overflow_mask, yes);
  const __m128i na = _mm_andnot_si128(overflow_mask, conv);

  const __m128i conv_masked = _mm_or_si128(a, na);

  const __m128i actual = _mm_cmpeq_epi32(conv_masked,
_mm_set1_epi32(INT32_MAX));
  const __m128i expected = _mm_set1_epi32(-1);

  assert_eq(expected, actual);
}
```

The discrepancy:

Ok:
    $ /tmp/gb/gcc/xg++ -Wall -B/tmp/gb/gcc bug.cc -o bug -O0 && ./bug
Bad:
    $ /tmp/gb/gcc/xg++ -Wall -B/tmp/gb/gcc bug.cc -o bug -O2 && ./bug
    Illegal instruction (core dumped)

  parent reply	other threads:[~2024-05-23 10:39 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-20 10:07 [Bug target/115161] New: " slyfox at gcc dot gnu.org
2024-05-20 11:26 ` [Bug target/115161] " slyfox at gcc dot gnu.org
2024-05-20 14:48 ` roger at nextmovesoftware dot com
2024-05-20 22:08 ` slyfox at gcc dot gnu.org
2024-05-21  6:41 ` rguenth at gcc dot gnu.org
2024-05-21 14:53 ` jakub at gcc dot gnu.org
2024-05-21 15:02 ` jakub at gcc dot gnu.org
2024-05-21 15:13 ` jakub at gcc dot gnu.org
2024-05-21 15:40 ` amonakov at gcc dot gnu.org
2024-05-21 15:50 ` slyfox at gcc dot gnu.org
2024-05-21 15:51 ` jakub at gcc dot gnu.org
2024-05-21 16:07 ` jakub at gcc dot gnu.org
2024-05-22  1:06 ` liuhongt at gcc dot gnu.org
2024-05-22  1:13 ` pinskia at gcc dot gnu.org
2024-05-22  7:27 ` jakub at gcc dot gnu.org
2024-05-22  7:41 ` slyfox at gcc dot gnu.org
2024-05-22  7:43 ` slyfox at gcc dot gnu.org
2024-05-22  7:52 ` liuhongt at gcc dot gnu.org
2024-05-22  8:03 ` jakub at gcc dot gnu.org
2024-05-22  8:22 ` amonakov at gcc dot gnu.org
2024-05-22  8:26 ` jakub at gcc dot gnu.org
2024-05-22  8:49 ` amonakov at gcc dot gnu.org
2024-05-23 10:39 ` slyfox at gcc dot gnu.org [this message]
2024-05-24 22:00 ` slyfox at gcc dot gnu.org
2024-05-25 17:15 ` amonakov at gcc dot gnu.org
2024-05-25 18:44 ` slyfox at gcc dot gnu.org
2024-05-27  0:47 ` [Bug target/115161] highway-1.0.7 miscompilation of _mm_cvttps_epi32(): invalid result assumed liuhongt at gcc dot gnu.org
2024-06-05  4:09 ` cvs-commit at gcc dot gnu.org
2024-06-05  9:13 ` slyfox at gcc dot gnu.org
2024-06-17  8:17 ` cvs-commit at gcc dot gnu.org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-115161-4-Xmsr8UYWPl@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).