public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Aldy Hernandez <aldyh@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r12-3328] Improve support for IMAGPART_EXPR and REALPART_EXPR in ranger.
Date: Fri,  3 Sep 2021 13:31:30 +0000 (GMT)	[thread overview]
Message-ID: <20210903133130.348103848405@sourceware.org> (raw)

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

commit r12-3328-gbccf4b88e184e925ee2d7931e4cf09704f1c3932
Author: Aldy Hernandez <aldyh@redhat.com>
Date:   Fri Sep 3 09:58:29 2021 +0200

    Improve support for IMAGPART_EXPR and REALPART_EXPR in ranger.
    
    Currently we adjust statements containing an IMAGPART_EXPR if the
    defining statement was one of a few built-ins known to return boolean
    types.  We can also adjust statements for both IMAGPART_EXPR and
    REALPART_EXPR where the defining statement is a constant.
    
    This patch adds such support, and cleans up the code a bit.
    
    Tested on x86-64 Linux.
    
    gcc/ChangeLog:
    
            * gimple-range-fold.cc (adjust_imagpart_expr): Move from
            gimple_range_adjustment.  Add support for constants.
            (adjust_realpart_expr): New.
            (gimple_range_adjustment): Move IMAGPART_EXPR code to
            adjust_imagpart_expr.
            * range-op.cc (integral_table::integral_table): Add entry for
            REALPART_CST.

Diff:
---
 gcc/gimple-range-fold.cc | 110 ++++++++++++++++++++++++++++++++---------------
 gcc/range-op.cc          |   1 +
 2 files changed, 77 insertions(+), 34 deletions(-)

diff --git a/gcc/gimple-range-fold.cc b/gcc/gimple-range-fold.cc
index 94dd042721e..8be6d473f82 100644
--- a/gcc/gimple-range-fold.cc
+++ b/gcc/gimple-range-fold.cc
@@ -369,14 +369,78 @@ adjust_pointer_diff_expr (irange &res, const gimple *diff_stmt)
     }
 }
 
+// Adjust the range for an IMAGPART_EXPR.
+
+static void
+adjust_imagpart_expr (irange &res, const gimple *stmt)
+{
+  tree name = TREE_OPERAND (gimple_assign_rhs1 (stmt), 0);
+
+  if (TREE_CODE (name) != SSA_NAME || !SSA_NAME_DEF_STMT (name))
+    return;
+
+  gimple *def_stmt = SSA_NAME_DEF_STMT (name);
+  if (is_gimple_call (def_stmt) && gimple_call_internal_p (def_stmt))
+    {
+      switch (gimple_call_internal_fn (def_stmt))
+	{
+	case IFN_ADD_OVERFLOW:
+	case IFN_SUB_OVERFLOW:
+	case IFN_MUL_OVERFLOW:
+	case IFN_ATOMIC_COMPARE_EXCHANGE:
+	  {
+	    int_range<2> r;
+	    r.set_varying (boolean_type_node);
+	    tree type = TREE_TYPE (gimple_assign_lhs (stmt));
+	    range_cast (r, type);
+	    res.intersect (r);
+	  }
+	default:
+	  break;
+	}
+      return;
+    }
+  if (is_gimple_assign (def_stmt))
+    {
+      tree cst = gimple_assign_rhs1 (def_stmt);
+      if (TREE_CODE (cst) == COMPLEX_CST)
+	{
+	  tree imag = TREE_IMAGPART (cst);
+	  int_range<2> tmp (imag, imag);
+	  res.intersect (tmp);
+	}
+    }
+}
+
+// Adjust the range for a REALPART_EXPR.
+
+static void
+adjust_realpart_expr (irange &res, const gimple *stmt)
+{
+  tree name = TREE_OPERAND (gimple_assign_rhs1 (stmt), 0);
+
+  if (TREE_CODE (name) != SSA_NAME)
+    return;
+
+  gimple *def_stmt = SSA_NAME_DEF_STMT (name);
+  if (!SSA_NAME_DEF_STMT (name))
+    return;
+
+  if (is_gimple_assign (def_stmt))
+    {
+      tree cst = gimple_assign_rhs1 (def_stmt);
+      if (TREE_CODE (cst) == COMPLEX_CST)
+	{
+	  tree imag = TREE_REALPART (cst);
+	  int_range<2> tmp (imag, imag);
+	  res.intersect (tmp);
+	}
+    }
+}
+
 // This function looks for situations when walking the use/def chains
 // may provide additonal contextual range information not exposed on
-// this statement.  Like knowing the IMAGPART return value from a
-// builtin function is a boolean result.
-
-// We should rework how we're called, as we have an op_unknown entry
-// for IMAGPART_EXPR and POINTER_DIFF_EXPR in range-ops just so this
-// function gets called.
+// this statement.
 
 static void
 gimple_range_adjustment (irange &res, const gimple *stmt)
@@ -388,34 +452,12 @@ gimple_range_adjustment (irange &res, const gimple *stmt)
       return;
 
     case IMAGPART_EXPR:
-      {
-	tree name = TREE_OPERAND (gimple_assign_rhs1 (stmt), 0);
-	if (TREE_CODE (name) == SSA_NAME)
-	  {
-	    gimple *def_stmt = SSA_NAME_DEF_STMT (name);
-	    if (def_stmt && is_gimple_call (def_stmt)
-		&& gimple_call_internal_p (def_stmt))
-	      {
-		switch (gimple_call_internal_fn (def_stmt))
-		  {
-		  case IFN_ADD_OVERFLOW:
-		  case IFN_SUB_OVERFLOW:
-		  case IFN_MUL_OVERFLOW:
-		  case IFN_ATOMIC_COMPARE_EXCHANGE:
-		    {
-		      int_range<2> r;
-		      r.set_varying (boolean_type_node);
-		      tree type = TREE_TYPE (gimple_assign_lhs (stmt));
-		      range_cast (r, type);
-		      res.intersect (r);
-		    }
-		  default:
-		    break;
-		  }
-	      }
-	  }
-	break;
-      }
+      adjust_imagpart_expr (res, stmt);
+      return;
+
+    case REALPART_EXPR:
+      adjust_realpart_expr (res, stmt);
+      return;
 
     default:
       break;
diff --git a/gcc/range-op.cc b/gcc/range-op.cc
index 56eccf471a2..fee0e834c23 100644
--- a/gcc/range-op.cc
+++ b/gcc/range-op.cc
@@ -4017,6 +4017,7 @@ integral_table::integral_table ()
   set (PAREN_EXPR, op_identity);
   set (OBJ_TYPE_REF, op_identity);
   set (IMAGPART_EXPR, op_unknown);
+  set (REALPART_EXPR, op_unknown);
   set (POINTER_DIFF_EXPR, op_unknown);
   set (ABS_EXPR, op_abs);
   set (ABSU_EXPR, op_absu);


                 reply	other threads:[~2021-09-03 13:31 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210903133130.348103848405@sourceware.org \
    --to=aldyh@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).