On Tue, Dec 17, 2019 at 6:33 PM Hongtao Liu <crazy...@gmail.com> wrote: > > Hi: > This patch is to simplify A * C + (-D) -> (A - D/C) * C when C is a > power of 2 and D mod C == 0. > bootstrap and make check is ok.
I don't see why D has to be negative here. >TREE_CODE (TREE_TYPE (@0)) == INTEGER_TYPE + && TYPE_UNSIGNED (TREE_TYPE (@0)) This is the wrong check here. Use INTEGRAL_TYPE_P . >+ (plus (mult @0 integer_pow2p@1) INTEGER_CST@2) You might want a :s here for the mult and/or plus. unsigned HOST_WIDE_INT d = tree_to_uhwi (@2); ... Maybe use wide_int math instead of HOST_WIDE_INT here, then you don't need the tree_fits_uhwi_p check. Add a testcase should tests the pattern directly rather than indirectly. Also we are in stage 3 which means bug fixes only so this might/should wait until stage 1. Thanks, Andrew Pinski > > changelog > gcc/ > * gcc/match.pd (A * C + (-D) = (A - D/C) * C. when C is a > power of 2 and D mod C == 0): Add new simplification. > > gcc/testsuite > * gcc.dg/pr92980.c: New test. > > -- > BR, > Hongtao