* [PATCH GCC]Try to fold (long)(A-B) into (long)A - (long)B for canonicalization in tree affine
@ 2015-09-02 3:48 Bin Cheng
2015-09-02 12:29 ` Richard Biener
0 siblings, 1 reply; 2+ messages in thread
From: Bin Cheng @ 2015-09-02 3:48 UTC (permalink / raw)
To: gcc-patches
[-- Attachment #1: Type: text/plain, Size: 694 bytes --]
Hi,
Generally we don't try to fold (long)(A-B) into (long)A - (long)B because it
results in more operations. On the other hand, this fold is wanted when we
want to explore as many canonical opportunities as possible. Tree affine is
definitely such a place. This patch supports this in
tree_to_aff_combination, so it can produce canonical affines rather than
stupid expressions like "&arr + (sizetype) (t_4(D) + t_4(D)) * 4 -
(sizetype)t_4(D) * 8".
Bootstrap and test on x86_64 and aarch64 along with other patches. Is it
OK?
2015-08-31 Bin Cheng <bin.cheng@arm.com>
* tree-affine.c (tree_to_aff_combination): Try to fold (long)(A-B)
by adding CASE_CONVERT support.
[-- Attachment #2: pr66388_2-20150824.txt --]
[-- Type: text/plain, Size: 1350 bytes --]
Index: gcc/tree-affine.c
===================================================================
--- gcc/tree-affine.c (revision 227163)
+++ gcc/tree-affine.c (working copy)
@@ -377,6 +377,37 @@ tree_to_aff_combination (tree expr, tree type, aff
aff_combination_add (comb, &tmp);
return;
+ CASE_CONVERT:
+ {
+ tree outer_type = TREE_TYPE (expr);
+ tree inner = TREE_OPERAND (expr, 0);
+ tree inner_type = TREE_TYPE (inner);
+
+ /* Fold will not canonicalize (long)(A-B) to (long)A - (long)B
+ because it has more operations. We perform this fold in
+ affine to explore more canonicalization opportunities. */
+ if ((TREE_CODE (inner) == PLUS_EXPR
+ || TREE_CODE (inner) == MINUS_EXPR)
+ && TREE_CODE (inner_type) == INTEGER_TYPE
+ && TREE_CODE (outer_type) == INTEGER_TYPE
+ && TYPE_PRECISION (outer_type) > TYPE_PRECISION (inner_type)
+ && TYPE_OVERFLOW_UNDEFINED (inner_type))
+ {
+ tree op0 = TREE_OPERAND (inner, 0);
+ tree op1 = TREE_OPERAND (inner, 1);
+
+ tree_to_aff_combination (fold_build2 (TREE_CODE (inner),
+ outer_type,
+ fold_convert (outer_type,
+ op0),
+ fold_convert (outer_type,
+ op1)),
+ type, comb);
+ return;
+ }
+ }
+ break;
+
default:
break;
}
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH GCC]Try to fold (long)(A-B) into (long)A - (long)B for canonicalization in tree affine
2015-09-02 3:48 [PATCH GCC]Try to fold (long)(A-B) into (long)A - (long)B for canonicalization in tree affine Bin Cheng
@ 2015-09-02 12:29 ` Richard Biener
0 siblings, 0 replies; 2+ messages in thread
From: Richard Biener @ 2015-09-02 12:29 UTC (permalink / raw)
To: Bin Cheng; +Cc: GCC Patches
On Wed, Sep 2, 2015 at 5:48 AM, Bin Cheng <bin.cheng@arm.com> wrote:
> Hi,
> Generally we don't try to fold (long)(A-B) into (long)A - (long)B because it
> results in more operations. On the other hand, this fold is wanted when we
> want to explore as many canonical opportunities as possible. Tree affine is
> definitely such a place. This patch supports this in
> tree_to_aff_combination, so it can produce canonical affines rather than
> stupid expressions like "&arr + (sizetype) (t_4(D) + t_4(D)) * 4 -
> (sizetype)t_4(D) * 8".
>
> Bootstrap and test on x86_64 and aarch64 along with other patches. Is it
> OK?
Hmm, but we also do code-gen from affine combinations and we can't reverse
that operation. So eventually we end up generating an expensive wide plus/minus
instead of a narrow one and an extension.
But I see we already do this transform, just only for constant 2nd operand and
in aff_combination_expand. Any reason you chose tree_to_aff_combination
only? I suppose if we need it in both places it would be good to factor it out
to a helper function.
Richard.
>
> 2015-08-31 Bin Cheng <bin.cheng@arm.com>
>
> * tree-affine.c (tree_to_aff_combination): Try to fold (long)(A-B)
> by adding CASE_CONVERT support.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2015-09-02 12:29 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-09-02 3:48 [PATCH GCC]Try to fold (long)(A-B) into (long)A - (long)B for canonicalization in tree affine Bin Cheng
2015-09-02 12:29 ` Richard Biener
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).