* Remove match.pd pattern dups in favor of using :c
@ 2016-06-01 10:29 Richard Biener
2016-06-01 10:37 ` Alexander Monakov
0 siblings, 1 reply; 5+ messages in thread
From: Richard Biener @ 2016-06-01 10:29 UTC (permalink / raw)
To: gcc-patches
The following uses the now available possibility to use :c on relational
compares.
Bootstrapped and tested on x86_64-unknown-linux-gnu, applied.
Richard.
2016-06-01 Richard Biener <rguenther@suse.de>
* match.pd ((A & B) - (A & ~B) -> B - (A ^ B)): Add missing :c.
(relational patterns): Use :c to avoid pattern duplications.
Index: gcc/match.pd
===================================================================
--- gcc/match.pd (revision 236877)
+++ gcc/match.pd (working copy)
@@ -493,7 +493,7 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
/* Fold (A & B) - (A & ~B) into B - (A ^ B). */
(simplify
- (minus (bit_and:s @0 @1) (bit_and:cs @0 (bit_not @1)))
+ (minus (bit_and:cs @0 @1) (bit_and:cs @0 (bit_not @1)))
(minus @1 (bit_xor @0 @1)))
/* Simplify (X & ~Y) | (~X & Y) -> X ^ Y. */
@@ -2584,18 +2606,7 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
(for cmp (lt le ge gt)
out (gt gt le le)
(simplify
- (cmp (plus@2 @0 INTEGER_CST@1) @0)
- (if (TYPE_UNSIGNED (TREE_TYPE (@0))
- && TYPE_OVERFLOW_WRAPS (TREE_TYPE (@0))
- && wi::ne_p (@1, 0)
- && single_use (@2))
- (out @0 { wide_int_to_tree (TREE_TYPE (@0), wi::max_value
- (TYPE_PRECISION (TREE_TYPE (@0)), UNSIGNED) - @1); }))))
-/* A CMP A + CST -> A CMP' CST' */
-(for cmp (gt ge le lt)
- out (gt gt le le)
- (simplify
- (cmp @0 (plus@2 @0 INTEGER_CST@1))
+ (cmp:c (plus@2 @0 INTEGER_CST@1) @0)
(if (TYPE_UNSIGNED (TREE_TYPE (@0))
&& TYPE_OVERFLOW_WRAPS (TREE_TYPE (@0))
&& wi::ne_p (@1, 0)
@@ -2608,35 +2619,19 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
expects the long form, so we restrict the transformation for now. */
(for cmp (gt le)
(simplify
- (cmp (minus@2 @0 @1) @0)
+ (cmp:c (minus@2 @0 @1) @0)
(if (single_use (@2)
&& ANY_INTEGRAL_TYPE_P (TREE_TYPE (@0))
&& TYPE_UNSIGNED (TREE_TYPE (@0))
&& TYPE_OVERFLOW_WRAPS (TREE_TYPE (@0)))
(cmp @1 @0))))
-(for cmp (lt ge)
- (simplify
- (cmp @0 (minus@2 @0 @1))
- (if (single_use (@2)
- && ANY_INTEGRAL_TYPE_P (TREE_TYPE (@0))
- && TYPE_UNSIGNED (TREE_TYPE (@0))
- && TYPE_OVERFLOW_WRAPS (TREE_TYPE (@0)))
- (cmp @0 @1))))
/* Testing for overflow is unnecessary if we already know the result. */
-/* A < A - B */
-(for cmp (lt ge)
- out (ne eq)
- (simplify
- (cmp @0 (realpart (IFN_SUB_OVERFLOW@2 @0 @1)))
- (if (TYPE_UNSIGNED (TREE_TYPE (@0))
- && types_match (TREE_TYPE (@0), TREE_TYPE (@1)))
- (out (imagpart @2) { build_zero_cst (TREE_TYPE (@0)); }))))
/* A - B > A */
(for cmp (gt le)
out (ne eq)
(simplify
- (cmp (realpart (IFN_SUB_OVERFLOW@2 @0 @1)) @0)
+ (cmp:c (realpart (IFN_SUB_OVERFLOW@2 @0 @1)) @0)
(if (TYPE_UNSIGNED (TREE_TYPE (@0))
&& types_match (TREE_TYPE (@0), TREE_TYPE (@1)))
(out (imagpart @2) { build_zero_cst (TREE_TYPE (@0)); }))))
@@ -2644,15 +2639,7 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
(for cmp (lt ge)
out (ne eq)
(simplify
- (cmp (realpart (IFN_ADD_OVERFLOW:c@2 @0 @1)) @0)
- (if (TYPE_UNSIGNED (TREE_TYPE (@0))
- && types_match (TREE_TYPE (@0), TREE_TYPE (@1)))
- (out (imagpart @2) { build_zero_cst (TREE_TYPE (@0)); }))))
-/* A > A + B */
-(for cmp (gt le)
- out (ne eq)
- (simplify
- (cmp @0 (realpart (IFN_ADD_OVERFLOW:c@2 @0 @1)))
+ (cmp:c (realpart (IFN_ADD_OVERFLOW:c@2 @0 @1)) @0)
(if (TYPE_UNSIGNED (TREE_TYPE (@0))
&& types_match (TREE_TYPE (@0), TREE_TYPE (@1)))
(out (imagpart @2) { build_zero_cst (TREE_TYPE (@0)); }))))
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Remove match.pd pattern dups in favor of using :c
2016-06-01 10:29 Remove match.pd pattern dups in favor of using :c Richard Biener
@ 2016-06-01 10:37 ` Alexander Monakov
2016-06-01 10:39 ` Richard Biener
0 siblings, 1 reply; 5+ messages in thread
From: Alexander Monakov @ 2016-06-01 10:37 UTC (permalink / raw)
To: Richard Biener; +Cc: gcc-patches
Hi,
On Wed, 1 Jun 2016, Richard Biener wrote:
> 2016-06-01 Richard Biener <rguenther@suse.de>
>
> * match.pd ((A & B) - (A & ~B) -> B - (A ^ B)): Add missing :c.
> (relational patterns): Use :c to avoid pattern duplications.
Should the same treatment be applied to recently added IFN_MUL_OVERFLOW
patterns (lines 2625-2643 in current match.pd)?
Thanks.
Alexander
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Remove match.pd pattern dups in favor of using :c
2016-06-01 10:37 ` Alexander Monakov
@ 2016-06-01 10:39 ` Richard Biener
2016-06-10 12:29 ` Alexander Monakov
0 siblings, 1 reply; 5+ messages in thread
From: Richard Biener @ 2016-06-01 10:39 UTC (permalink / raw)
To: Alexander Monakov; +Cc: gcc-patches
On Wed, 1 Jun 2016, Alexander Monakov wrote:
> Hi,
>
> On Wed, 1 Jun 2016, Richard Biener wrote:
> > 2016-06-01 Richard Biener <rguenther@suse.de>
> >
> > * match.pd ((A & B) - (A & ~B) -> B - (A ^ B)): Add missing :c.
> > (relational patterns): Use :c to avoid pattern duplications.
>
> Should the same treatment be applied to recently added IFN_MUL_OVERFLOW
> patterns (lines 2625-2643 in current match.pd)?
Ah, yeah - I missed those appearantly.
Richard.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Remove match.pd pattern dups in favor of using :c
2016-06-01 10:39 ` Richard Biener
@ 2016-06-10 12:29 ` Alexander Monakov
2016-06-10 12:43 ` Richard Biener
0 siblings, 1 reply; 5+ messages in thread
From: Alexander Monakov @ 2016-06-10 12:29 UTC (permalink / raw)
To: Richard Biener; +Cc: gcc-patches
On Wed, 1 Jun 2016, Richard Biener wrote:
> > On Wed, 1 Jun 2016, Richard Biener wrote:
> > > 2016-06-01 Richard Biener <rguenther@suse.de>
> > >
> > > * match.pd ((A & B) - (A & ~B) -> B - (A ^ B)): Add missing :c.
> > > (relational patterns): Use :c to avoid pattern duplications.
> >
> > Should the same treatment be applied to recently added IFN_MUL_OVERFLOW
> > patterns (lines 2625-2643 in current match.pd)?
>
> Ah, yeah - I missed those appearantly.
Here's a patch. Bootstrapped/regtested on x86_64, OK to apply?
Thanks.
Alexander
* match.pd (-1 / B < A): Use :c to avoid pattern duplication.
diff --git a/gcc/match.pd b/gcc/match.pd
index fe71115..7d4beea 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -2626,22 +2626,12 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
&& types_match (TREE_TYPE (@0), TREE_TYPE (@1)))
(out (imagpart @2) { build_zero_cst (TREE_TYPE (@0)); }))))
-/* For unsigned operands, A > -1 / B checks whether A * B would overflow.
+/* For unsigned operands, -1 / B < A checks whether A * B would overflow.
Simplify it to __builtin_mul_overflow (A, B, <unused>). */
-/* -1 / B < A */
(for cmp (lt ge)
out (ne eq)
(simplify
- (cmp (trunc_div:s integer_all_onesp @1) @0)
- (if (TYPE_UNSIGNED (TREE_TYPE (@0)) && !VECTOR_TYPE_P (TREE_TYPE (@0)))
- (with { tree t = TREE_TYPE (@0), cpx = build_complex_type (t); }
- (out (imagpart (IFN_MUL_OVERFLOW:cpx @0 @1)) { build_zero_cst (t); })))))
-
-/* A > -1 / B */
-(for cmp (gt le)
- out (ne eq)
- (simplify
- (cmp @0 (trunc_div:s integer_all_onesp @1))
+ (cmp:c (trunc_div:s integer_all_onesp @1) @0)
(if (TYPE_UNSIGNED (TREE_TYPE (@0)) && !VECTOR_TYPE_P (TREE_TYPE (@0)))
(with { tree t = TREE_TYPE (@0), cpx = build_complex_type (t); }
(out (imagpart (IFN_MUL_OVERFLOW:cpx @0 @1)) { build_zero_cst (t); })))))
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Remove match.pd pattern dups in favor of using :c
2016-06-10 12:29 ` Alexander Monakov
@ 2016-06-10 12:43 ` Richard Biener
0 siblings, 0 replies; 5+ messages in thread
From: Richard Biener @ 2016-06-10 12:43 UTC (permalink / raw)
To: Alexander Monakov; +Cc: gcc-patches
On Fri, 10 Jun 2016, Alexander Monakov wrote:
> On Wed, 1 Jun 2016, Richard Biener wrote:
> > > On Wed, 1 Jun 2016, Richard Biener wrote:
> > > > 2016-06-01 Richard Biener <rguenther@suse.de>
> > > >
> > > > * match.pd ((A & B) - (A & ~B) -> B - (A ^ B)): Add missing :c.
> > > > (relational patterns): Use :c to avoid pattern duplications.
> > >
> > > Should the same treatment be applied to recently added IFN_MUL_OVERFLOW
> > > patterns (lines 2625-2643 in current match.pd)?
> >
> > Ah, yeah - I missed those appearantly.
>
> Here's a patch. Bootstrapped/regtested on x86_64, OK to apply?
Ok.
Thanks,
Richard.
> Thanks.
> Alexander
>
> * match.pd (-1 / B < A): Use :c to avoid pattern duplication.
>
> diff --git a/gcc/match.pd b/gcc/match.pd
> index fe71115..7d4beea 100644
> --- a/gcc/match.pd
> +++ b/gcc/match.pd
> @@ -2626,22 +2626,12 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
> && types_match (TREE_TYPE (@0), TREE_TYPE (@1)))
> (out (imagpart @2) { build_zero_cst (TREE_TYPE (@0)); }))))
>
> -/* For unsigned operands, A > -1 / B checks whether A * B would overflow.
> +/* For unsigned operands, -1 / B < A checks whether A * B would overflow.
> Simplify it to __builtin_mul_overflow (A, B, <unused>). */
> -/* -1 / B < A */
> (for cmp (lt ge)
> out (ne eq)
> (simplify
> - (cmp (trunc_div:s integer_all_onesp @1) @0)
> - (if (TYPE_UNSIGNED (TREE_TYPE (@0)) && !VECTOR_TYPE_P (TREE_TYPE (@0)))
> - (with { tree t = TREE_TYPE (@0), cpx = build_complex_type (t); }
> - (out (imagpart (IFN_MUL_OVERFLOW:cpx @0 @1)) { build_zero_cst (t); })))))
> -
> -/* A > -1 / B */
> -(for cmp (gt le)
> - out (ne eq)
> - (simplify
> - (cmp @0 (trunc_div:s integer_all_onesp @1))
> + (cmp:c (trunc_div:s integer_all_onesp @1) @0)
> (if (TYPE_UNSIGNED (TREE_TYPE (@0)) && !VECTOR_TYPE_P (TREE_TYPE (@0)))
> (with { tree t = TREE_TYPE (@0), cpx = build_complex_type (t); }
> (out (imagpart (IFN_MUL_OVERFLOW:cpx @0 @1)) { build_zero_cst (t); })))))
>
>
--
Richard Biener <rguenther@suse.de>
SUSE LINUX GmbH, GF: Felix Imendoerffer, Jane Smithard, Graham Norton, HRB 21284 (AG Nuernberg)
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2016-06-10 12:43 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-06-01 10:29 Remove match.pd pattern dups in favor of using :c Richard Biener
2016-06-01 10:37 ` Alexander Monakov
2016-06-01 10:39 ` Richard Biener
2016-06-10 12:29 ` Alexander Monakov
2016-06-10 12:43 ` 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).