On Fri, Oct 30, 2015 at 11:26 AM, Marc Glisse <marc.gli...@inria.fr> wrote: > On Fri, 30 Oct 2015, Richard Biener wrote: > >> +/* Convert (A + A) * C -> A * 2 * C. */ >> +(simplify >> + (mult:c (convert? (plus @0 @0)) (convert? @1)) >> + (if (tree_nop_conversion_p (TREE_TYPE (@0), type)) >> + (convert (mult @0 (mult { build_int_cst (TREE_TYPE (@1), 2); } @1))))) >> +(simplify >> + (mult:c (convert? (plus @0 @0)) INTEGER_CST@1) >> + (if (tree_nop_conversion_p (TREE_TYPE (@0), type)) >> + (convert (mult @0 (mult { build_int_cst (TREE_TYPE (@1), 2); } @1))))) >> >> fold-const.c only handles constant C, so we only need to 2nd pattern. >> Also the :c on the mult in that is not needed due to canonicalization >> rules. >> Please build the result of the inner multiplication directly. >> I think the fold-const.c code has an overflow issue when the outer >> multiplication >> is signed and the inner addition unsigned. (signed)((unsigned)INT_MAX >> + (unsigned)INT_MAX)*2 >> is valid but INT_MAX * 4 is not as it overflows. So I think we should >> _not_ allow >> nop conversions here (it's fine if all ops are signed or unsigned). > > > Is there a reason why the simple transformation A+A->2*A is not > generally a desirable canonicalization? We currently restrict it to > SCALAR_FLOAT_TYPE_P.
No special reason I know of. > > -- > Marc Glisse