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

            Bug ID: 119903
           Summary: [13/14/15/16 Regression] non-call exception vs traping
                    comparison
           Product: gcc
           Version: 16.0
            Status: UNCONFIRMED
          Keywords: EH, wrong-code
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: pinskia at gcc dot gnu.org
          Reporter: pinskia at gcc dot gnu.org
  Target Milestone: ---

Take:
```
int f() noexcept;
int g() noexcept;

int m(double a)
{
  try {
    if (a < 1.0)
      return f();
    return g();
  }catch(...)
  {
        return -1;
  }
}
```
Compile with `-O2 -fnon-call-exceptions -ftrapping-math`, we lose the exception
landing pad in forwprop1.

And we get:
```
;;   basic block 2, loop depth 0, count 1073741824 (estimated locally), maybe
hot
;;    prev block 0, next block 3, flags: (NEW, VISITED)
;;    pred:       ENTRY [always]  count:1073741824 (estimated locally)
(FALLTHRU,EXECUTABLE)
  [LP 1] _5 = a_4(D) < 1.0e+0;
;;    succ:       7 [never]  count:0 (precise) (EH,EXECUTABLE)
;;                3 [always]  count:1073741824 (estimated locally)
(FALLTHRU,EXECUTABLE)

;;   basic block 3, loop depth 0, count 1073741824 (estimated locally), maybe
hot
;;    prev block 2, next block 4, flags: (NEW, VISITED)
;;    pred:       2 [always]  count:1073741824 (estimated locally)
(FALLTHRU,EXECUTABLE)
  _15 = a_4(D) < 1.0e+0;
  if (_15 != 0)
```

Notice that _5 is no used so it will be DCE (on the RTL level).

This started with r13-322-g7f04b0d786e13f.

I have a "hack" to gimple-fold to fix this by rejecting what match and simplify
has done after the fact. But I almost think we should reject this kind of thing
outside of gimple fold too.

Reply via email to