From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by sourceware.org (Postfix) with ESMTPS id 7325A3858D37 for ; Tue, 5 Apr 2022 08:50:02 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 7325A3858D37 Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out2.suse.de (Postfix) with ESMTP id 5CFA01F856; Tue, 5 Apr 2022 08:50:01 +0000 (UTC) Received: from murzim.suse.de (murzim.suse.de [10.160.4.192]) (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 3F0F5A3B93; Tue, 5 Apr 2022 08:50:01 +0000 (UTC) Date: Tue, 5 Apr 2022 10:50:01 +0200 (CEST) From: Richard Biener To: Jakub Jelinek cc: gcc-patches@gcc.gnu.org Subject: Re: [PATCH] match.pd: Punt on optimizing sqrt with incorrect arg type [PR105150] In-Reply-To: Message-ID: References: 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.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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: Tue, 05 Apr 2022 08:50:03 -0000 On Tue, 5 Apr 2022, Jakub Jelinek wrote: > Hi! > > In the following testcase sqrt is declared as unprototyped function > and so it depends on what type has the argument passed to it. > If an argument of incorrect type is passed, the sqrt comparison > simplification can create invalid GIMPLE. > > The patch fixes it by punting if there is a mismatch of types. > As I didn't want to reindent 133 lines, the first hunk contains an > ugly hack with if (false). If you prefer reindentation, I can do that > too. > > Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? So why does this get pas gimple_call_combined_fn ()? Are those internal functions at the point we match them? Otherwise we invoke gimple_builtin_call_types_compatible_p on them. If they are internal functions why did we rewrite the calls to them when the types do not match? If gimple_builtin_call_types_compatible_p is fine then why did the frontend assign BUILT_IN_SQRT to the function decls? Richard. > 2022-04-05 Jakub Jelinek > > PR tree-optimization/105150 > * match.pd (sqrt (x) cmp real_cst, sqrt (x) cmp sqrt (y)): Punt > if sqrt operand has incompatible types. > > * gcc.dg/pr105150.c: New test. > > --- gcc/match.pd.jj 2022-03-18 18:32:36.000000000 +0100 > +++ gcc/match.pd 2022-04-04 19:49:28.621934784 +0200 > @@ -4927,6 +4927,10 @@ (define_operator_list SYNC_FETCH_AND_AND > (simplify > (cmp (sq @0) REAL_CST@1) > (switch > + (if (!types_match (TREE_TYPE (@0), TREE_TYPE (@1))) > + /* Punt if there is a type mismatch. */ > + (if (false) > + @1)) > (if (REAL_VALUE_NEGATIVE (TREE_REAL_CST (@1))) > (switch > /* sqrt(x) < y is always false, if y is negative. */ > @@ -5062,7 +5066,7 @@ (define_operator_list SYNC_FETCH_AND_AND > /* Transform sqrt(x) cmp sqrt(y) -> x cmp y. */ > (simplify > (cmp (sq @0) (sq @1)) > - (if (! HONOR_NANS (@0)) > + (if (! HONOR_NANS (@0) && types_match (TREE_TYPE (@0), TREE_TYPE (@1))) > (cmp @0 @1)))))) > > /* Optimize various special cases of (FTYPE) N CMP (FTYPE) M. */ > --- gcc/testsuite/gcc.dg/pr105150.c.jj 2022-04-04 19:53:03.597935060 +0200 > +++ gcc/testsuite/gcc.dg/pr105150.c 2022-04-04 19:54:55.734370333 +0200 > @@ -0,0 +1,8 @@ > +/* PR tree-optimization/105150 */ > +/* { dg-options "-w -Ofast" } */ > + > +#define A(name) __typeof (__builtin_##name (0)) name (); \ > + float name##1 () { return !name (1); } \ > + double name##2 () { return name (1.0L); } > +#define B(name) A(name) A(name##l) > +B (sqrt) > > Jakub > > -- Richard Biener SUSE Software Solutions Germany GmbH, Maxfeldstrasse 5, 90409 Nuernberg, Germany; GF: Ivo Totev; HRB 36809 (AG Nuernberg)