On Fri, Jul 14, 2017 at 7:59 AM, Marc Glisse <marc.gli...@inria.fr> wrote: > On Thu, 13 Jul 2017, Alexander Monakov wrote: > >> On Thu, 13 Jul 2017, Marc Glisse wrote: >>> >>> I notice that we do not turn (X*10)*10 into X*100 in GIMPLE. >> >> >> Sorry, could you clarify what you mean here? I think we certainly do >> that, >> just not via match.pd, but in 'associate:' case of fold_binary_loc. > > > fold_binary_loc is for GENERIC, so mostly for front-end time optimization of > expressions. > > int f(int a){ > int b=a*10; > return b*10; > } > > $ gcc-snapshot -O3 -S -fdump-tree-optimized a.c > $ cat a.c.228t.optimized > [...] > b_2 = a_1(D) * 10; > _3 = b_2 * 10; > return _3;
Yeah, but I think we best address this by adding support to re-associate expressions with !TYPE_OVERFLOW_WRAPS to the reassoc pass. It's not going to be an easy task if you want to avoid re-writing everything to unsigned arithmetic. Simple cases might be worth doing with patterns (like the case above). Richard. >>> Relying on inner expressions being folded can be slightly dangerous, >>> especially for generic IIRC. It seems easy enough to check that @1 is >>> neither >>> 0 nor -1 for safety. >> >> >> I wanted to add a gcc_checking_assert to that effect, but it's not used in >> match.pd anywhere. Is there a nice way to do that? > > > You can use (with { arbitrary C++ code } ... ) to add an assertion (you can > use @0 in the block of C++ code). > > I was more thinking of an "if" than an assertion though. > > -- > Marc Glisse