public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Kai Tietz <ktietz70@googlemail.com>
To: Richard Guenther <richard.guenther@gmail.com>
Cc: Kai Tietz <ktietz@redhat.com>, gcc-patches@gcc.gnu.org
Subject: Re: [patch tree-optimization]: Fix for PR/49806
Date: Tue, 09 Aug 2011 09:44:00 -0000	[thread overview]
Message-ID: <CAEwic4bWReVnOzi5YJ80jZxVouSsNCpisqnOqP9TmON5P_yDmw@mail.gmail.com> (raw)
In-Reply-To: <CAFiYyc3Q6spLvqhqpHKJquvsjiMs5nWnEeaH14bU8syh9BOMVA@mail.gmail.com>

Hello,

actual the remaining issue about this PR is that vrp
constructs by range analyzis for bitwise and/or expressions
type-casted results, like ((type) A) op ((type) B), or ((type) A) op CST.
So I've added to simplify_bit_ops_using_rnages the transformation of
  ((type) A) op ((type) B) -> (type) (A op B)
  ((type) A) op CST -> (type) (A op CST'), with CST'=(type-A)

  This first transformation is valid if A has an integral type, TYPE
is of integral kind,
  and type of B has compatible type to type of A.
  The second transformation is valid if A has integral type, TYPE is
of integral kind,
  and CST fits into type of A.

2011-08-09  Kai Tietz  <ktietz@redhat.com>

	PR middle-end/49806
	* tree-vrp.c (simplify_bit_ops_using_ranges): Add
	code for type-cast sinking for bitwise-operations.

        * gcc.dg/tree-ssa/vrp47.c: Remove dom-dump and adjusted
        scan test for vrp result.

Bootstrapped and regression tested for all languages (including Ada
and Obj-C++) on host x86_64-pc-linux-gnu.  Ok for apply?

Regards,
Kai

Index: gcc/gcc/testsuite/gcc.dg/tree-ssa/vrp47.c
===================================================================
--- gcc.orig/gcc/testsuite/gcc.dg/tree-ssa/vrp47.c
+++ gcc/gcc/testsuite/gcc.dg/tree-ssa/vrp47.c
@@ -4,8 +4,8 @@
    jumps when evaluating an && condition.  VRP is not able to optimize
    this.  */
 /* { dg-do compile { target { ! "mips*-*-* s390*-*-*  avr-*-*
mn10300-*-*" } } } */
-/* { dg-options "-O2 -fdump-tree-vrp1 -fdump-tree-dom1" } */
-/* { dg-options "-O2 -fdump-tree-vrp1 -fdump-tree-dom1 -march=i586" {
target { i?86-*-* && ilp32 } } } */
+/* { dg-options "-O2 -fdump-tree-vrp1" } */
+/* { dg-options "-O2 -fdump-tree-vrp1 -march=i586" { target {
i?86-*-* && ilp32 } } } */

 int h(int x, int y)
 {
@@ -37,12 +37,10 @@ int f(int x)
 /* { dg-final { scan-tree-dump-times "\[xy\]\[^ \]* !=" 0 "vrp1" } } */

 /* This one needs more copy propagation that only happens in dom1.  */
-/* { dg-final { scan-tree-dump-times "x\[^ \]* & y" 1 "dom1" } } */
-/* { dg-final { scan-tree-dump-times "x\[^ \]* & y" 1 "vrp1" { xfail
*-*-* } } } */
+/* { dg-final { scan-tree-dump-times "x\[^ \]* & y" 1 "vrp1" } } */

 /* These two are fully simplified by VRP.  */
 /* { dg-final { scan-tree-dump-times "x\[^ \]* \[|\] y" 1 "vrp1" } } */
 /* { dg-final { scan-tree-dump-times "x\[^ \]* \\^ 1" 1 "vrp1" } } */

 /* { dg-final { cleanup-tree-dump "vrp1" } } */
-/* { dg-final { cleanup-tree-dump "dom1" } } */
Index: gcc/gcc/tree-vrp.c
===================================================================
--- gcc.orig/gcc/tree-vrp.c
+++ gcc/gcc/tree-vrp.c
@@ -6968,15 +6968,63 @@ simplify_abs_using_ranges (gimple stmt)
 static bool
 simplify_bit_ops_using_ranges (gimple_stmt_iterator *gsi, gimple stmt)
 {
+  gimple def0, def1;
   tree op0 = gimple_assign_rhs1 (stmt);
   tree op1 = gimple_assign_rhs2 (stmt);
-  tree op = NULL_TREE;
+  tree op = NULL_TREE, nop0 = NULL_TREE, nop1 = NULL_TREE;
   value_range_t vr0 = { VR_UNDEFINED, NULL_TREE, NULL_TREE, NULL };
   value_range_t vr1 = { VR_UNDEFINED, NULL_TREE, NULL_TREE, NULL };
   double_int may_be_nonzero0, may_be_nonzero1;
   double_int must_be_nonzero0, must_be_nonzero1;
   double_int mask;

+  def0 = TREE_CODE (op0) == SSA_NAME ? SSA_NAME_DEF_STMT (op0) : NULL;
+  def1 = TREE_CODE (op1) == SSA_NAME ? SSA_NAME_DEF_STMT (op1) : NULL;
+  if (def0 && is_gimple_assign (def0))
+      nop0 = gimple_assign_rhs1 (def0);
+  if (def1 && is_gimple_assign (def1))
+      nop1 = gimple_assign_rhs1 (def1);
+
+  /* Simplify ((type) X) op ((type) Y) -> (type) (X op Y), if X and Y have
+     compatible integral types.  */
+  if (nop0 != NULL_TREE && nop1 != NULL_TREE
+      && CONVERT_EXPR_CODE_P (gimple_assign_rhs_code (def0))
+      && CONVERT_EXPR_CODE_P (gimple_assign_rhs_code (def1))
+      && INTEGRAL_TYPE_P (TREE_TYPE (nop0))
+      && types_compatible_p (TREE_TYPE (nop0), TREE_TYPE (nop1)))
+    {
+      gimple newop;
+      tree tem = create_tmp_reg (TREE_TYPE (nop0), NULL);
+      newop = gimple_build_assign_with_ops (gimple_assign_rhs_code (stmt),
+					    tem, nop0, nop1);
+      tem = make_ssa_name (tem, newop);
+      gimple_assign_set_lhs (newop, tem);
+      gsi_insert_before (gsi, newop, GSI_SAME_STMT);
+      update_stmt (newop);
+      gimple_assign_set_rhs_with_ops (gsi, NOP_EXPR, tem, NULL_TREE);
+      return true;
+    }
+  /* Simplify ((type) X) op CST -> (type) (X op (type-X) CST), if X has
+     an integral types.  Additiona CST has to fit into type of X.  */
+  else if (nop0 != NULL_TREE && TREE_CODE (op1) == INTEGER_CST
+           && CONVERT_EXPR_CODE_P (gimple_assign_rhs_code (def0))
+           && INTEGRAL_TYPE_P (TREE_TYPE (nop0))
+           && int_fits_type_p (op1, TREE_TYPE (nop0)))
+    {
+      tree nop0 = gimple_assign_rhs1 (def0);
+      tree nop1 = fold_convert (TREE_TYPE (nop0), op1);
+      gimple newop;
+      tree tem = create_tmp_reg (TREE_TYPE (nop0), NULL);
+      newop = gimple_build_assign_with_ops (gimple_assign_rhs_code (stmt),
+					    tem, nop0, nop1);
+      tem = make_ssa_name (tem, newop);
+      gimple_assign_set_lhs (newop, tem);
+      gsi_insert_before (gsi, newop, GSI_SAME_STMT);
+      update_stmt (newop);
+      gimple_assign_set_rhs_with_ops (gsi, NOP_EXPR, tem, NULL_TREE);
+      return true;
+    }
+
   if (TREE_CODE (op0) == SSA_NAME)
     vr0 = *(get_value_range (op0));
   else if (is_gimple_min_invariant (op0))

  reply	other threads:[~2011-08-09  8:23 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <2141181079.338186.1311940751732.JavaMail.root@zmail06.collab.prod.int.phx2.redhat.com>
2011-07-29 12:24 ` Kai Tietz
2011-08-01 12:16   ` Richard Guenther
2011-08-09  9:44     ` Kai Tietz [this message]
2011-08-09 11:48       ` Kai Tietz
2011-11-18 13:11       ` Kai Tietz
2011-11-07 10:59     ` Kai Tietz

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=CAEwic4bWReVnOzi5YJ80jZxVouSsNCpisqnOqP9TmON5P_yDmw@mail.gmail.com \
    --to=ktietz70@googlemail.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=ktietz@redhat.com \
    --cc=richard.guenther@gmail.com \
    /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).