public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jakub Jelinek <jakub@redhat.com>
To: Uros Bizjak <ubizjak@gmail.com>, Hongtao Liu <crazylht@gmail.com>
Cc: gcc-patches@gcc.gnu.org
Subject: [PATCH] i386: Fix a pasto in ix86_expand_int_sse_cmp [PR114339]
Date: Fri, 15 Mar 2024 09:50:02 +0100	[thread overview]
Message-ID: <ZfQLuno+PsZ2WsNh@tucnak> (raw)

Hi!

In r13-3803-gfa271afb58 I've added an optimization for LE/LEU/GE/GEU
comparison against CONST_VECTOR.  As the comments say:
         /* x <= cst can be handled as x < cst + 1 unless there is
            wrap around in cst + 1.  */
...
                     /* For LE punt if some element is signed maximum.  */
...
                 /* For LEU punt if some element is unsigned maximum.  */
and
         /* x >= cst can be handled as x > cst - 1 unless there is
            wrap around in cst - 1.  */
...
                     /* For GE punt if some element is signed minimum.  */
...
                 /* For GEU punt if some element is zero.  */
Apparently I wrote the GE/GEU (second case) first and then
copied/adjusted it for LE/LEU, most of the adjustments look correct, but
I've left if (code == GE) comparison when testing if it should punt for
signed maximum.  That condition is never true, because this is in
switch (code) { ... case LE: case LEU: block and we really meant to
be what the comment says, for LE punt if some element is signed maximum,
as then cst + 1 wraps around.

The following patch fixes the pasto.

Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

2024-03-15  Jakub Jelinek  <jakub@redhat.com>

	PR target/114339
	* config/i386/i386-expand.cc (ix86_expand_int_sse_cmp) <case LE>: Fix
	a pasto, compare code against LE rather than GE.

	* gcc.target/i386/pr114339.c: New test.

--- gcc/config/i386/i386-expand.cc.jj	2024-03-07 08:34:21.043802912 +0100
+++ gcc/config/i386/i386-expand.cc	2024-03-14 22:55:57.321842686 +0100
@@ -4690,7 +4690,7 @@ ix86_expand_int_sse_cmp (rtx dest, enum
 		  rtx elt = CONST_VECTOR_ELT (cop1, i);
 		  if (!CONST_INT_P (elt))
 		    break;
-		  if (code == GE)
+		  if (code == LE)
 		    {
 		      /* For LE punt if some element is signed maximum.  */
 		      if ((INTVAL (elt) & (GET_MODE_MASK (eltmode) >> 1))
--- gcc/testsuite/gcc.target/i386/pr114339.c.jj	2024-03-14 22:58:04.739076025 +0100
+++ gcc/testsuite/gcc.target/i386/pr114339.c	2024-03-14 22:38:59.736972124 +0100
@@ -0,0 +1,20 @@
+/* PR target/114339 */
+/* { dg-do run } */
+/* { dg-options "-O2 -Wno-psabi" } */
+/* { dg-additional-options "-mavx" { target avx_runtime } } */
+
+typedef long long V __attribute__((vector_size (16)));
+
+__attribute__((noipa)) V
+foo (V a)
+{
+  return a <= (V) {0, __LONG_LONG_MAX__ };
+}
+
+int
+main ()
+{
+  V t = foo ((V) { 0, 0 });
+  if (t[0] != -1LL || t[1] != -1LL)
+    __builtin_abort ();
+}

	Jakub


             reply	other threads:[~2024-03-15  8:50 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-15  8:50 Jakub Jelinek [this message]
2024-03-15  9:43 ` Uros Bizjak

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=ZfQLuno+PsZ2WsNh@tucnak \
    --to=jakub@redhat.com \
    --cc=crazylht@gmail.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=ubizjak@gmail.com \
    /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).