public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/116772] New: [15 regression] SIGFPE (branch optimised out) in eigen-3.4.0 testsuite
@ 2024-09-18 21:53 sjames at gcc dot gnu.org
  2024-09-18 21:54 ` [Bug c++/116772] " sjames at gcc dot gnu.org
                   ` (9 more replies)
  0 siblings, 10 replies; 11+ messages in thread
From: sjames at gcc dot gnu.org @ 2024-09-18 21:53 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 116772
           Summary: [15 regression] SIGFPE (branch optimised out) in
                    eigen-3.4.0 testsuite
           Product: gcc
           Version: 15.0
            Status: UNCONFIRMED
          Keywords: wrong-code
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: sjames at gcc dot gnu.org
  Target Milestone: ---

Forwarding a report from Paul Zander in Gentoo:
"""
While running the eigen-3.4.0 test suite in gentoo, a few tests fail with
"signal SIGFPE, Arithmetic exception" under gcc-15. 

> Program received signal SIGFPE, Arithmetic exception.
> 0x0000555555559dda in Eigen::internal::gemm_pack_lhs<double, long, Eigen::internal::const_blas_data_mapper<double, long, 0>, 4, 2, double __vector(4), 0, false, false>::operator()(double*, Eigen::internal::const_blas_data_mapper<double, long, 0> const&, long, long, long, long) (blockA=blockA@entry=0x7fffffffcb40, lhs=..., depth=depth@entry=3, 
>     rows=rows@entry=3, stride=stride@entry=0, offset=offset@entry=0, this=<optimized out>) at /var/tmp/paludis/dev-cpp-eigen-3.4.0-r3/work/eigen-3.4.0/Eigen/src/Core/products/GeneralBlockPanelKernel.h:2121
> 2121      const Index peeled_mc0 = Pack2>=PacketSize ? peeled_mc_quarter
> (gdb) x/i $pc
> => 0x555555559dda <_ZN5Eigen8internal13gemm_pack_lhsIdlNS0_22const_blas_data_mapperIdlLi0EEELi4ELi2EDv4_dLi0ELb0ELb0EEclEPdRKS3_llll+154>:      idiv   %r13

The failure occurs in
> const Index peeled_mc0 = Pack2>=PacketSize ? peeled_mc_quarter
>                        : Pack2>1 && last_lhs_progress ? (rows/last_lhs_progress)*last_lhs_progress : 0;

https://gitlab.com/libeigen/eigen/-/blob/3.4/Eigen/src/Core/products/GeneralBlockPanelKernel.h?ref_type=heads#L2121-2122

A simple reproducer is https://godbolt.org/z/a5hzzK377
> #include <iostream>
> template<typename Index>
> Index round(Index a,Index b){
>   return b!=0 ? a/b*b :0;
> }
> 
> int main() {
>   std::cout << round<long>(3L, 1L) << '\n';
>   std::cout << round<long>(3L, 0L) << '\n';
>   return 0;
> }

Looking at assembler code gcc-15 reduces the ternary operation to "a/b*b",
which then fails for b == 0.
"""

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

* [Bug c++/116772] [15 regression] SIGFPE (branch optimised out) in eigen-3.4.0 testsuite
  2024-09-18 21:53 [Bug c++/116772] New: [15 regression] SIGFPE (branch optimised out) in eigen-3.4.0 testsuite sjames at gcc dot gnu.org
@ 2024-09-18 21:54 ` sjames at gcc dot gnu.org
  2024-09-18 22:01 ` [Bug middle-end/116772] " mpolacek at gcc dot gnu.org
                   ` (8 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: sjames at gcc dot gnu.org @ 2024-09-18 21:54 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Sam James <sjames at gcc dot gnu.org> ---
Created attachment 59142
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=59142&action=edit
test.cxx

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

* [Bug middle-end/116772] [15 regression] SIGFPE (branch optimised out) in eigen-3.4.0 testsuite
  2024-09-18 21:53 [Bug c++/116772] New: [15 regression] SIGFPE (branch optimised out) in eigen-3.4.0 testsuite sjames at gcc dot gnu.org
  2024-09-18 21:54 ` [Bug c++/116772] " sjames at gcc dot gnu.org
@ 2024-09-18 22:01 ` mpolacek at gcc dot gnu.org
  2024-09-18 22:08 ` pinskia at gcc dot gnu.org
                   ` (7 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2024-09-18 22:01 UTC (permalink / raw)
  To: gcc-bugs

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

Marek Polacek <mpolacek at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|                            |2024-09-18
   Target Milestone|---                         |15.0
           Priority|P3                          |P1
     Ever confirmed|0                           |1
                 CC|                            |mpolacek at gcc dot gnu.org,
                   |                            |pinskia at gcc dot gnu.org
          Component|c++                         |middle-end
             Status|UNCONFIRMED                 |NEW

--- Comment #2 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Started with r15-307:

commit e472527c7b45d23e8dfd0fb767a6e663b4bc136e
Author: Andrew Pinski <quic_apinski@quicinc.com>
Date:   Tue Apr 30 14:45:26 2024 -0700

    MATCH: Add some more value_replacement simplifications (a != 0 ? expr : 0)
to match

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

* [Bug middle-end/116772] [15 regression] SIGFPE (branch optimised out) in eigen-3.4.0 testsuite
  2024-09-18 21:53 [Bug c++/116772] New: [15 regression] SIGFPE (branch optimised out) in eigen-3.4.0 testsuite sjames at gcc dot gnu.org
  2024-09-18 21:54 ` [Bug c++/116772] " sjames at gcc dot gnu.org
  2024-09-18 22:01 ` [Bug middle-end/116772] " mpolacek at gcc dot gnu.org
@ 2024-09-18 22:08 ` pinskia at gcc dot gnu.org
  2024-09-18 22:13 ` pinskia at gcc dot gnu.org
                   ` (6 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-09-18 22:08 UTC (permalink / raw)
  To: gcc-bugs

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

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

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

--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
It is this pattern:
a != 0 ? a * b : 0 -> a * b

as we don't check if b could trap.
match and generic and cond_expr don't always get along it seems.

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

* [Bug middle-end/116772] [15 regression] SIGFPE (branch optimised out) in eigen-3.4.0 testsuite
  2024-09-18 21:53 [Bug c++/116772] New: [15 regression] SIGFPE (branch optimised out) in eigen-3.4.0 testsuite sjames at gcc dot gnu.org
                   ` (2 preceding siblings ...)
  2024-09-18 22:08 ` pinskia at gcc dot gnu.org
@ 2024-09-18 22:13 ` pinskia at gcc dot gnu.org
  2024-09-18 22:21 ` pinskia at gcc dot gnu.org
                   ` (5 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-09-18 22:13 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
      if (TREE_SIDE_EFFECTS (_p0)) goto next_after_fail964;
      if (TREE_SIDE_EFFECTS (_p1)) goto next_after_fail964;
      if (TREE_SIDE_EFFECTS (_p2)) goto next_after_fail964;


We check for SIDE_EFFECTS so that works correctly but trap is counted as  a
side effect here. Double blah.

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

* [Bug middle-end/116772] [15 regression] SIGFPE (branch optimised out) in eigen-3.4.0 testsuite
  2024-09-18 21:53 [Bug c++/116772] New: [15 regression] SIGFPE (branch optimised out) in eigen-3.4.0 testsuite sjames at gcc dot gnu.org
                   ` (3 preceding siblings ...)
  2024-09-18 22:13 ` pinskia at gcc dot gnu.org
@ 2024-09-18 22:21 ` pinskia at gcc dot gnu.org
  2024-09-18 22:31 ` pinskia at gcc dot gnu.org
                   ` (4 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-09-18 22:21 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
The easiest fix is to add:
&& !generic_expr_could_trap_p (@3)

There but I am not sure if that will always work even though
generic_expr_could_trap_p is recusive.

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

* [Bug middle-end/116772] [15 regression] SIGFPE (branch optimised out) in eigen-3.4.0 testsuite
  2024-09-18 21:53 [Bug c++/116772] New: [15 regression] SIGFPE (branch optimised out) in eigen-3.4.0 testsuite sjames at gcc dot gnu.org
                   ` (4 preceding siblings ...)
  2024-09-18 22:21 ` pinskia at gcc dot gnu.org
@ 2024-09-18 22:31 ` pinskia at gcc dot gnu.org
  2024-09-18 22:36 ` pinskia at gcc dot gnu.org
                   ` (3 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-09-18 22:31 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #6 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Created attachment 59143
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=59143&action=edit
Better reduced testcase

Here is a better reduced testcase.

The problem only shows up with these 2 patterns because in:
 a != 0 ? a * b : 0
 a != 0 ? a & b : 0

b is only conditionaly used.

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

* [Bug middle-end/116772] [15 regression] SIGFPE (branch optimised out) in eigen-3.4.0 testsuite
  2024-09-18 21:53 [Bug c++/116772] New: [15 regression] SIGFPE (branch optimised out) in eigen-3.4.0 testsuite sjames at gcc dot gnu.org
                   ` (5 preceding siblings ...)
  2024-09-18 22:31 ` pinskia at gcc dot gnu.org
@ 2024-09-18 22:36 ` pinskia at gcc dot gnu.org
  2024-09-19  8:46 ` rguenth at gcc dot gnu.org
                   ` (2 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-09-18 22:36 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #7 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
I am wondering if genmatch should generate the call to
generic_expr_could_trap_p rather than adding it to the pattern because there
could be more issues like this learking around.

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

* [Bug middle-end/116772] [15 regression] SIGFPE (branch optimised out) in eigen-3.4.0 testsuite
  2024-09-18 21:53 [Bug c++/116772] New: [15 regression] SIGFPE (branch optimised out) in eigen-3.4.0 testsuite sjames at gcc dot gnu.org
                   ` (6 preceding siblings ...)
  2024-09-18 22:36 ` pinskia at gcc dot gnu.org
@ 2024-09-19  8:46 ` rguenth at gcc dot gnu.org
  2024-09-25 15:17 ` cvs-commit at gcc dot gnu.org
  2024-09-25 15:18 ` pinskia at gcc dot gnu.org
  9 siblings, 0 replies; 11+ messages in thread
From: rguenth at gcc dot gnu.org @ 2024-09-19  8:46 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #8 from Richard Biener <rguenth at gcc dot gnu.org> ---
Note genmatch uses TREE_SIDE_EFFECTS only for dropping/duplicating issues,
making traps unconditional is sth that patterns need to check.

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

* [Bug middle-end/116772] [15 regression] SIGFPE (branch optimised out) in eigen-3.4.0 testsuite
  2024-09-18 21:53 [Bug c++/116772] New: [15 regression] SIGFPE (branch optimised out) in eigen-3.4.0 testsuite sjames at gcc dot gnu.org
                   ` (7 preceding siblings ...)
  2024-09-19  8:46 ` rguenth at gcc dot gnu.org
@ 2024-09-25 15:17 ` cvs-commit at gcc dot gnu.org
  2024-09-25 15:18 ` pinskia at gcc dot gnu.org
  9 siblings, 0 replies; 11+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2024-09-25 15:17 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #9 from GCC 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:6c5543d3d9c4bbcd19f0ae2b7ed7e523c978a9a8

commit r15-3870-g6c5543d3d9c4bbcd19f0ae2b7ed7e523c978a9a8
Author: Andrew Pinski <quic_apinski@quicinc.com>
Date:   Thu Sep 19 13:50:14 2024 -0700

    match: Fix `a != 0 ? a * b : 0` patterns for things that trap [PR116772]

    For generic, `a != 0 ? a * b : 0` would match where `b` would be an
expression
    which trap (in the case of the testcase, it was an integer division but it
could be any).

    This adds a new helper function, expr_no_side_effects_p which tests if
there is no side effects
    and the expression is not trapping which might be used in other locations.

    Changes since v1:
    * v2: Add move check to helper function instead of inlining it.

            PR middle-end/116772

    gcc/ChangeLog:

            * generic-match-head.cc (expr_no_side_effects_p): New function
            * gimple-match-head.cc (expr_no_side_effects_p): New function
            * match.pd (`a != 0 ? a / b : 0`): Check expr_no_side_effects_p.
            (`a != 0 ? a * b : 0`, `a != 0 ? a & b : 0`): Likewise.

    gcc/testsuite/ChangeLog:

            * gcc.dg/torture/pr116772-1.c: New test.

    Signed-off-by: Andrew Pinski <quic_apinski@quicinc.com>

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

* [Bug middle-end/116772] [15 regression] SIGFPE (branch optimised out) in eigen-3.4.0 testsuite
  2024-09-18 21:53 [Bug c++/116772] New: [15 regression] SIGFPE (branch optimised out) in eigen-3.4.0 testsuite sjames at gcc dot gnu.org
                   ` (8 preceding siblings ...)
  2024-09-25 15:17 ` cvs-commit at gcc dot gnu.org
@ 2024-09-25 15:18 ` pinskia at gcc dot gnu.org
  9 siblings, 0 replies; 11+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-09-25 15:18 UTC (permalink / raw)
  To: gcc-bugs

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

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

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

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

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

end of thread, other threads:[~2024-09-25 15:18 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-09-18 21:53 [Bug c++/116772] New: [15 regression] SIGFPE (branch optimised out) in eigen-3.4.0 testsuite sjames at gcc dot gnu.org
2024-09-18 21:54 ` [Bug c++/116772] " sjames at gcc dot gnu.org
2024-09-18 22:01 ` [Bug middle-end/116772] " mpolacek at gcc dot gnu.org
2024-09-18 22:08 ` pinskia at gcc dot gnu.org
2024-09-18 22:13 ` pinskia at gcc dot gnu.org
2024-09-18 22:21 ` pinskia at gcc dot gnu.org
2024-09-18 22:31 ` pinskia at gcc dot gnu.org
2024-09-18 22:36 ` pinskia at gcc dot gnu.org
2024-09-19  8:46 ` rguenth at gcc dot gnu.org
2024-09-25 15:17 ` cvs-commit at gcc dot gnu.org
2024-09-25 15:18 ` 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).