public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Richard Biener <rguenther@suse.de>
To: Li Jia He <helijia@linux.ibm.com>
Cc: Andrew Pinski <pinskia@gmail.com>, Jeff Law <law@redhat.com>,
	    GCC Patches <gcc-patches@gcc.gnu.org>,
	    Segher Boessenkool <segher@kernel.crashing.org>,
	wschmidt@linux.ibm.com,     Martin Liska <mliska@suse.de>
Subject: Re: [PATCH][middle-end/88784] Middle end is missing some optimizations about unsigned
Date: Thu, 05 Sep 2019 13:01:00 -0000	[thread overview]
Message-ID: <nycvar.YFH.7.76.1909051446520.5566@zhemvz.fhfr.qr> (raw)
In-Reply-To: <845bc280-7bd6-509b-3830-4ebde50f1b20@linux.ibm.com>

On Tue, 16 Jul 2019, Li Jia He wrote:

> Hi,
> 
>   I made some changes based on the recommendations. Would you like to
>   help me to see it again ? Sorry, it took so long time to provide the
>   patch.
> 
>   Note: 1. I keep the code for and_comparisons_1 and or_comparisons_1.
> 	The reason is that I did not found a good way to handle the
> 	optimization of '((x CODE1 y) AND (x CODE2 y))' in match.pd.
> 	Maybe I missing some important information about match.pd.
> 	2. The gimple_resimplify2 function is not used.  Since stmt1,
> 	stmt2, lhs1 and lhs2 are allocated on the stack, Is there a
> 	question with the value on the stack as the return value ?
> 	I may have misunderstood Richard's intention.

Sorry for the delay in reviewing.

Rather than exporting gimple_set_code and gimple_size I'd split
out a

void
gimple_init (gimple *, enum gimple_code code, unsigned nops);

from gimple_alloc (changing that to GC allocate not cleared
memory) doing all of the actual initialization.  Then the
allocation would go like

gimple *stmt1 = (gimple *)XALLOCAVEC (char, gimple_size (GIMPLE_ASSIGN, 
3));
gimple_init (stmt1, GIMPLE_ASSIGN, 3);

with an overload for gimple_size to account for # of ops.

+  /* Allocate SSA names(lhs1) on the stack.  */
+  tree lhs1 = XALLOCA (tree_node);

you can use (tree) XALLOCA (tree_ssa_name) here

+  /* Call the interface function of match.pd to simplify the expression.  
*/
+  tree t = gimple_simplify (code, boolean_type_node, gimple_assign_lhs 
(stmt1),
+                           gimple_assign_lhs (stmt2), NULL,
+                           follow_all_ssa_edges);
+
+  if (t)

As I told Martin offline the appropriate function to use is

 You'd do

  gimple_match_op op (gimple_match_cond::UNCOND, code,
         boolean_type_node, gimple_assign_lhs (stmt1),
gimple_assign_lhs (stmt2));
  if (op->resimplify (NULL, follow_all_ssa_edges))
   {
      if (gimple_simplified_result_is_gimple_val (res_op))
        .. got a constant or SSA name ..
      else if (res_op->code.is_tree_code ()
                 && TREE_CODE_CLASS ((tree_code)res_op->code)) ==
tcc_comparison)
        ... got a comparison res_op->op[0] res_op->code res_op->op[1] ...

so you get the outermost expression back decomposed.

Otherwise with you passing NULL as the gimple_seq you'll miss quite
some simplification cases.

You also have to watch out for the result containing the LHS of one
of your temporary stmts.

+  if (tree t = maybe_fold_comparisons_from_match_pd (BIT_AND_EXPR, code1, 
op1a,
+                                                    op1b, code2, op2a, 
op2b))
+    return t;
+
+  if (tree t = maybe_fold_comparisons_from_match_pd (BIT_AND_EXPR, code2, 
op2a,
+                                                    op2b, code1, op1a, 
op1b))
+    return t;

with match.pd rules you shouldn't need to call this twice, once with
swapped operands.

Otherwise this first patch looks like what I'd have done and we
can build upon it.

Not sure if you or Martin wants to improve it according to my
comments.

Thanks,
Richard.

  parent reply	other threads:[~2019-09-05 13:01 UTC|newest]

Thread overview: 56+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-06-27  6:12 Li Jia He
2019-06-27 15:48 ` Jeff Law
2019-06-28  4:55   ` Li Jia He
2019-06-28 17:02     ` Andrew Pinski
2019-07-01  7:31       ` Richard Biener
2019-07-02  7:41         ` Li Jia He
2019-07-02  8:09           ` Richard Biener
2019-07-02  8:51             ` Richard Biener
2019-07-16  6:54               ` Li Jia He
2019-08-30 11:16                 ` Martin Liška
2019-09-05 13:01                 ` Richard Biener [this message]
2019-09-05 18:47                   ` Martin Liška
2019-09-06  8:01                     ` Richard Biener
2019-09-06  8:04                       ` Martin Liška
2019-09-06 10:13                   ` [PATCH 1/2] Auto-generate maybe_fold_and/or_comparisons from match.pd Martin Liška
2019-09-09 12:23                     ` Martin Liška
2019-09-09 13:10                       ` Richard Biener
2019-09-09 13:40                         ` Martin Liška
2019-09-09 13:42                           ` Richard Biener
2019-09-09 13:45                             ` Martin Liška
2019-09-09 13:55                               ` Richard Biener
2019-09-10  7:40                                 ` Martin Liška
     [not found]                                   ` <ba4ec7b3-0d0d-ca7b-b2d9-2f34478a23f4@linux.ibm.com>
2019-09-11  8:51                                     ` Martin Liška
2019-09-11 11:16                                   ` Martin Liška
2019-09-11 12:23                                     ` Richard Biener
2019-09-11 13:55                                       ` Martin Liška
2019-09-09 13:10                       ` Marc Glisse
2019-09-09 13:30                         ` Martin Liška
2019-09-09 13:39                           ` Richard Biener
2019-09-09 12:24                     ` [PATCH 4/5] Rewrite first part of or_comparisons_1 into match.pd Martin Liška
2019-09-11 11:19                       ` Martin Liška
2019-09-11 13:57                         ` Martin Liška
2019-09-16  9:05                           ` Richard Biener
2019-09-09 12:24                     ` [PATCH 3/5] Rewrite part of and_comparisons_1 " Martin Liška
2019-09-09 13:41                       ` Martin Liška
2019-09-10  7:41                         ` Martin Liška
2019-09-10 11:19                           ` Marc Glisse
2019-09-11  8:27                             ` Martin Liška
2019-09-11 11:18                               ` Martin Liška
2019-09-11 12:44                                 ` Richard Biener
2019-09-11 13:19                                   ` Martin Liška
2019-09-11 13:57                                     ` Martin Liška
2019-09-16  9:04                                       ` Richard Biener
2019-09-16 13:47                                         ` Martin Liška
2019-09-10  8:52                         ` Bernhard Reutner-Fischer
2019-09-11  8:11                           ` Martin Liška
2019-09-09 12:25                     ` [PATCH 5/5] Rewrite second part of or_comparisons_1 " Martin Liška
2019-09-11 11:19                       ` Martin Liška
2019-09-11 13:57                         ` Martin Liška
2019-09-16  9:07                           ` Richard Biener
2019-09-16 14:23                             ` Martin Liška
2019-09-05 13:17                 ` [PATCH][middle-end/88784] Middle end is missing some optimizations about unsigned Richard Biener
2019-09-05 18:47                   ` Martin Liška
2019-09-06 10:14                   ` [PATCH 2/2] Fix PR88784, middle " Martin Liška
2019-09-11 13:08                     ` Richard Biener
2019-09-11 13:56                       ` Martin Liška

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=nycvar.YFH.7.76.1909051446520.5566@zhemvz.fhfr.qr \
    --to=rguenther@suse.de \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=helijia@linux.ibm.com \
    --cc=law@redhat.com \
    --cc=mliska@suse.de \
    --cc=pinskia@gmail.com \
    --cc=segher@kernel.crashing.org \
    --cc=wschmidt@linux.ibm.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).