[PATCH][match-and-simplify] Properly canonicalize operand order for sub-expressions

2015-07-03 Thread Richard Biener
I observed that we fail to match patterns because when valueizing sub-expression operands we fail to canonicalize operand order and thus try matching (1 + a) - 1 instead of the canonical (a + 1) - 1. The following fixes this at least for commutative tree codes. For comparisons which we also cano

[PATCH][match-and-simplify] Add more binary patterns exercised by fold_stmt

2014-11-13 Thread Richard Biener
The patch also makes us allow to iterate over things in the predicate position like (for op (INTEGER_CST REAL_CST) (simplify (plus @0 op) ... Bootstrapped and tested on x86_64-unknown-linux-gnu, applied to the branch. Richard. 2014-11-13 Richard Biener * match.pd: Implement mor

[PATCH][match-and-simplify] Allow SCCVN to follow SSA use-def chains

2014-10-29 Thread Richard Biener
Bootstrapped and tested on x86_64-unknown-linux-gnu, applied. Richard. 2014-10-29 Richard Biener * tree-ssa-sccvn.c (try_to_simplify): Allow gimple_fold_stmt_to_constant_1 to follow SSA use-def chains. (visit_use): Likewise. Index: gcc/tree-ssa-sccvn.c ==

[PATCH][match-and-simplify] Fix failed init of force_no_side_effects

2014-10-24 Thread Richard Biener
Committed. Richard. 2014-10-24 Richard Biener * genmatch.c (capture_info::capture_info): Initialize force_no_side_effects. Index: gcc/genmatch.c === --- gcc/genmatch.c (revision 216594) +++ gcc/genmatch.c

[PATCH][match-and-simplify] 2nd try handling TREE_SIDE_EFFECTS

2014-10-23 Thread Richard Biener
This is a second attempt - it fixes the bugs in the previous one and handles falling back or not separately for the incoming arguments. What we handle too conservatively right now is non-captured leafs and captured expressions that are substituted into the result. Both result in the incoming argu

Re: [PATCH][match-and-simplify] Hande side-effects in GENERIC

2014-10-22 Thread Richard Biener
On October 22, 2014 5:08:50 PM CEST, Jakub Jelinek wrote: >On Wed, Oct 22, 2014 at 04:20:09PM +0200, Richard Biener wrote: >> 2014-10-22 Richard Biener >> >> * genmatch.c (count_captures): New function. >> (dt_simplify::gen): Handle preserving side-effects for >> GENERIC code ge

Re: [PATCH][match-and-simplify] Hande side-effects in GENERIC

2014-10-22 Thread Jakub Jelinek
On Wed, Oct 22, 2014 at 04:20:09PM +0200, Richard Biener wrote: > 2014-10-22 Richard Biener > > * genmatch.c (count_captures): New function. > (dt_simplify::gen): Handle preserving side-effects for > GENERIC code generation. > (decision_tree::gen_generic): Do not reject

Re: [PATCH][match-and-simplify] Hande side-effects in GENERIC

2014-10-22 Thread Richard Biener
On Wed, 22 Oct 2014, Richard Biener wrote: > > The following auto-handles preserving of side-effects properly > for GENERIC simplification instead of simply rejecting operands > with side-effects. Cases we cannot handle correctly are still > handled that way. > > For example for > > /* (x | CS

[PATCH][match-and-simplify] Hande side-effects in GENERIC

2014-10-22 Thread Richard Biener
The following auto-handles preserving of side-effects properly for GENERIC simplification instead of simply rejecting operands with side-effects. Cases we cannot handle correctly are still handled that way. For example for /* (x | CST1) & CST2 -> (x & CST2) | (CST1 & CST2) */ (simplify (bit_a

[PATCH][match-and-simplify] Remove local generic_simplify prototypes

2014-10-22 Thread Richard Biener
This adds a generic-match.h header to cover these (even though they are not public API). Richard. 2014-10-22 Richard Biener * generic-match.h: New file. * generic-match-head.c: Include generic-match.h, not gimple-match.h. * fold-const.c: Include generic-match.h.

[PATCH][match-and-simplify] Prepare next merge

2014-10-22 Thread Richard Biener
I am testing the following patch to add a location argument to generic_simplify and properly build GENERIC trees with a location (oops). The patch also implements special handling for NON_LVALUE_EXPR by dropping it for GIMPLE and using non_lvalue_loc to build it for GENERIC. This simplifies impl

[PATCH][match-and-simplify] Re-factor code in fold_stmt_1

2014-10-21 Thread Richard Biener
This refactors the code I added to fold_stmt to dispatch to pattern-based folding to avoid long lines and make error handling easier (no goto). It also uses the newly introduced gimple_seq_discard to properly discard an unused simplification result. Bootstrapped on x86_64-unknown-linux-gnu, test

[PATCH][match-and-simplify] Merge from trunk

2014-10-17 Thread Richard Biener
Lightly tested, committed. Richard. 2014-10-17 Richard Biener Merge from trunk r216316 through r216394.

Re: [PATCH][match-and-simplify] More ternary commutative ops, canonicalize operand order before generic_simplify

2014-10-17 Thread Richard Biener
On Fri, 17 Oct 2014, Richard Biener wrote: > On Thu, 16 Oct 2014, Jeff Law wrote: > > > On 10/16/14 05:06, Richard Biener wrote: > > > > > > This patch (also applicable to trunk) makes us canoncialize operand > > > order for comparisons at the same time we canonicalize other > > > operand order,

Re: [PATCH][match-and-simplify] More ternary commutative ops, canonicalize operand order before generic_simplify

2014-10-17 Thread Richard Biener
On Thu, 16 Oct 2014, Jeff Law wrote: > On 10/16/14 05:06, Richard Biener wrote: > > > > This patch (also applicable to trunk) makes us canoncialize operand > > order for comparisons at the same time we canonicalize other > > operand order, in particular before dispatching to generic_simplify. > >

Re: [PATCH][match-and-simplify] More ternary commutative ops, canonicalize operand order before generic_simplify

2014-10-16 Thread Jeff Law
On 10/16/14 05:06, Richard Biener wrote: This patch (also applicable to trunk) makes us canoncialize operand order for comparisons at the same time we canonicalize other operand order, in particular before dispatching to generic_simplify. It also adds operand canonicalization to ternary ops and

[PATCH][match-and-simplify] Merge from trunk

2014-10-16 Thread Richard Biener
Bootstrapped on x86_64-unknown-linux-gnu. Richard. 2014-10-16 Richard Biener Merge from trunk r216235 through r216315.

[PATCH][match-and-simplify] More ternary commutative ops, canonicalize operand order before generic_simplify

2014-10-16 Thread Richard Biener
This patch (also applicable to trunk) makes us canoncialize operand order for comparisons at the same time we canonicalize other operand order, in particular before dispatching to generic_simplify. It also adds operand canonicalization to ternary ops and adds FMA_EXPR and DOT_PROD_EXPR to the list

[PATCH][match-and-simplify] Remove/revert unneeded changes

2014-10-14 Thread Richard Biener
This removes duplicate/not needed code from generic-match-head.c and removes integral_op_p (if needed these new predicates should go to tree.h). It also revers one unnecessary Makefile.in change. Applied. Richard. 2014-10-14 Richard Biener * Makefile.in (BUILD_RTL): Revert not need

Re: [PATCH][match-and-simplify] Change back default behavior of fold_stmt

2014-10-14 Thread Richard Biener
On Tue, 14 Oct 2014, Richard Biener wrote: > On Tue, 14 Oct 2014, Richard Biener wrote: > > > > > This changes default behavior of fold_stmt back to _not_ following > > SSA use-def chains when trying to simplify things. I had to force > > that already for one caller and for the merge to trunk I

Re: [PATCH][match-and-simplify] Change back default behavior of fold_stmt

2014-10-14 Thread Richard Biener
On Tue, 14 Oct 2014, Richard Biener wrote: > > This changes default behavior of fold_stmt back to _not_ following > SSA use-def chains when trying to simplify things. I had to force > that already for one caller and for the merge to trunk I'd rather > not track down issues in every other existin

[PATCH][match-and-simplify] Fix ICE

2014-10-14 Thread Richard Biener
This fixes an ICE that occurs when valueziation returns NULL and we are looking at single-rhs REALPART_EXPR. We should check for is_gimple_min_invariant before valueization. Bootstrapped on x86_64-unknown-linux-gnu, applied. Richard. 2014-10-14 Richard Biener * genmatch.c (dt_opera

[PATCH][match-and-simplify] Update texi documentation

2014-10-14 Thread Richard Biener
This updates it with changed/added features. pfd-build checked and inspected, applied. Richard. 2014-10-14 Richard Biener * doc/match-and-simplify.texi: Update. Index: gcc/doc/match-and-simplify.texi === --- gcc/doc/ma

[PATCH][match-and-simplify] More TLC to genmatch

2014-10-14 Thread Richard Biener
This applies more comment / whitespace TLC to genmatch and does minor refactoring on-the-fly. Bootstrap running on x86_64-unknown-linux-gnu. Richard. 2014-10-14 Richard Biener * genmatch.c: Whitespace and comment fixes, some minor refactoring. Index: gcc/genmatch.c

[PATCH][match-and-simplify] Change back default behavior of fold_stmt

2014-10-14 Thread Richard Biener
This changes default behavior of fold_stmt back to _not_ following SSA use-def chains when trying to simplify things. I had to force that already for one caller and for the merge to trunk I'd rather not track down issues in every other existing caller. This means that fold_stmt will not become m

[PATCH][match-and-simplify] Change (match ...) syntax

2014-10-07 Thread Richard Biener
After internal discussion this changes (match logical_inverted_value (ne truth_valued_p@0 integer_onep) (if (INTEGRAL_TYPE_P (TREE_TYPE (@0))) (logical_inverted_value @0))) to (match (logical_inverted_value @0) (ne truth_valued_p@0 integer_onep) (if (INTEGRAL_TYPE_P (TREE_TYPE (@0) t

Re: [PATCH][match-and-simplify] Enable conversions properly for GENERIC

2014-09-26 Thread Jason Merrill
On 09/26/2014 06:54 AM, Richard Biener wrote: It also uncovers that the C++ FE uses a mix of NOP_EXPR and CONVERT_EXPR both when building expressions and when checking for them. Jason - is there any difference between NOP_EXPR and CONVERT_EXPR as far as the C++ FE is concerned? There are a few

[PATCH][match-and-simplify] Enable conversions properly for GENERIC

2014-09-26 Thread Richard Biener
This fixes a ??? and handles NOP_EXPR and CONVERT_EXPR matching similar to GIMPLE by using CASE_CONVERT. This uncovers a mismatch between fold-const.c and tree-ssa-forwprop.c transforms which try to do opposite things with ((T) X) & CST vs. (T) (X & CST). I have disabled the forwprop transform o

[PATCH][match-and-simplify] Merge some more code-gen code

2014-09-26 Thread Richard Biener
Bootstrapped on x86_64-unknown-linux-gnu, applied. Richard. 2014-09-26 Richard Biener * genmatch.c (struct dt_node): Merge gen_gimple and gen_generic into gen, merge gen_gimple_kids and gen_generic_kids into gen_kids. (struct dt_operand): Likewise. Index: gcc

[PATCH][match-and-simplify] Fix capture change

2014-09-25 Thread Richard Biener
Of course I missed c-exprs... The following patch fixes that. Now bootstrapped (building stage3 target libs now). Applied. Richard. 2014-09-25 Richard Biener * genmatch.c (struct c_expr): Also record capture identifier to index map. (c_expr::gen_transform): Use it.

[PATCH][match-and-simplify] Allow @foo captures

2014-09-25 Thread Richard Biener
The following makes us assign capture indexes dynamically which easily allows handling of identifiers. I've used std::map for this. Applied. Note that this may make debugging a little bit harder as @0 now no longer necessarily corresponds to captures[0] (I don't think it necessarily did before

[PATCH][match-and-simplify] Get rid of static limit on captures

2014-09-25 Thread Richard Biener
$subject. Still not the full-blown idea of dynamically assigning the (internal) IDs from any number or identifier. Somebody said it would be nice to write (plus @a @b) instead of (plus @1 @2). Applied. Richard. 2014-09-25 Richard Biener * genmatch.c: Keep track of the maximum capt

[PATCH][match-and-simplify] Parser TLC, 2nd

2014-09-25 Thread Richard Biener
The following wraps lexing and parsing into a parser class, simplifying state management. It also removes the need to forward declare matchers as we now keep a vector of them filled in declaration order. Committed. Richard. 2014-09-25 Richard Biener * genmatch.c: Put all AST parsin

[PATCH][match-and-simplify] Apply TLC

2014-09-25 Thread Richard Biener
This shuffles routines around, grouping them properly and adding function comments. Applies minor code TLC. Applied. Richard. 2014-09-25 Richard Biener * genmatch.c: TLC. Index: gcc/genmatch.c === --- gcc/genmatch.c

[PATCH][match-and-simplify] Remove outlining of C exprs

2014-09-24 Thread Richard Biener
It no longer works in the face of (with { } which would need to pass down all named temporaries. Instead we can simply inline all C exprs now that we pass 'output' to all gen_transform calls. Boostrap pending on x86_64-unknown-linux-gnu. Richard. 2014-09-24 Richard Biener * ge

[PATCH][match-and-simplify] Cleanup operator arity related diagnostics

2014-09-24 Thread Richard Biener
The following removes a bunch of code dealing with "late" verifying of operator presence and matching arity. This can now all be verified at parsing, giving proper locations and operator names. Bootstrap pending. Richard. 2014-09-24 Richard Biener * genmatch.c (struct id_base): Mov

[PATCH][match-and-simplify][2/2] Delay for lowering

2014-09-24 Thread Richard Biener
This delays for lowering by recording fors to apply in simplify similar to how we record ifs. Bootstrapped on x86_64-unknown-linux-gnu. Richard. 2014-09-24 Richard Biener * genmatch.c (id_base): Derive from typed_noop_remove. (struct user_id): New id_base derivative.

[PATCH][match-and-simplify] Caret diagnostics

2014-09-23 Thread Richard Biener
The following implements very simple caret diagnostics. A slow implementation is possible as we're only emitting fatal errors (and thus at most one). Committed. Richard. 2014-09-23 Richard Biener * genmatch.c (error_cb): Implement simple caret diagnostics. Index: gcc/genmatch.c ==

[PATCH][match-and-simplify][1/2] Delay for lowering

2014-09-23 Thread Richard Biener
This is a first cleanup step towards lowering for late, not during parsing. This intermediate step removes the e_operation indirection and makes parse_for temporarily insert operators it defines so we can avoid lazily accepting anything as user-defined and thus report proper error locations. Boo

[PATCH][match-and-simplify] Fix outer if parsing

2014-09-23 Thread Richard Biener
This restructures outer if parsing to maintain a stack of active ifs. This gets rid of all the reverse if stuff and fixes outer ifs on (match ...)es. What is left to be done is delaying 'for' lowering. Richard. 2014-09-23 Richard Biener * genmatch.c (dt_simplify::gen): Adj

[PATCH][match-and-simplify] Add predicate expressions

2014-09-23 Thread Richard Biener
As promised this allows you to define custom predicate expressions (or operators), like one modeled after tree-ssa-forwprop.c:lookup_logical_inverted_value: (match logical_inverted_value (bit_not truth_valued_p@0) (logical_inverted_value @0)) (match logical_inverted_value (eq @0 integer_zerop

[PATCH][match-and-simplify] Also canonicalize comparison ops

2014-09-23 Thread Richard Biener
Bootstrapped and tested on x86_64-unknown-linux-gnu, applied. Richard. 2014-09-22 Richard Biener * gimple-match-head.c (gimple_resimplify2): Also swap comparison operands. (gimple_simplify): Likewise. Index: gcc/gimple-match-head.c ===

Re: [PATCH][match-and-simplify] User defined predicates

2014-09-22 Thread Richard Biener
On Tue, 16 Sep 2014, Marc Glisse wrote: > On Tue, 16 Sep 2014, Richard Biener wrote: > > > The following adds the ability to write predicates using patterns > > with an example following negate_expr_p which already has a > > use in comparison folding (via its if c-expr). > > > > The syntax is as

Re: [PATCH][match-and-simplify] User defined predicates

2014-09-16 Thread Marc Glisse
On Tue, 16 Sep 2014, Richard Biener wrote: The following adds the ability to write predicates using patterns with an example following negate_expr_p which already has a use in comparison folding (via its if c-expr). The syntax is as follows: (match negate_expr_p INTEGER_CST (if (TYPE_OVERFLOW_

[PATCH][match-and-simplify] User defined predicates

2014-09-16 Thread Richard Biener
The following adds the ability to write predicates using patterns with an example following negate_expr_p which already has a use in comparison folding (via its if c-expr). The syntax is as follows: (match negate_expr_p INTEGER_CST (if (TYPE_OVERFLOW_WRAPS (type) || may_negate_without_ov

[PATCH][match-and-simplify] Make predicate IDs explicit

2014-09-16 Thread Richard Biener
The following patch makes the parser know known predicates via us defining them in match.pd with a new (define_predicates ...) construct. This will allow (in a followup patch) to define our own predicates via sth like (match negate_expr_p (negate @0)) (match negate_expr_p INTEGER_CST@0 (if

[PATCH][match-and-simplify] Fix comparison operator type handling

2014-09-16 Thread Richard Biener
Bootstrapped and tested on x86_64-unknown-linux-gnu, applied. Richard. 2014-09-16 Richard Biener * genmatch.c (operator_id): Add tcc member. (get_operand_type): New function, split out from ... (expr::gen_transform): ... here. Treat comparisons properly.

[PATCH][match-and-simplify] Enable simplifying of GIMPLE_CONDs

2014-09-15 Thread Richard Biener
To get desired transforms from tree-ssa-forwprop.c which uses fold_stmt. Bootstrapped and tested on x86_64-unknown-linux-gnu, applied. Richard. 2014-09-15 Richard Biener * gimple-fold.c: Include tree-eh.c. (fold_stmt_1): Handle GIMPLE_CONDs for gimple_simplify. * gim

Re: [PATCH][match-and-simplify] Finish simplify_bitwise_binary patterns

2014-09-12 Thread Richard Biener
On Fri, 12 Sep 2014, Marc Glisse wrote: > On Fri, 12 Sep 2014, Richard Biener wrote: > > > +/* x ^ ~0 -> ~x */ > > (simplify > > (bit_and @0 integer_all_onesp) > > @0) > > The comment doesn't seem to match. Thanks - fixed below which also implements simplify_mult and simplify_not_neg_expr.

Re: [PATCH][match-and-simplify] Finish simplify_bitwise_binary patterns

2014-09-12 Thread Marc Glisse
On Fri, 12 Sep 2014, Richard Biener wrote: +/* x ^ ~0 -> ~x */ (simplify (bit_and @0 integer_all_onesp) @0) The comment doesn't seem to match. -- Marc Glisse

[PATCH][match-and-simplify] Fix lto.exp=20110201-1_0.c ICE

2014-09-12 Thread Richard Biener
Committed. Richard. 2014-09-12 Richard Biener * genmatch.c (expr::gen_transform): Properly autocompute type of REALPART_EXPR and IMAGPART_EXPR. Index: gcc/genmatch.c === --- gcc/genmatch.c (revision 215210)

[PATCH][match-and-simplify] Finish simplify_bitwise_binary patterns

2014-09-12 Thread Richard Biener
And some more. Bootstrapped and tested on x86_64-unknown-linux-gnu, applied. Richard. 2014-09-12 Richard Biener * match-bitwise.pd: Complete tree-ssa-forwprop.c patterns from simplify_bitwise_binary. Implement some from fold_binary. * match-constant-folding.pd: Add

Re: [PATCH][match-and-simplify] Minor fixes to match-plusminus.pd

2014-09-11 Thread Richard Biener
On Thu, 11 Sep 2014, Marc Glisse wrote: > /* ~A + 1 -> -A */ > (simplify >(plus (bit_not @0) integer_onep@1) >(if (TREE_CODE (TREE_TYPE (@1)) != COMPLEX_TYPE > || (TREE_CODE (@1) == COMPLEX_CST > && integer_onep (TREE_REALPART (@1)) > && integer_onep (TR

Re: [PATCH][match-and-simplify] Minor fixes to match-plusminus.pd

2014-09-11 Thread Marc Glisse
/* ~A + 1 -> -A */ (simplify (plus (bit_not @0) integer_onep@1) (if (TREE_CODE (TREE_TYPE (@1)) != COMPLEX_TYPE || (TREE_CODE (@1) == COMPLEX_CST && integer_onep (TREE_REALPART (@1)) && integer_onep (TREE_IMAGPART (@1 (negate @0))) the complex par

[PATCH][match-and-simplify] Pattern for simplify_conversion_from_bitmask

2014-09-11 Thread Richard Biener
Applied. Richard. 2014-09-11 Richard Biener * match-plusminus.pd: Fix typo. * match-conversions.pd: Add pattern for simplify_conversion_from_bitmask. Index: gcc/match-conversions.pd === --- gcc/match-con

[PATCH][match-and-simplify] Minor fixes to match-plusminus.pd

2014-09-11 Thread Richard Biener
More closely match-up to tree-ssa-forwprop.c code. Committed. Richard. 2014-09-11 Richard Biener * match-plusminus.pd: More closely match tree-ssa-forwprop.c code. Index: gcc/match-plusminus.pd === --- gcc/match-plusmi

Re: [PATCH][match-and-simplify] Complete associate_* patterns

2014-09-11 Thread Richard Biener
On Thu, 11 Sep 2014, Marc Glisse wrote: > On Thu, 11 Sep 2014, Richard Biener wrote: > > > + /* We can't reassociate floating-point or fixed-point plus or minus > > +because of saturation to +-Inf. */ > > + (if (!FLOAT_TYPE_P (type) && !FIXED_POINT_TYPE_P (type)) > > Do you remember if ther

Re: [PATCH][match-and-simplify] Complete associate_* patterns

2014-09-11 Thread Marc Glisse
On Thu, 11 Sep 2014, Richard Biener wrote: + /* We can't reassociate floating-point or fixed-point plus or minus +because of saturation to +-Inf. */ + (if (!FLOAT_TYPE_P (type) && !FIXED_POINT_TYPE_P (type)) Do you remember if there was a particular reason not to add || flag_associative

[PATCH][match-and-simplify] Complete associate_* patterns

2014-09-11 Thread Richard Biener
The following patch completes transitioning tree-ssa-forwprop.c:associate_* to patterns. Bootstrapped and tested on x86_64-unknown-linux-gnu. Richard. 2014-09-11 Richard Biener * match-plusminus.pd: Complete associate_plusminus patterns. Properly guard all patterns. Add as

[PATCH][match-and-simplify] Fix PR41043

2014-09-11 Thread Richard Biener
So I managed to re-introduce PR41043 by implementing the fold_unary (T1)(X * Y) -> (T1)X * (T1)Y pattern on GIMPLE. That is because it re-applies recursively on a large multiplication tree and because if there are multiple uses of SSA names doing that will expand (aka un-CSE) the multiplication tr

[PATCH][match-and-simplify] Dump what patterns get applied

2014-09-11 Thread Richard Biener
The following adds dumping what patterns get applied with -details. This is useful for tracking down which patterns cause a miscompile. Applied. Richard. 2014-09-11 Richard Biener * genmatch.c (output_line_directive): Add variant for dump files. (dt_simplify::gen): Write to

[PATCH][match-and-simplify] More flexible 'for', polish match-builtins.pd

2014-09-10 Thread Richard Biener
This completes match-builtins.pd by handling all builtin variants in all present patterns. That requires a little more flexibility in the 'for' handling to support for example /* Optimize sqrt(expN(x)) = expN(x*0.5). */ (for expfn (BUILT_IN_EXP10F BUILT_IN_EXP10 BUILT_IN_EXP10L B

[PATCH][match-and-simplify] Fix last commit

2014-09-10 Thread Richard Biener
Committed. Richard. 2014-09-10 Richard Biener * match-conversions.pd: Fix unsigned type used for shortened multiplication. Index: gcc/match-conversions.pd === --- gcc/match-conversions.pd(revision 215057) ++

[PATCH][match-and-simplify] Explicitely specified types

2014-09-09 Thread Richard Biener
This adds the capability to specify a type to be used when building an expression. Committed. 2014-09-09 Richard Biener * genmatch.c (struct expr): Add expr_type member. (expr::gen_transform): Honor explicitely specified type. (parse_expr): Parse ':' on the operator a

[PATCH][match-and-simplify] Use multi-id for in one example

2014-09-08 Thread Richard Biener
The following patch makes use of the new multi-id for in builtin math fn patterns related to POW to show how we can address the usual triplets of fnF, fn, fnL simplifications with it. It's still quite explicit of course. The patch also supplies locations to some parser error calls and removes a

[PATCH][match-and-simplify] Fix error in VCE pattern

2014-09-03 Thread Richard Biener
The pattern (and the fold_unary code it was derived from) stripping inner conversions from VIEW_CONVERT_EXPRs is bogus as in that it doesn't make sure the the size of the types match. This triggers a IL verification for gfortran.fortran-torture/compile/forall-1.f90 otherwise. Committed to the br

[PATCH][match-and-simplify] Add comparison patterns

2014-09-02 Thread Richard Biener
The following patch adds more comparison patterns (with comments on what is missing still). Bootstrapped on x86_64-unknown-linux-gnu, testing in progress. Richard. 2014-09-02 Richard Biener * fold-const.h (negate_expr_p): Declare. * fold-const.c (negate_expr_p): Export.

[PATCH][match-and-simplify] Fix single RHS code-gen

2014-09-02 Thread Richard Biener
Appearantly we didn't exercise this before and thus it has gone unnoticed that we don't properly special case single-RHSs on GIMPLE. Fixed as follows. Bootstrapped on x86_64-unknown-linux-gnu, applied. Richard. 2014-09-02 Richard Biener * gimple-match-head.c (maybe_build_generic_op

[PATCH][match-and-simplify] Complete conversion patterns

2014-09-02 Thread Richard Biener
This completes conversion patterns (apart from commented case which needs a new IL feature). Bootstrapped on x86_64-unknown-linux-gnu, applied. Richard. 2014-09-02 Richard Biener * match-conversions.pd: Add more patterns. Index: gcc/match-conversions.pd

[PATCH][match-and-simplify] Move simplify first in fold_stmt

2014-08-28 Thread Richard Biener
Now as the fold_stmt re-org is merged from trunk this moves the simplify dispatch first before doing the legacy stuff. It also adds dumping to this place and removes dumping from tree-ssa-forwprop.c (as there it catches all fold_stmt transforms done). I now also dump the associated sequence whic

[PATCH][match-and-simplify] Fix NON_LVALUE_EXPR leaking

2014-08-28 Thread Richard Biener
This tries to prevent NON_LVALUE_EXPR from leaking in to GIMPLE (happens on trunk also, but mostly savaged by re-gimplifying GENERIC folding results which strips them). We need a better solution in the end (fix the C++ frontend), but for now the following should fix things enough. (fingers cross

[PATCH][match-and-simplify] Fix some testcases

2014-08-28 Thread Richard Biener
The following fixes a few ICEs and C++ testsuite fails. Bootstrapped and tested on x86_64-unknown-linux-gnu, applied. Richard. 2014-08-28 Richard Biener * match-constant-folding.pd (x + 0 -> x): Wrap result in a NON_LVALUE_EXPR to account for the C++ frontend folding

[PATCH][match-and-simplify] Fix type guessing for conversions

2014-08-27 Thread Richard Biener
The following fixes type guessing by handling VIEW_CONVERT_EXPR and by properly passing down "unknown" for outermost conversions. Btw, a case where we need some explicit type specification support is Convert (T1)(X * Y) into (T1)X * (T1)Y which needs to eventually use an unsigned type for the mul

[PATCH][match-and-simplify] Fail more gracefully when encountering EOF

2014-08-27 Thread Richard Biener
This fixes the segfaults when an unexpected EOF occurs. Committed. Richard. 2014-08-27 Richard Biener * genmatch.c (peek): Fail at unexpected EOF. (main): Do not peek at the next token as we do expect EOF at some point. Index: gcc/genmatch.c

[PATCH][match-and-simplify] Fix some C++ testsuite FAILs

2014-08-26 Thread Richard Biener
The following fixes C++ testsuite FAILs. First in fold_binary we should delay the dispatch to generic_simplify until after const OP const folding which generic_simplify isn't supposed to do. (I note that neither fold_unary nor fold_ternary has such clear const operand path...) Second, the C++ F

[PATCH][match-and-simplify] Sort IVOPTs iv_uses after dominator

2014-08-26 Thread Richard Biener
The following is needed to allow building libada if the conversion simplifications go in. Currently IVOPTs replaces IV uses in arbitrary order which can result in intermediate code that still refers to IVs that are going to be removed. As it folds replacement statements via force_gimple_operand

[PATCH][match-and-simplify] Introduce (with { .. } op), combine conversions

2014-08-26 Thread Richard Biener
The following patch introduces a new syntax to initialize temporaries used in c-exprs (such as if conditionals). So a simplify pattern is now 'simplify' [ ] with = | | = '(' 'if' '(' ')' ')' = '(' 'with' '{' '}' ')' which allows nearly literal translation of

Re: [PATCH][match-and-simplify] Auto-guess conversion types

2014-08-26 Thread Richard Biener
On Thu, 21 Aug 2014, Marc Glisse wrote: > On Thu, 21 Aug 2014, Richard Biener wrote: > > > 2014-08-21 Richard Biener > > > > * match.pd ((T1)(~(T2) X) -> ~(T1) X): Paste all comment > > from fold-const.c, fix simplification result. > > > > Index: gcc/match.pd > >

Re: [PATCH][match-and-simplify] Auto-guess conversion types

2014-08-21 Thread Marc Glisse
On Thu, 21 Aug 2014, Richard Biener wrote: 2014-08-21 Richard Biener * match.pd ((T1)(~(T2) X) -> ~(T1) X): Paste all comment from fold-const.c, fix simplification result. Index: gcc/match.pd === --- gcc/match.p

Re: [PATCH][match-and-simplify] Auto-guess conversion types

2014-08-21 Thread Richard Biener
On Thu, 21 Aug 2014, Marc Glisse wrote: > On Thu, 21 Aug 2014, Richard Biener wrote: > > > +/* From fold_unary. */ > > + > > +/* (T1)(~(T2) X) -> ~(T1) X */ > > +(simplify > > + (convert (bit_not@0 (convert @1))) > > + (if (INTEGRAL_TYPE_P (type) > > + && INTEGRAL_TYPE_P (TREE_TYPE (@0)) >

[PATCH][match-and-simplify] Merge from trunk

2014-08-21 Thread Richard Biener
Committed. Richard. 2014-08-21 Richard Biener Merge from trunk r213754 through r214265.

Re: [PATCH][match-and-simplify] Auto-guess conversion types

2014-08-21 Thread Marc Glisse
On Thu, 21 Aug 2014, Richard Biener wrote: +/* From fold_unary. */ + +/* (T1)(~(T2) X) -> ~(T1) X */ +(simplify + (convert (bit_not@0 (convert @1))) + (if (INTEGRAL_TYPE_P (type) + && INTEGRAL_TYPE_P (TREE_TYPE (@0)) + && TYPE_PRECISION (type) == TYPE_PRECISION (TREE_TYPE (@0)) +

[PATCH][match-and-simplify] Merge dt_simplify::gen_gimple and dt_simplify::gen_generic

2014-08-21 Thread Richard Biener
This merges the two functions that have much in common and prettifies the code-gen. Committed. Richard. 2014-08-21 Richard Biener * genmatch.c (dt_simplify::gen): New function merged from ... (dt_simplify::gen_gimple, dt_simplify::gen_generic): ... these, mad

[PATCH][match-and-simplify] Auto-guess conversion types

2014-08-21 Thread Richard Biener
This adds the capability to auto-guess the type of non-outermost conversions by looking at the parent expression type. This also adds fatal () to the cases we can't auto-detect. Bootstrapped on x86_64-unknown-linux-gnu, testing in progress. Richard. 2014-08-21 Richard Biener * genm

[PATCH][match-and-simplify] Do not match loads

2014-08-21 Thread Richard Biener
This avoids matching loads in the signle-rhs matching logic. Bootstrapped and tested on x86_64-unknown-linux-gnu, applied. Richard. 2014-08-21 Richard Biener * genmatch.c (dt_operand::gen_gimple_expr): Only match non-reference-like GIMPLE single RHS. Index: gcc/genmatch.c =

Re: [PATCH][match-and-simplify] Fix comparison pattern

2014-08-20 Thread Richard Biener
On Wed, 20 Aug 2014, Marc Glisse wrote: > On Wed, 20 Aug 2014, Richard Biener wrote: > > > On Wed, 20 Aug 2014, Marc Glisse wrote: > > > > > On Wed, 20 Aug 2014, Richard Biener wrote: > > > > > > > Committed. > > > > > > > > Also makes visible a desirable change I plan for if-exprs. They > >

[PATCH][match-and-simplify] Fix texinfo errors

2014-08-20 Thread Richard Biener
Committed. Richard. 2014-08-20 Richard Biener * match-and-simplify.texi: Fix errors during pdf build. Index: gcc/doc/match-and-simplify.texi === --- gcc/doc/match-and-simplify.texi (revision 214220) +++ gcc/doc/matc

[PATCH][match-and-simplify] Nested inner ifs

2014-08-20 Thread Richard Biener
$subject. Bootstrap ongoing on x86_64-unknown-linux-gnu. Richard. 2014-08-20 Richard Biener * genmatch.c (copy_reverse): New function. (parse_simplify): Support nested inner ifs. * match-comparison.pd: Use nested inner ifs. Index: match-and-simplify/gcc/genmatch.c =

[PATCH][match-and-simplify] Change inner if-parsing

2014-08-20 Thread Richard Biener
This changes inner ifs to have a result operand and to allow a simplify pattern to have multiple such ifs, thus: (simplify (match-expression...) (if (cond1) result1) (if (cond2) result2) ... resultdefault) I'm not sure a default makes sense when a previous if failed

[PATCH][match-and-simplify] Refactor GIMPLE code-gen

2014-08-20 Thread Richard Biener
This refactors GIMPLE code-gen to use switch ()es similar to the GENERIC version. This should provide all of the backtracking avoidance we need (I think so at least). Bootstrap and regtest ongoing on x86_64-unknown-linux-gnu. Richard. 2014-08-20 Richard Biener * genmatch.c (dt_node

Re: [PATCH][match-and-simplify] Fix comparison pattern

2014-08-20 Thread Marc Glisse
On Wed, 20 Aug 2014, Richard Biener wrote: On Wed, 20 Aug 2014, Marc Glisse wrote: On Wed, 20 Aug 2014, Richard Biener wrote: Committed. Also makes visible a desirable change I plan for if-exprs. They should behave like outer ifs and allow us to write that series of pattern as (for op in

[PATCH][match-and-simplify] Use gsi_replace_with_seq_vops

2014-08-20 Thread Richard Biener
Bootstrapped / tested on x86_64-unknown-linux-gnu, applied. Richard. 2014-08-20 Richard Biener * gimple-fold.c (fold_stmt_1): Use gsi_replace_with_seq_vops helper to insert gimple_simplify result. Index: gcc/gimple-fold.c =

Re: [PATCH][match-and-simplify] Fix comparison pattern

2014-08-20 Thread Richard Biener
On Wed, 20 Aug 2014, Marc Glisse wrote: > On Wed, 20 Aug 2014, Richard Biener wrote: > > > Committed. > > > > Also makes visible a desirable change I plan for if-exprs. They > > should behave like outer ifs and allow us to write that series > > of pattern as > > > > (for op in eq ne > > /* Si

Re: [PATCH][match-and-simplify] Fix comparison pattern

2014-08-20 Thread Marc Glisse
On Wed, 20 Aug 2014, Richard Biener wrote: Committed. Also makes visible a desirable change I plan for if-exprs. They should behave like outer ifs and allow us to write that series of pattern as (for op in eq ne /* Simplify X * C1 CMP 0 to X CMP 0 if C1 is not zero. */ (simplify (op (mu

[PATCH][match-and-simplify] Fix comparison pattern

2014-08-20 Thread Richard Biener
Committed. Also makes visible a desirable change I plan for if-exprs. They should behave like outer ifs and allow us to write that series of pattern as (for op in eq ne /* Simplify X * C1 CMP 0 to X CMP 0 if C1 is not zero. */ (simplify (op (mult @0 INTEGER_CST@1) integer_zerop@2)

[PATCH][match-and-simplify] Avoid excessive bracesin code-gen

2014-08-19 Thread Richard Biener
Committed. Richard. 2014-08-19 Richard Biener * genmatch.c (dt_operand::gen_gimple): Remove excessive braces. (dt_operand::gen_generic): Likewise. Index: gcc/genmatch.c === --- gcc/genmatch.c (revis

[PATCH][match-and-simplify] Use a switch (code) for the GIMPLE code gen

2014-08-19 Thread Richard Biener
on the outermost level. Committed. Richard. 2014-08-19 Richard Biener * genmatch.c (decision_tree::gen_gimple): Use a switch statement for the outermost level. * gimple-match.h (code_helper::get_rep): New method. Index: gcc/genmatch.c ===

[PATCH][match-and-simplify] Split out common code for c_expr codegen

2014-08-19 Thread Richard Biener
Applied. Richard. 2014-08-19 Richard Biener * genmatch.c (c_expr::output_code): New method. (c_expr::gen_transform): Call it. (outline_c_exprs): Likewise. Index: gcc/genmatch.c === --- gcc/genmatch.c

[PATCH][match-and-simplify] Allow zero-operand operators as predicates

2014-08-19 Thread Richard Biener
This makes us accept (plus @0 INTEGER_CST) and parse it as (plus @0 (INTEGER_CST)), that is, handle operator names in predicate position as expression with zero operands. This makes those leafs better integrate with the decision tree and also removes the need to define all those INTEGER_CST_P p

[PATCH][match-and-simplify] Fix GENERIC outermost expression type

2014-08-19 Thread Richard Biener
We shouldn't use the type of the operand but the type requested. This otherwise triggers asserts for (eq @0 @1) which requires boolean type, not whatever type @0 has. Applied. Richard. 2014-08-19 Richard Biener * genmatch.c (dt_simplify::gen_generic): Properly use the specif

  1   2   >