public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/103181] New: [9/10/11/12 Regression] wrong code at -O1 due to conditional division by 0 being executed
@ 2021-11-11  4:47 zsojka at seznam dot cz
  2021-11-11  5:01 ` [Bug tree-optimization/103181] " pinskia at gcc dot gnu.org
                   ` (11 more replies)
  0 siblings, 12 replies; 13+ messages in thread
From: zsojka at seznam dot cz @ 2021-11-11  4:47 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 103181
           Summary: [9/10/11/12 Regression] wrong code at -O1 due to
                    conditional division by 0 being executed
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Keywords: wrong-code
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: zsojka at seznam dot cz
  Target Milestone: ---
              Host: x86_64-pc-linux-gnu

Created attachment 51762
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=51762&action=edit
reduced testcase

Output:
$ x86_64-pc-linux-gnu-gcc testcase.c -O0 && ./a.out
$ x86_64-pc-linux-gnu-gcc testcase.c -O1 && ./a.out 
Floating point exception
$ x86_64-pc-linux-gnu-gcc testcase.c -O2 && ./a.out
$ x86_64-pc-linux-gnu-gcc testcase.c -O3 && ./a.out

The right hand operand of || in
  v += __builtin_bswap16 (s) || (S) (a / ((U){3, 0}));
is executed, even though s != 0 and it may trap.

$ x86_64-pc-linux-gnu-gcc -v
Using built-in specs.
COLLECT_GCC=/repo/gcc-trunk/binary-latest-amd64//bin/x86_64-pc-linux-gnu-gcc
COLLECT_LTO_WRAPPER=/repo/gcc-trunk/binary-trunk-r12-5136-20211110203027-gabc2f01914d-checking-yes-rtl-df-extra-amd64/bin/../libexec/gcc/x86_64-pc-linux-gnu/12.0.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: /repo/gcc-trunk//configure --enable-languages=c,c++
--enable-valgrind-annotations --disable-nls --enable-checking=yes,rtl,df,extra
--with-cloog --with-ppl --with-isl --build=x86_64-pc-linux-gnu
--host=x86_64-pc-linux-gnu --target=x86_64-pc-linux-gnu
--with-ld=/usr/bin/x86_64-pc-linux-gnu-ld
--with-as=/usr/bin/x86_64-pc-linux-gnu-as --disable-libstdcxx-pch
--prefix=/repo/gcc-trunk//binary-trunk-r12-5136-20211110203027-gabc2f01914d-checking-yes-rtl-df-extra-amd64
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 12.0.0 20211110 (experimental) (GCC)

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

* [Bug tree-optimization/103181] [9/10/11/12 Regression] wrong code at -O1 due to conditional division by 0 being executed
  2021-11-11  4:47 [Bug tree-optimization/103181] New: [9/10/11/12 Regression] wrong code at -O1 due to conditional division by 0 being executed zsojka at seznam dot cz
@ 2021-11-11  5:01 ` pinskia at gcc dot gnu.org
  2021-11-11  5:12 ` pinskia at gcc dot gnu.org
                   ` (10 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-11-11  5:01 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |pinskia at gcc dot gnu.org

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Adding -fno-inline causes the failure at -O2 and above.

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

* [Bug tree-optimization/103181] [9/10/11/12 Regression] wrong code at -O1 due to conditional division by 0 being executed
  2021-11-11  4:47 [Bug tree-optimization/103181] New: [9/10/11/12 Regression] wrong code at -O1 due to conditional division by 0 being executed zsojka at seznam dot cz
  2021-11-11  5:01 ` [Bug tree-optimization/103181] " pinskia at gcc dot gnu.org
@ 2021-11-11  5:12 ` pinskia at gcc dot gnu.org
  2021-11-11  5:18 ` pinskia at gcc dot gnu.org
                   ` (9 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-11-11  5:12 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|---                         |9.5
   Last reconfirmed|                            |2021-11-11
             Status|UNCONFIRMED                 |NEW
     Ever confirmed|0                           |1

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Confirm, reassoc1 is converting this into straight line code ....

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

* [Bug tree-optimization/103181] [9/10/11/12 Regression] wrong code at -O1 due to conditional division by 0 being executed
  2021-11-11  4:47 [Bug tree-optimization/103181] New: [9/10/11/12 Regression] wrong code at -O1 due to conditional division by 0 being executed zsojka at seznam dot cz
  2021-11-11  5:01 ` [Bug tree-optimization/103181] " pinskia at gcc dot gnu.org
  2021-11-11  5:12 ` pinskia at gcc dot gnu.org
@ 2021-11-11  5:18 ` pinskia at gcc dot gnu.org
  2021-11-11  8:03 ` rguenth at gcc dot gnu.org
                   ` (8 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-11-11  5:18 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |rguenth at gcc dot gnu.org

--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
The problem is in gimple.c:
      return (operation_could_trap_p (op, FLOAT_TYPE_P (t),
                                      (INTEGRAL_TYPE_P (t)
                                       && TYPE_OVERFLOW_TRAPS (t)),
                                      div));


We only check for scalar integer types ...

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

* [Bug tree-optimization/103181] [9/10/11/12 Regression] wrong code at -O1 due to conditional division by 0 being executed
  2021-11-11  4:47 [Bug tree-optimization/103181] New: [9/10/11/12 Regression] wrong code at -O1 due to conditional division by 0 being executed zsojka at seznam dot cz
                   ` (2 preceding siblings ...)
  2021-11-11  5:18 ` pinskia at gcc dot gnu.org
@ 2021-11-11  8:03 ` rguenth at gcc dot gnu.org
  2021-11-11  8:33 ` rguenth at gcc dot gnu.org
                   ` (7 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: rguenth at gcc dot gnu.org @ 2021-11-11  8:03 UTC (permalink / raw)
  To: gcc-bugs

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

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Assignee|unassigned at gcc dot gnu.org      |rguenth at gcc dot gnu.org
             Status|NEW                         |ASSIGNED

--- Comment #4 from Richard Biener <rguenth at gcc dot gnu.org> ---
Mine

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

* [Bug tree-optimization/103181] [9/10/11/12 Regression] wrong code at -O1 due to conditional division by 0 being executed
  2021-11-11  4:47 [Bug tree-optimization/103181] New: [9/10/11/12 Regression] wrong code at -O1 due to conditional division by 0 being executed zsojka at seznam dot cz
                   ` (3 preceding siblings ...)
  2021-11-11  8:03 ` rguenth at gcc dot gnu.org
@ 2021-11-11  8:33 ` rguenth at gcc dot gnu.org
  2021-11-11  9:18 ` rguenth at gcc dot gnu.org
                   ` (6 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: rguenth at gcc dot gnu.org @ 2021-11-11  8:33 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from Richard Biener <rguenth at gcc dot gnu.org> ---
The issue is rather

      if (!TREE_CONSTANT (divisor) || integer_zerop (divisor))
        return true;
      return false;

for division handling where here we have { 3, 0 } for the divisor.

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

* [Bug tree-optimization/103181] [9/10/11/12 Regression] wrong code at -O1 due to conditional division by 0 being executed
  2021-11-11  4:47 [Bug tree-optimization/103181] New: [9/10/11/12 Regression] wrong code at -O1 due to conditional division by 0 being executed zsojka at seznam dot cz
                   ` (4 preceding siblings ...)
  2021-11-11  8:33 ` rguenth at gcc dot gnu.org
@ 2021-11-11  9:18 ` rguenth at gcc dot gnu.org
  2021-11-11  9:33 ` cvs-commit at gcc dot gnu.org
                   ` (5 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: rguenth at gcc dot gnu.org @ 2021-11-11  9:18 UTC (permalink / raw)
  To: gcc-bugs

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

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Priority|P3                          |P2

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

* [Bug tree-optimization/103181] [9/10/11/12 Regression] wrong code at -O1 due to conditional division by 0 being executed
  2021-11-11  4:47 [Bug tree-optimization/103181] New: [9/10/11/12 Regression] wrong code at -O1 due to conditional division by 0 being executed zsojka at seznam dot cz
                   ` (5 preceding siblings ...)
  2021-11-11  9:18 ` rguenth at gcc dot gnu.org
@ 2021-11-11  9:33 ` cvs-commit at gcc dot gnu.org
  2021-11-19  8:36 ` [Bug tree-optimization/103181] [9/10/11 " rguenth at gcc dot gnu.org
                   ` (4 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-11-11  9:33 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #6 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Richard Biener <rguenth@gcc.gnu.org>:

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

commit r12-5149-ga5fed4063f428a14f5b91533d5954b9bf4e3e7db
Author: Richard Biener <rguenther@suse.de>
Date:   Thu Nov 11 09:40:36 2021 +0100

    middle-end/103181 - fix operation_could_trap_p for vector division

    For integer vector division we only checked for all zero vector
    constants rather than checking whether any element in the constant
    vector is zero.

    2021-11-11  Richard Biener  <rguenther@suse.de>

            PR middle-end/103181
            * tree-eh.c (operation_could_trap_helper_p): Properly
            check vector constants for a zero element for integer
            division.  Separate floating point and integer division code.

            * gcc.dg/torture/pr103181.c: New testcase.

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

* [Bug tree-optimization/103181] [9/10/11 Regression] wrong code at -O1 due to conditional division by 0 being executed
  2021-11-11  4:47 [Bug tree-optimization/103181] New: [9/10/11/12 Regression] wrong code at -O1 due to conditional division by 0 being executed zsojka at seznam dot cz
                   ` (6 preceding siblings ...)
  2021-11-11  9:33 ` cvs-commit at gcc dot gnu.org
@ 2021-11-19  8:36 ` rguenth at gcc dot gnu.org
  2021-11-22  8:00 ` cvs-commit at gcc dot gnu.org
                   ` (3 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: rguenth at gcc dot gnu.org @ 2021-11-19  8:36 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103181
Bug 103181 depends on bug 103248, which changed state.

Bug 103248 Summary: [12 Regression] ICE in operation_could_trap_helper_p, at tree-eh.c:2479
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103248

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

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

* [Bug tree-optimization/103181] [9/10/11 Regression] wrong code at -O1 due to conditional division by 0 being executed
  2021-11-11  4:47 [Bug tree-optimization/103181] New: [9/10/11/12 Regression] wrong code at -O1 due to conditional division by 0 being executed zsojka at seznam dot cz
                   ` (7 preceding siblings ...)
  2021-11-19  8:36 ` [Bug tree-optimization/103181] [9/10/11 " rguenth at gcc dot gnu.org
@ 2021-11-22  8:00 ` cvs-commit at gcc dot gnu.org
  2022-02-17 10:48 ` [Bug tree-optimization/103181] [9/10 " cvs-commit at gcc dot gnu.org
                   ` (2 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-11-22  8:00 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #7 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-11 branch has been updated by Richard Biener
<rguenth@gcc.gnu.org>:

https://gcc.gnu.org/g:2f0c8f74daef93c0c7b33294213e7db6df58c4d1

commit r11-9259-g2f0c8f74daef93c0c7b33294213e7db6df58c4d1
Author: Richard Biener <rguenther@suse.de>
Date:   Thu Nov 11 09:40:36 2021 +0100

    middle-end/103181 - fix operation_could_trap_p for vector division

    For integer vector division we only checked for all zero vector
    constants rather than checking whether any element in the constant
    vector is zero.

    It also fixes the adjustment to operation_could_trap_helper_p
    where I failed to realize that RDIV_EXPR is also used for
    fixed-point types.  It also fixes that handling by properly
    checking for a fixed_zerop divisor.

    2021-11-11  Richard Biener  <rguenther@suse.de>

            PR middle-end/103181
            PR middle-end/103248
            * tree-eh.c (operation_could_trap_helper_p): Properly
            check vector constants for a zero element for integer
            division.  Separate floating point and integer division code.
            Properly handle fixed-point RDIV_EXPR.

            * gcc.dg/torture/pr103181.c: New testcase.
            * gcc.dg/pr103248.c: Likewise.

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

* [Bug tree-optimization/103181] [9/10 Regression] wrong code at -O1 due to conditional division by 0 being executed
  2021-11-11  4:47 [Bug tree-optimization/103181] New: [9/10/11/12 Regression] wrong code at -O1 due to conditional division by 0 being executed zsojka at seznam dot cz
                   ` (8 preceding siblings ...)
  2021-11-22  8:00 ` cvs-commit at gcc dot gnu.org
@ 2022-02-17 10:48 ` cvs-commit at gcc dot gnu.org
  2022-02-17 11:57 ` [Bug tree-optimization/103181] [9 " cvs-commit at gcc dot gnu.org
  2022-02-17 11:57 ` rguenth at gcc dot gnu.org
  11 siblings, 0 replies; 13+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2022-02-17 10:48 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #8 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-10 branch has been updated by Richard Biener
<rguenth@gcc.gnu.org>:

https://gcc.gnu.org/g:5f5c26a2f02572996efd2b2de0dd5600ad7e91e7

commit r10-10464-g5f5c26a2f02572996efd2b2de0dd5600ad7e91e7
Author: Richard Biener <rguenther@suse.de>
Date:   Thu Nov 11 09:40:36 2021 +0100

    middle-end/103181 - fix operation_could_trap_p for vector division

    For integer vector division we only checked for all zero vector
    constants rather than checking whether any element in the constant
    vector is zero.

    It also fixes the adjustment to operation_could_trap_helper_p
    where I failed to realize that RDIV_EXPR is also used for
    fixed-point types.  It also fixes that handling by properly
    checking for a fixed_zerop divisor.

    2021-11-11  Richard Biener  <rguenther@suse.de>

            PR middle-end/103181
            PR middle-end/103248
            * tree-eh.c (operation_could_trap_helper_p): Properly
            check vector constants for a zero element for integer
            division.  Separate floating point and integer division code.
            Properly handle fixed-point RDIV_EXPR.

            * gcc.dg/torture/pr103181.c: New testcase.
            * gcc.dg/pr103248.c: Likewise.

    (cherry picked from commit 2f0c8f74daef93c0c7b33294213e7db6df58c4d1)

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

* [Bug tree-optimization/103181] [9 Regression] wrong code at -O1 due to conditional division by 0 being executed
  2021-11-11  4:47 [Bug tree-optimization/103181] New: [9/10/11/12 Regression] wrong code at -O1 due to conditional division by 0 being executed zsojka at seznam dot cz
                   ` (9 preceding siblings ...)
  2022-02-17 10:48 ` [Bug tree-optimization/103181] [9/10 " cvs-commit at gcc dot gnu.org
@ 2022-02-17 11:57 ` cvs-commit at gcc dot gnu.org
  2022-02-17 11:57 ` rguenth at gcc dot gnu.org
  11 siblings, 0 replies; 13+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2022-02-17 11:57 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #9 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-9 branch has been updated by Richard Biener
<rguenth@gcc.gnu.org>:

https://gcc.gnu.org/g:1ac5fbea476e4ebd6a0086ccfbf92e648768be7b

commit r9-9955-g1ac5fbea476e4ebd6a0086ccfbf92e648768be7b
Author: Richard Biener <rguenther@suse.de>
Date:   Thu Nov 11 09:40:36 2021 +0100

    middle-end/103181 - fix operation_could_trap_p for vector division

    For integer vector division we only checked for all zero vector
    constants rather than checking whether any element in the constant
    vector is zero.

    It also fixes the adjustment to operation_could_trap_helper_p
    where I failed to realize that RDIV_EXPR is also used for
    fixed-point types.  It also fixes that handling by properly
    checking for a fixed_zerop divisor.

    2021-11-11  Richard Biener  <rguenther@suse.de>

            PR middle-end/103181
            PR middle-end/103248
            * tree-eh.c (operation_could_trap_helper_p): Properly
            check vector constants for a zero element for integer
            division.  Separate floating point and integer division code.
            Properly handle fixed-point RDIV_EXPR.

            * gcc.dg/torture/pr103181.c: New testcase.
            * gcc.dg/pr103248.c: Likewise.

    (cherry picked from commit 2f0c8f74daef93c0c7b33294213e7db6df58c4d1)

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

* [Bug tree-optimization/103181] [9 Regression] wrong code at -O1 due to conditional division by 0 being executed
  2021-11-11  4:47 [Bug tree-optimization/103181] New: [9/10/11/12 Regression] wrong code at -O1 due to conditional division by 0 being executed zsojka at seznam dot cz
                   ` (10 preceding siblings ...)
  2022-02-17 11:57 ` [Bug tree-optimization/103181] [9 " cvs-commit at gcc dot gnu.org
@ 2022-02-17 11:57 ` rguenth at gcc dot gnu.org
  11 siblings, 0 replies; 13+ messages in thread
From: rguenth at gcc dot gnu.org @ 2022-02-17 11:57 UTC (permalink / raw)
  To: gcc-bugs

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

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
      Known to fail|10.3.1                      |10.3.0
         Resolution|---                         |FIXED
      Known to work|                            |10.3.1
             Status|ASSIGNED                    |RESOLVED

--- Comment #10 from Richard Biener <rguenth at gcc dot gnu.org> ---
Fixed.

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

end of thread, other threads:[~2022-02-17 11:57 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-11  4:47 [Bug tree-optimization/103181] New: [9/10/11/12 Regression] wrong code at -O1 due to conditional division by 0 being executed zsojka at seznam dot cz
2021-11-11  5:01 ` [Bug tree-optimization/103181] " pinskia at gcc dot gnu.org
2021-11-11  5:12 ` pinskia at gcc dot gnu.org
2021-11-11  5:18 ` pinskia at gcc dot gnu.org
2021-11-11  8:03 ` rguenth at gcc dot gnu.org
2021-11-11  8:33 ` rguenth at gcc dot gnu.org
2021-11-11  9:18 ` rguenth at gcc dot gnu.org
2021-11-11  9:33 ` cvs-commit at gcc dot gnu.org
2021-11-19  8:36 ` [Bug tree-optimization/103181] [9/10/11 " rguenth at gcc dot gnu.org
2021-11-22  8:00 ` cvs-commit at gcc dot gnu.org
2022-02-17 10:48 ` [Bug tree-optimization/103181] [9/10 " cvs-commit at gcc dot gnu.org
2022-02-17 11:57 ` [Bug tree-optimization/103181] [9 " cvs-commit at gcc dot gnu.org
2022-02-17 11:57 ` rguenth 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).