This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: Move ABS detection from fold-const.c to match.pd
- From: Richard Biener <richard dot guenther at gmail dot com>
- To: Marc Glisse <marc dot glisse at inria dot fr>, Prathamesh <bilbotheelffriend at gmail dot com>
- Cc: GCC Patches <gcc-patches at gcc dot gnu dot org>
- Date: Tue, 26 May 2015 11:25:36 +0200
- Subject: Re: Move ABS detection from fold-const.c to match.pd
- Authentication-results: sourceware.org; auth=none
- References: <alpine dot DEB dot 2 dot 02 dot 1505231828530 dot 22033 at stedding dot saclay dot inria dot fr> <alpine dot DEB dot 2 dot 11 dot 1505241504030 dot 1625 at laptop-mg dot saclay dot inria dot fr>
On Sun, May 24, 2015 at 3:17 PM, Marc Glisse <marc.glisse@inria.fr> wrote:
>
> I forgot to mention I optimistically tried to write something like this:
>
> (match
> (negated_value_for_comparison @0)
> (negate @0))
> (match
> (negated_value_for_comparison (negate @0))
> @0)
> (match
> (negated_value_for_comparison (minus @0 @1))
> (if (!HONOR_SIGN_DEPENDENT_ROUNDING (type))
> (minus @1 @0))
>
> without success. There is already a comment for logical_inverted_value about
> related limitations in genmatch.
Yeah, Prathamesh was working on inlining - not sure if that ended up
in sth usable?
+(match zerop integer_zerop)
+(match zerop real_zerop)
Would it also include fixed_zerop? Note that with inlining implemented it would
duplicate the pattern for each match variant thus in this case adding a
tree.[ch] function zerop () might be better.
+ (simplify
+ (cnd (cmp @0 zerop) (convert?@2 @0) (negate@1 @2))
+ (if (cmp == EQ_EXPR || cmp == UNEQ_EXPR)
+ @1)
+ (if (cmp == NE_EXPR || cmp == LTGT_EXPR)
+ (non_lvalue @2))
+ (if (TYPE_SIGN (TREE_TYPE (@0)) == SIGNED /* implicit */
+ && TYPE_SIGN (type) == SIGNED
+ && element_precision (type) >= element_precision (TREE_TYPE (@0)))
+ (if (cmp == GE_EXPR || cmp == GT_EXPR
+ || (!flag_trapping_math && (cmp == UNGE_EXPR || cmp == UNGT_EXPR)))
+ (abs @2))
+ (if (cmp == LE_EXPR || cmp == LT_EXPR
+ || (!flag_trapping_math && (cmp == UNLE_EXPR || cmp == UNLT_EXPR)))
+ (negate (abs @2)))))
+ /* Now with the branches swapped. */
+ (simplify
+ (cnd (cmp @0 zerop) (negate@1 (convert?@2 @0)) @2)
not obvious from a quick look - but would you be able to remove the
swapped branch
vairant if (cnd:c (cmp @0 zerop) X Y) would work by swapping X and Y?
The fold-const.c code doesn't seem to handle as many variants (esp.
the swapping?),
so maybe you can add a testcase that exercises some of the above on GIMPLE?
Thanks,
Richard.
>
> --
> Marc Glisse