public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/110666] New: wrong code at -O1 and above on x86_64-linux-gnu
@ 2023-07-14 13:45 zhendong.su at inf dot ethz.ch
  2023-07-14 15:02 ` [Bug tree-optimization/110666] [14 Regression] " pinskia at gcc dot gnu.org
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: zhendong.su at inf dot ethz.ch @ 2023-07-14 13:45 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 110666
           Summary: wrong code at -O1 and above on x86_64-linux-gnu
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: zhendong.su at inf dot ethz.ch
  Target Milestone: ---

This appears to be a recent regression.

Compiler Explorer: https://godbolt.org/z/xG14vrs6K

[501] % gcctk -v
Using built-in specs.
COLLECT_GCC=gcctk
COLLECT_LTO_WRAPPER=/local/home/suz/suz-local/software/local/gcc-trunk/bin/../libexec/gcc/x86_64-pc-linux-gnu/14.0.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ../gcc-trunk/configure --disable-bootstrap
--enable-checking=yes --prefix=/local/suz-local/software/local/gcc-trunk
--enable-sanitizers --enable-languages=c,c++ --disable-werror --enable-multilib
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 14.0.0 20230714 (experimental) (GCC) 
[502] % 
[502] % gcctk -O0 small.c; ./a.out
[503] % gcctk -O1 small.c; ./a.out
Aborted
[504] % cat small.c
int a;
int main() {
  if ((a != 2) == a)
    __builtin_abort();
  return 0;
}

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

* [Bug tree-optimization/110666] [14 Regression] wrong code at -O1 and above on x86_64-linux-gnu
  2023-07-14 13:45 [Bug tree-optimization/110666] New: wrong code at -O1 and above on x86_64-linux-gnu zhendong.su at inf dot ethz.ch
@ 2023-07-14 15:02 ` pinskia at gcc dot gnu.org
  2023-07-14 15:26 ` 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-07-14 15:02 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |wrong-code
           Assignee|unassigned at gcc dot gnu.org      |pinskia at gcc dot gnu.org
   Target Milestone|---                         |14.0
   Last reconfirmed|                            |2023-07-14
     Ever confirmed|0                           |1
            Summary|wrong code at -O1 and above |[14 Regression] wrong code
                   |on x86_64-linux-gnu         |at -O1 and above on
                   |                            |x86_64-linux-gnu
            Version|unknown                     |14.0
             Status|UNCONFIRMED                 |ASSIGNED

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Mine. Let me look at what I did wrong.

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

* [Bug tree-optimization/110666] [14 Regression] wrong code at -O1 and above on x86_64-linux-gnu
  2023-07-14 13:45 [Bug tree-optimization/110666] New: wrong code at -O1 and above on x86_64-linux-gnu zhendong.su at inf dot ethz.ch
  2023-07-14 15:02 ` [Bug tree-optimization/110666] [14 Regression] " pinskia at gcc dot gnu.org
@ 2023-07-14 15:26 ` pinskia at gcc dot gnu.org
  2023-07-14 16:38 ` 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-07-14 15:26 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
I totally messed up the !=1/!=0 cases for the outer eq case:
Patch
diff --git a/gcc/match.pd b/gcc/match.pd
index 351d9285e92..3de30df8b06 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -6431,8 +6431,8 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)

 /* x != (typeof x)(x == CST) -> CST == 0 ? 1 : (CST == 1 ? (x!=0&&x!=1) : x !=
0) */
 /* x != (typeof x)(x != CST) -> CST == 1 ? 1 : (CST == 0 ? (x!=0&&x!=1) : x !=
1) */
-/* x == (typeof x)(x == CST) -> CST == 0 ? 0 : (CST == 1 ? (x==0||x==1) : x !=
0) */
-/* x == (typeof x)(x != CST) -> CST == 1 ? 0 : (CST == 0 ? (x==0||x==1) : x !=
1) */
+/* x == (typeof x)(x == CST) -> CST == 0 ? 0 : (CST == 1 ? (x==0||x==1) : x ==
0) */
+/* x == (typeof x)(x != CST) -> CST == 1 ? 0 : (CST == 0 ? (x==0||x==1) : x ==
1) */
 (for outer (ne eq)
  (for inner (ne eq)
   (simplify
@@ -6457,9 +6457,14 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
       )
      )
     )
-    (if (innereq)
-     (ne @0 { build_zero_cst (TREE_TYPE (@0)); }))
-    (ne @0 { build_one_cst (TREE_TYPE (@0)); }))
+    (with {
+      tree value = build_int_cst (TREE_TYPE (@0), !innereq);
+     }
+     (if (outereq)
+      (eq @0 { value; })
+      (ne @0 { value; })
+     )
+    )
    )
   )
  )

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

* [Bug tree-optimization/110666] [14 Regression] wrong code at -O1 and above on x86_64-linux-gnu
  2023-07-14 13:45 [Bug tree-optimization/110666] New: wrong code at -O1 and above on x86_64-linux-gnu zhendong.su at inf dot ethz.ch
  2023-07-14 15:02 ` [Bug tree-optimization/110666] [14 Regression] " pinskia at gcc dot gnu.org
  2023-07-14 15:26 ` pinskia at gcc dot gnu.org
@ 2023-07-14 16:38 ` pinskia at gcc dot gnu.org
  2023-07-14 20:58 ` 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-07-14 16:38 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Created attachment 55544
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=55544&action=edit
Full testcase to make sure we don't create wrong code

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

* [Bug tree-optimization/110666] [14 Regression] wrong code at -O1 and above on x86_64-linux-gnu
  2023-07-14 13:45 [Bug tree-optimization/110666] New: wrong code at -O1 and above on x86_64-linux-gnu zhendong.su at inf dot ethz.ch
                   ` (2 preceding siblings ...)
  2023-07-14 16:38 ` pinskia at gcc dot gnu.org
@ 2023-07-14 20:58 ` pinskia at gcc dot gnu.org
  2023-07-15  5:28 ` zhendong.su at inf dot ethz.ch
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-07-14 20:58 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |patch
                URL|                            |https://gcc.gnu.org/piperma
                   |                            |il/gcc-patches/2023-July/62
                   |                            |4551.html

--- Comment #4 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Patch posted:
https://gcc.gnu.org/pipermail/gcc-patches/2023-July/624551.html

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

* [Bug tree-optimization/110666] [14 Regression] wrong code at -O1 and above on x86_64-linux-gnu
  2023-07-14 13:45 [Bug tree-optimization/110666] New: wrong code at -O1 and above on x86_64-linux-gnu zhendong.su at inf dot ethz.ch
                   ` (3 preceding siblings ...)
  2023-07-14 20:58 ` pinskia at gcc dot gnu.org
@ 2023-07-15  5:28 ` zhendong.su at inf dot ethz.ch
  2023-07-15  5:39 ` pinskia at gcc dot gnu.org
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: zhendong.su at inf dot ethz.ch @ 2023-07-15  5:28 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from Zhendong Su <zhendong.su at inf dot ethz.ch> ---
A couple of very likely related tests (especially #2 and #3):

*** (1) wrong code at -O2, -O3, and -Os

[539] % gcctk -O1 small.c; ./a.out
[540] % gcctk -O2 small.c
[541] % timeout -s 9 5 ./a.out
Killed
[542] % cat small.c
int a, b = -1, c, d = -1;
int main() {
  if (a)
    goto L2;
 L1:
  a = 0;
 L2:
  b && c;
  c = ~c * (d ^ (0 || a) || d & b);
  if (c)
    goto L1;
  return 0;
}

*** (2) wrong code at -O1 and above

[558] % gcctk -O0 small.c; ./a.out
[559] % gcctk -O1 small.c
[560] % ./a.out
Floating point exception
[561] % cat small.c
int a = 1, b, c;
void f(int d) {
  for (; c < 2; c++) {
    if (!a)
      b = -1;
    a = (d != 4) == d;
    b = 1 % ~b;
  }
}
int main() { f(1 || b); }

*** (3) wrong code at -O1 and above

[577] % gcctk -O0 small.c; ./a.out
[578] % gcctk -O1 small.c
[579] % timeout -s 9 5 ./a.out
Killed
[580] % cat small.c
int a = 1, b, c, d;
void e(int f) {
  for (; c < 2; c++) {
    if (b)
      d = c;
    c = d;
    b = f;
  }
}
int main() { e(((a != 2) != a) != 1); }

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

* [Bug tree-optimization/110666] [14 Regression] wrong code at -O1 and above on x86_64-linux-gnu
  2023-07-14 13:45 [Bug tree-optimization/110666] New: wrong code at -O1 and above on x86_64-linux-gnu zhendong.su at inf dot ethz.ch
                   ` (4 preceding siblings ...)
  2023-07-15  5:28 ` zhendong.su at inf dot ethz.ch
@ 2023-07-15  5:39 ` pinskia at gcc dot gnu.org
  2023-07-17  6:27 ` cvs-commit at gcc dot gnu.org
  2023-07-17  6:27 ` pinskia at gcc dot gnu.org
  7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-07-15  5:39 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #6 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to Zhendong Su from comment #5)
> A couple of very likely related tests (especially #2 and #3):
> 
> *** (1) wrong code at -O2, -O3, and -Os

case 1 is a phiopt issue (PR 110252).


> *** (2) wrong code at -O1 and above

Case 2 is this issue.

> 
> *** (3) wrong code at -O1 and above

Case 3 is this issue too.

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

* [Bug tree-optimization/110666] [14 Regression] wrong code at -O1 and above on x86_64-linux-gnu
  2023-07-14 13:45 [Bug tree-optimization/110666] New: wrong code at -O1 and above on x86_64-linux-gnu zhendong.su at inf dot ethz.ch
                   ` (5 preceding siblings ...)
  2023-07-15  5:39 ` pinskia at gcc dot gnu.org
@ 2023-07-17  6:27 ` cvs-commit at gcc dot gnu.org
  2023-07-17  6:27 ` pinskia at gcc dot gnu.org
  7 siblings, 0 replies; 9+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-07-17  6:27 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #7 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The trunk branch has been updated by Andrew Pinski <pinskia@gcc.gnu.org>:

https://gcc.gnu.org/g:d20e542ecd8cfc009b120f9e432caeb7005e7c53

commit r14-2554-gd20e542ecd8cfc009b120f9e432caeb7005e7c53
Author: Andrew Pinski <apinski@marvell.com>
Date:   Fri Jul 14 09:55:57 2023 -0700

    Fix PR 110666: `(a != 2) == a` produces wrong code

    I had messed up the case where the outer operator is `==`.
    The check for the resulting should have been `==` and not `!=`.
    This patch fixes that and adds a full runtime testcase now for
    all cases to make sure it works.

    OK? Bootstrapped and tested on x86-64-linux-gnu with no regressions.

    gcc/ChangeLog:

            PR tree-optimization/110666
            * match.pd (A NEEQ (A NEEQ CST)): Fix Outer EQ case.

    gcc/testsuite/ChangeLog:

            PR tree-optimization/110666
            * gcc.c-torture/execute/pr110666-1.c: New test.

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

* [Bug tree-optimization/110666] [14 Regression] wrong code at -O1 and above on x86_64-linux-gnu
  2023-07-14 13:45 [Bug tree-optimization/110666] New: wrong code at -O1 and above on x86_64-linux-gnu zhendong.su at inf dot ethz.ch
                   ` (6 preceding siblings ...)
  2023-07-17  6:27 ` cvs-commit at gcc dot gnu.org
@ 2023-07-17  6:27 ` pinskia at gcc dot gnu.org
  7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-07-17  6:27 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|---                         |FIXED

--- Comment #8 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Fixed.

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

end of thread, other threads:[~2023-07-17  6:27 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-07-14 13:45 [Bug tree-optimization/110666] New: wrong code at -O1 and above on x86_64-linux-gnu zhendong.su at inf dot ethz.ch
2023-07-14 15:02 ` [Bug tree-optimization/110666] [14 Regression] " pinskia at gcc dot gnu.org
2023-07-14 15:26 ` pinskia at gcc dot gnu.org
2023-07-14 16:38 ` pinskia at gcc dot gnu.org
2023-07-14 20:58 ` pinskia at gcc dot gnu.org
2023-07-15  5:28 ` zhendong.su at inf dot ethz.ch
2023-07-15  5:39 ` pinskia at gcc dot gnu.org
2023-07-17  6:27 ` cvs-commit at gcc dot gnu.org
2023-07-17  6:27 ` 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).