On Sun, May 24, 2015 at 3:17 PM, Marc Glisse <marc.gli...@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