Bug 114678 - FAIL: gcc.dg/tree-ssa/range-sincos.c scan-tree-dump-not evrp "link_error" on s390
Summary: FAIL: gcc.dg/tree-ssa/range-sincos.c scan-tree-dump-not evrp "link_error" on ...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: tree-optimization (show other bugs)
Version: 14.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: missed-optimization, testsuite-fail
Depends on:
Blocks: VRP
  Show dependency treegraph
 
Reported: 2024-04-10 13:39 UTC by Stefan Schulze Frielinghaus
Modified: 2024-10-23 10:39 UTC (History)
2 users (show)

See Also:
Host:
Target: s390*-*-*
Build:
Known to work:
Known to fail:
Last reconfirmed: 2024-04-11 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Stefan Schulze Frielinghaus 2024-04-10 13:39:28 UTC
FAIL: gcc.dg/tree-ssa/range-sincos.c scan-tree-dump-not evrp "link_error"

I assume this is due to the case that on s390 we have an isinf optab.  Thus, prior evrp we end up with

void bar (double x)
{
  int _1;
  double _5;

  <bb 2> :
  _5 = sin (x_4(D));
  if (_5 ord _5)
    goto <bb 3>; [INV]
  else
    goto <bb 5>; [INV]

  <bb 3> :
  _1 = __builtin_isinf (x_4(D));
  if (_1 != 0)
    goto <bb 4>; [INV]
  else
    goto <bb 5>; [INV]

  <bb 4> :
  link_error ();

  <bb 5> :
  return;

}

whereas, e.g., on x86-64 we have

void bar (double x)
{
  double _1;
  double _7;

  <bb 2> :
  _7 = sin (x_6(D));
  if (_7 ord _7)
    goto <bb 3>; [INV]
  else
    goto <bb 7>; [INV]

  <bb 3> :
  if (x_6(D) unord x_6(D))
    goto <bb 4>; [INV]
  else
    goto <bb 5>; [INV]

  <bb 4> :
  link_error ();

  <bb 5> :
  _1 = ABS_EXPR <x_6(D)>;
  if (_1 u<= 1.79769313486231570814527423731704356798070567525844996599e+308)
    goto <bb 7>; [INV]
  else
    goto <bb 6>; [INV]

  <bb 6> :
  link_error ();

  <bb 7> :
  return;

}

If this optimization is all about ABS_EXPR the following patch would work on s390x and x86-64:

@@ -24,20 +24,20 @@ bar (double x)
     {
       if (__builtin_isnan (x))
        link_error ();
-      if (__builtin_isinf (x))
+      if (__builtin_fabs (x) == __builtin_inf ())
        link_error ();
     }
 }

However, I'm not sure whether this is not also a missed optimization in case of an isinf optab?
Comment 1 Richard Biener 2024-04-10 16:48:52 UTC
I guess VRP should handle __builtin_isinf and friends.
Comment 2 Andrew Pinski 2024-04-10 16:51:19 UTC
(In reply to Richard Biener from comment #1)
> I guess VRP should handle __builtin_isinf and friends.

Like was posted here:
https://gcc.gnu.org/pipermail/gcc-patches/2024-March/648303.html ?
Comment 3 Stefan Schulze Frielinghaus 2024-04-11 13:30:10 UTC
Thanks for the pointer.  I can confirm that the patch fixes this PR and also fixes

FAIL: gcc.dg/tree-ssa/vrp-float-abs-1.c scan-tree-dump-not evrp "link_error"
Comment 4 Andrew Pinski 2024-04-11 21:12:49 UTC
Confirmed then. Maybe you should xfail it for s390 for GCC 14 at least and then unxfail when the patch is committed?
Comment 5 Stefan Schulze Frielinghaus 2024-04-12 08:38:02 UTC
Ok, done in https://gcc.gnu.org/pipermail/gcc-patches/2024-April/649367.html
Comment 6 GCC Commits 2024-08-15 03:29:36 UTC
The master branch has been updated by HaoChen Gui <guihaoc@gcc.gnu.org>:

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

commit r15-2922-gcd0930768ff936b681135bf8873e7f7b796a4ed9
Author: Haochen Gui <guihaoc@gcc.gnu.org>
Date:   Thu Aug 15 11:19:10 2024 +0800

    Value Range: Add range op for builtin isinf
    
    The builtin isinf is not folded at front end if the corresponding optab
    exists.  So the range op for isinf is needed for value range analysis.
    This patch adds range op for builtin isinf.
    
    gcc/
            PR target/114678
            * gimple-range-op.cc (class cfn_isinf): New.
            (op_cfn_isinf): New variables.
            (gimple_range_op_handler::maybe_builtin_call): Handle
            CASE_FLT_FN (BUILT_IN_ISINF).
    
    gcc/testsuite/
            PR target/114678
            * gcc.dg/tree-ssa/range-isinf.c: New test.
            * gcc.dg/tree-ssa/range-sincos.c: Remove xfail for s390.
            * gcc.dg/tree-ssa/vrp-float-abs-1.c: Likewise.
Comment 7 Stefan Schulze Frielinghaus 2024-10-23 10:39:08 UTC
Fixed.