From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by sourceware.org (Postfix) with ESMTPS id 950FB3858295 for ; Thu, 2 Jun 2022 09:58:32 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 950FB3858295 Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out1.suse.de (Postfix) with ESMTP id 73D3221B25; Thu, 2 Jun 2022 09:58:31 +0000 (UTC) Received: from wotan.suse.de (wotan.suse.de [10.160.0.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by relay2.suse.de (Postfix) with ESMTPS id 56AB92C141; Thu, 2 Jun 2022 09:58:31 +0000 (UTC) Date: Thu, 2 Jun 2022 09:58:31 +0000 (UTC) From: Richard Biener To: Jakub Jelinek cc: gcc-patches@gcc.gnu.org Subject: Re: [PATCH] match.pd: Optimize __builtin_mul_overflow_p (x, cst, (utype)0) to x > ~(utype)0 / cst [PR30314] In-Reply-To: Message-ID: References: User-Agent: Alpine 2.22 (LSU 394 2020-01-19) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-Spam-Status: No, score=-4.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 02 Jun 2022 09:58:34 -0000 On Thu, 2 Jun 2022, Jakub Jelinek wrote: > On Thu, Jun 02, 2022 at 08:36:42AM +0000, Richard Biener wrote: > > > --- gcc/match.pd.jj 2022-06-01 13:54:32.000654151 +0200 > > > +++ gcc/match.pd 2022-06-01 15:13:35.473084402 +0200 > > > @@ -5969,6 +5969,17 @@ (define_operator_list SYNC_FETCH_AND_AND > > > && (!TYPE_UNSIGNED (TREE_TYPE (@2)) || TYPE_UNSIGNED (TREE_TYPE (@0)))) > > > (ovf @1 @0)))) > > > > > > +/* Optimize __builtin_mul_overflow_p (x, cst, (utype) 0) if all 3 types > > > + are unsigned to x > (umax / cst). */ > > > +(simplify > > > + (imagpart (IFN_MUL_OVERFLOW:cs@2 @0 integer_nonzerop@1)) > > > > does :c work here? I think it is at least ignored, possibly diagnostic > > in genmatch is missing ... > > I saw it used in another pattern, so thought it will work fine: > (cmp:c (realpart (IFN_ADD_OVERFLOW:c@2 @0 @1)) @0) > > And looking at the generated source, I think it does work: > case CFN_MUL_OVERFLOW: > if (gimple_call_num_args (_c1) == 2) > { > tree _q20 = gimple_call_arg (_c1, 0); > _q20 = do_valueize (valueize, _q20); > tree _q21 = gimple_call_arg (_c1, 1); > _q21 = do_valueize (valueize, _q21); > if (integer_nonzerop (_q21)) > { > { > /* #line 5976 "../../gcc/match.pd" */ > tree captures[3] ATTRIBUTE_UNUSED = { _p0, _q20, _q21 }; > if (gimple_simplify_256 (res_op, seq, valueize, type, captures)) > return true; > } > } > if (integer_nonzerop (_q20)) > { > { > /* #line 5976 "../../gcc/match.pd" */ > tree captures[3] ATTRIBUTE_UNUSED = { _p0, _q21, _q20 }; > if (gimple_simplify_256 (res_op, seq, valueize, type, captures)) > return true; > } > } > } > Though, sure, I should test it in the testcase too. Ah yeah, we simply trust :c on functions with two arguments (and explicitely handle CFN_FMA). Richard.