On Mon, Sep 14, 2020 at 5:19 AM Feng Xue OS via Gcc-patches <gcc-patches@gcc.gnu.org> wrote: > > Thanks, > Feng > > ________________________________________ > From: Feng Xue OS <f...@os.amperecomputing.com> > Sent: Thursday, September 3, 2020 5:29 PM > To: Richard Biener; gcc-patches@gcc.gnu.org > Subject: Re: [PATCH 2/2 V3] Simplify plusminus-mult-with-convert expr in > forwprop (PR 94234) > > Attach patch file. > > Feng > ________________________________________ > From: Gcc-patches <gcc-patches-boun...@gcc.gnu.org> on behalf of Feng Xue OS > via Gcc-patches <gcc-patches@gcc.gnu.org> > Sent: Thursday, September 3, 2020 5:27 PM > To: Richard Biener; gcc-patches@gcc.gnu.org > Subject: [PATCH 2/2 V3] Simplify plusminus-mult-with-convert expr in forwprop > (PR 94234) > > This patch is to handle simplification of plusminus-mult-with-convert > expression > as ((T) X) +- ((T) Y), in which at least one of (X, Y) is result of > multiplication. > This is done in forwprop pass. We try to transform it to (T) (X +- Y), and > resort > to gimple-matcher to fold (X +- Y) instead of manually code pattern > recognition.
I still don't like the complete new function with all its correctness issues - the existing fold_plusminus_mult_expr was difficult enough to get correct for corner cases and we do have a set of match.pd patterns (partly?) implementing its transforms. Looking at +unsigned goo (unsigned m_param, unsigned n_param) +{ + unsigned b1 = m_param * (n_param + 2); + unsigned b2 = m_param * (n_param + 1); + int r = (int)(b1) - (int)(b2); it seems we want to simplify (signed)A - (signed)B to (signed)(A - B) if A - B "simplifies"? I guess (simplify (plusminus (nop_convert @0) (nop_convert? @1)) (convert (plusminus! @0 @1))) probably needs a swapped pattern or not iterate over plus/minus to handle at least one converted operand and avoid adding a (plus @0 @1) -> (convert (plus! @0 @1)) rule. Even (simplify (minus (nop_convert @0) (nop_convert @1)) (convert (minus! @0 @1))) seems to handle all your testcases already (which means they are all the same and not very exhaustive...) Richard. > Regards, > Feng > --- > 2020-09-03 Feng Xue <f...@os.amperecomputing.com> > > gcc/ > PR tree-optimization/94234 > * tree-ssa-forwprop.c (simplify_plusminus_mult_with_convert): New > function. > (fwprop_ssa_val): Move it before its new caller. > (pass_forwprop::execute): Add call to > simplify_plusminus_mult_with_convert. > > gcc/testsuite/ > PR tree-optimization/94234 > * gcc.dg/pr94234-3.c: New test.