On Fri, Jun 16, 2017 at 5:48 PM, Marc Glisse <marc.gli...@inria.fr> wrote: > On Fri, 16 Jun 2017, Bin.Cheng wrote: > >> On Fri, Jun 16, 2017 at 5:16 PM, Richard Biener >> <richard.guent...@gmail.com> wrote: >>> >>> >>> That means we miss a pattern in match.PD to handle this case. >> >> I see. I will withdraw this patch and look in that direction. > > > For _123, we have > > /* (A +- CST1) +- CST2 -> A + CST3 > or > /* Associate (p +p off1) +p off2 as (p +p (off1 + off2)). */ > > > For _115, we have > > /* min (a, a + CST) -> a where CST is positive. */ > /* min (a, a + CST) -> a + CST where CST is negative. */ > (simplify > (min:c @0 (plus@2 @0 INTEGER_CST@1)) > (if (TYPE_OVERFLOW_UNDEFINED (TREE_TYPE (@0))) > (if (tree_int_cst_sgn (@1) > 0) > @0 > @2))) > > What is the type of all those SSA_NAMEs? Hi, >From the debugging process, there are two issues preventing "(A +- CST1) +- CST2 -> A + CST3" from being applied: A) before we reach this pattern, there is pattern:
/* A - B -> A + (-B) if B is easily negatable. */ (simplify (minus @0 negate_expr_p@1) (if (!FIXED_POINT_TYPE_P (type)) (plus @0 (negate @1)))) which is matched and returned in gimple_simplify_MINUS_EXPR. So does pattern order matter here? B) When folding "_124 - 1" on the basis of existing stmts sequence like "_124 = _197 + 1;". The corresponding gimple-match.c code is like: if (gimple_nop_convert (op0, op0_pops, valueize)) { tree o20 = op0_pops[0]; switch (TREE_CODE (o20)) { case SSA_NAME: if (do_valueize (valueize, o20) != NULL_TREE) { gimple *def_stmt = SSA_NAME_DEF_STMT (o20); if (gassign *def = dyn_cast <gassign *> (def_stmt)) switch (gimple_assign_rhs_code (def)) { case PLUS_EXPR: { tree o30 = gimple_assign_rhs1 (def); if ((o30 = do_valueize (valueize, o30))) { tree o31 = gimple_assign_rhs2 (def); if ((o31 = do_valueize (valueize, o31))) { if (tree_swap_operands_p (o30, o31)) std::swap (o30, o31); if (CONSTANT_CLASS_P (o31)) { if (CONSTANT_CLASS_P (op1)) { { /* #line 1392 "../../gcc/gcc/match.pd" */ tree captures[3] ATTRIBUTE_UNUSED = { o30, o31, op1 }; if (gimple_simplify_194 (res_code, res_ops, seq, valueize, type, captures, PLUS_EXPR, MINUS_EXPR, MINUS_EXPR)) return true; } } } } } break; } Note we have: (gdb) call debug_generic_expr(op0) _124 (gdb) call debug_generic_expr(op1) 1 (gdb) call debug_gimple_stmt(def_stmt) _124 = _197 + 1; (gdb) call debug_generic_expr(o30) _197 But since definition of _197 isn't in current stmt sequence, call "o31 = do_valueize (valueize, o31)" will return NULL. As a result, it's not matched. Any ideas? Thanks. Thanks, bin