]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
i386: Fix a pasto in ix86_expand_int_sse_cmp [PR114339]
authorJakub Jelinek <jakub@redhat.com>
Fri, 15 Mar 2024 09:46:47 +0000 (10:46 +0100)
committerJakub Jelinek <jakub@redhat.com>
Fri, 15 Mar 2024 10:04:29 +0000 (11:04 +0100)
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.

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
gcc/testsuite/gcc.target/i386/pr114339.c [new file with mode: 0644]

index 2210e6f7cc8563047e5714dc8e46166a557be91e..8bb8f21e6860580dd4eddc972f66e9b1d529309a 100644 (file)
@@ -4690,7 +4690,7 @@ ix86_expand_int_sse_cmp (rtx dest, enum rtx_code code, rtx cop0, rtx cop1,
                  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))
diff --git a/gcc/testsuite/gcc.target/i386/pr114339.c b/gcc/testsuite/gcc.target/i386/pr114339.c
new file mode 100644 (file)
index 0000000..8fba374
--- /dev/null
@@ -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 ();
+}