From: Kai Tietz <ktietz70@googlemail.com>
To: Richard Guenther <richard.guenther@gmail.com>
Cc: GCC Patches <gcc-patches@gcc.gnu.org>
Subject: Re: [patch tree-ssa-reassoc.c]: Better reassoication for comparision and boolean-logic
Date: Thu, 19 May 2011 15:51:00 -0000 [thread overview]
Message-ID: <BANLkTim+jQ9N56pC8Ke2Q3WeAi=VOnEvVw@mail.gmail.com> (raw)
In-Reply-To: <BANLkTimM_BZJKXirZg1DwGM=h7qJMKNxkQ@mail.gmail.com>
2011/5/19 Richard Guenther <richard.guenther@gmail.com>:
> On Thu, May 19, 2011 at 3:30 PM, Kai Tietz <ktietz70@googlemail.com> wrote:
>> 2011/5/19 Richard Guenther <richard.guenther@gmail.com>:
>>> On Thu, May 19, 2011 at 3:08 PM, Kai Tietz <ktietz70@googlemail.com> wrote:
>>>> 2011/5/19 Richard Guenther <richard.guenther@gmail.com>:
>>>>> On Thu, May 19, 2011 at 2:59 PM, Kai Tietz <ktietz70@googlemail.com> wrote:
>>>>>> 2011/5/19 Richard Guenther <richard.guenther@gmail.com>:
>>>>>>> On Thu, May 19, 2011 at 2:48 PM, Kai Tietz <ktietz70@googlemail.com> wrote:
>>>>>>>> Hello,
>>>>>>>>
>>>>>>>> This patch improves reassociation folding for comparision. It expands
>>>>>>>> expressions within binary-AND/OR expression like (X | Y) == 0 to (X ==
>>>>>>>> 0 && Y == 0)
>>>>>>>> and (X | Y) != 0 to (X != 0 || Y != 0). This is necessary to allow
>>>>>>>> better reassociation
>>>>>>>> on weak pre-folded logical expressions. This unfolding gets undone
>>>>>>>> anyway later by pass,
>>>>>>>> so no disadvantage gets introduced.
>>>>>>>> Also while going through BB-list, it tries to do some little
>>>>>>>> type-sinking for SSA sequences
>>>>>>>> like "D1 = (type) bool1; D2 = (type) bool2; D3 = D1 & D2;' to 'D1 =
>>>>>>>> bool1 & bool2; D2 = (type) D1;'.
>>>>>>>> This folding has the advantage to see better through intermediate
>>>>>>>> results with none-boolean type.
>>>>>>>> The function eliminate_redundant_comparison () got reworded so, that
>>>>>>>> doesn't break in all cases.
>>>>>>>> It now continues to find duplicates and tries to find inverse variant
>>>>>>>> (folded to constant). By this
>>>>>>>> change we don't combine possible weak optimizations too fast, before
>>>>>>>> we can find and handle
>>>>>>>> inverse or duplicates.
>>>>>>>
>>>>>>> sinking casting belongs not here but instead to tree-ssa-forwprop.
>>>>>>> I'm not sure that a != 0 | b != 0 is the better canonical variant than
>>>>>>> a | b != 0 though.
>>>>>>>
>>>>>>> is_boolean_compatible_type_p looks like a strange remanent.
>>>>>>>
>>>>>>> Richard.
>>>>>>
>>>>>> Well, a | b != 0 is for sure more optimal, but for reassociation we
>>>>>> need to see the unfolded variant temporary. This is necessary as
>>>>>> fold-const can't see through SSA statements. But this kind of
>>>>>> expansion should be reversed then by pass to the form (a | b) != 0
>>>>>> back.
>>>>>
>>>>> ? fold-const shouldn't deal with this at all as we are in gimple and in
>>>>> SSA form. Surely re-association comes to play only with chains of
>>>>> the above with more than two operands.
>>>>>
>>>>> Richard.
>>>>>
>>>>>>
>>>>>> Regards,
>>>>>> Kai
>>>>>>
>>>>>
>>>>
>>>> The issue you can see by testcase binop_tor4.c, as here are the
>>>> intermediate variables d and e (with int type) are destroying the
>>>> reassociation pass. This testcase for example needs this sinking.
>>>
>>> hoisting would work equally well
>>
>> Well, but just if then all operands in combined BIT_AND/OR block are
>> getting hoisting. And well, there might be still some cases where we
>> wouldn't find the equivalent. As hoisting leads to following
>> sequences, eg:
>>
>> D1 = a != 0;
>> D2 = b != 0;
>> D3 = a == 0;
>> D4 = b == 0;
>> D5 = (long) D1
>> D6 = (long) D2
>> D7 = (long) D3
>> D8 = (long) D4
>> D9 = D5 & D6;
>> D10 = D8 & D9
>> D11 = D9 & D10;
>>
>> which means that comparision folding will never will happen as the
>> statement passed to fold algorithm is a cast to a comparison and not
>> the comparison itself. So sinking looks more sane IMHO.
>
> The above is what you do.
No, I don't do this. Please see function sink_cast_and_expand function in patch.
if (gimple_assign_cast_p (s1)
&& gimple_assign_cast_p (s2)
&& is_boolean_compatible_type_p (TREE_TYPE (gimple_assign_rhs1 (s1)))
&& is_boolean_compatible_type_p (TREE_TYPE (gimple_assign_rhs1 (s2)))
&& useless_type_conversion_p (TREE_TYPE (gimple_assign_rhs1 (s1)),
TREE_TYPE (gimple_assign_rhs1 (s2))))
{
gimple_stmt_iterator gsi;
gimple sum;
tree op1a, op1b, tmpvar;
tmpvar = create_tmp_reg (TREE_TYPE (gimple_assign_rhs1 (s1)), NULL);
add_referenced_var (tmpvar);
sum = build_and_add_sum (tmpvar, gimple_assign_rhs1 (s1),
gimple_assign_rhs1 (s2), code);
op1 = gimple_get_lhs (sum);
op1 = fold_convert (type, op1);
op1a = gimple_assign_rhs1 (stmt);
op1b = gimple_assign_rhs2 (stmt);
gsi = gsi_for_stmt (stmt);
gimple_assign_set_rhs_from_tree (&gsi, op1);
update_stmt (stmt);
remove_visited_stmt_chain (op1a);
remove_visited_stmt_chain (op1b);
ret = true;
}
The none-boolean cast get moved outer, not inner.
Regards,
Kai
next prev parent reply other threads:[~2011-05-19 13:37 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-05-19 13:11 Kai Tietz
2011-05-19 13:17 ` Jakub Jelinek
2011-05-19 13:20 ` Kai Tietz
2011-05-19 13:30 ` Richard Guenther
2011-05-19 13:32 ` Kai Tietz
2011-05-19 13:38 ` Richard Guenther
2011-05-19 13:40 ` Kai Tietz
2011-05-19 13:51 ` Richard Guenther
2011-05-19 15:28 ` Kai Tietz
2011-05-19 15:41 ` Richard Guenther
2011-05-19 15:51 ` Kai Tietz [this message]
2011-05-19 16:16 ` Richard Guenther
2011-05-19 17:23 ` Kai Tietz
2011-05-19 19:20 ` Kai Tietz
2011-05-20 10:37 ` Richard Guenther
2011-05-21 0:12 ` Kai Tietz
2011-05-21 16:17 ` Richard Guenther
2011-05-19 13:37 ` Richard Guenther
2011-05-20 3:45 ` Eric Botcazou
2011-05-20 4:10 ` 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='BANLkTim+jQ9N56pC8Ke2Q3WeAi=VOnEvVw@mail.gmail.com' \
--to=ktietz70@googlemail.com \
--cc=gcc-patches@gcc.gnu.org \
--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).