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 447133858D33 for ; Tue, 7 Feb 2023 09:28:28 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 447133858D33 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.de Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 5400634FAA; Tue, 7 Feb 2023 09:28:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1675762107; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=leGB+uEc0neeWIQRvpFVfAUHfHYzaAcNFlHfo4ALlp8=; b=zkWPewYATU/CCt/Pk1a5/rQV5m54dBsYbgD+H66y7ejAMjIhpxb4DAs3MMJCH3B5HtcQvQ VIMsJFzWbAg1BiLjUWoTGTOSJWm4rj6WEO4+g9xuXS6c4YzHL9/atmLJ6ITVC7REnDJtGh NYt4KscgcbRJOk/BB3KKgogdtTNH/io= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1675762107; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=leGB+uEc0neeWIQRvpFVfAUHfHYzaAcNFlHfo4ALlp8=; b=itbnAaMwSDtGBFS1/vBUTYQ+p1XvwBwfLUvPFTF9+RhKNTgKg2YoXalM2ouO5rUCJA92ox sqEVYIyrVhWeDgBQ== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 37AB313A8C; Tue, 7 Feb 2023 09:28:27 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id A5WXDbsZ4mP9CAAAMHmgww (envelope-from ); Tue, 07 Feb 2023 09:28:27 +0000 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable From: Richard Biener Mime-Version: 1.0 (1.0) Subject: Re: [PATCH] cgraph: Handle simd clones in cgraph_node::set_{const,pure}_flag [PR106433] Date: Tue, 7 Feb 2023 10:28:16 +0100 Message-Id: <86AB6E8B-6B1A-4A1A-96E0-9A4AB533ACD3@suse.de> References: Cc: Jan Hubicka , gcc-patches@gcc.gnu.org In-Reply-To: To: Jakub Jelinek X-Mailer: iPhone Mail (20D47) X-Spam-Status: No, score=-5.8 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: > Am 07.02.2023 um 09:37 schrieb Jakub Jelinek : >=20 > =EF=BB=BFHi! >=20 > The following testcase ICEs, because we determine only in late pure const > pass that bar is const (the content of the function loses a store to a > global var during dse3 and read from it during cddce2) and local-pure-cons= t2 > makes it const. The cgraph ordering is that post IPA (in late IPA simd > clones are created) bar is processed first, then foo as its caller, then > foo.simdclone* and finally bar.simdclone*. Conceptually I think that is t= he > right ordering which allows for static simd clones to be removed. >=20 > The reason for the ICE is that because bar was marked const, the call to > it lost vops before vectorization, and when we in foo.simdclone* try to > vectorize the call to bar, we replace it with bar.simdclone* which hasn't > been marked const and so needs vops, which we don't add. >=20 > Now, because the simd clones are created from the same IL, just in a loop > with different argument/return value passing, I think generally if the bas= e > function is determined to be const or pure, the simd clones should be too,= > unless e.g. the vectorization causes different optimization decisions, but= > then still the global memory reads if any shouldn't affect what the functi= on > does and global memory stores shouldn't be reachable at runtime. >=20 > So, the following patch changes set_{const,pure}_flag to mark also simd > clones. >=20 > Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? Ok, Thanks, Richard=20 > 2023-02-07 Jakub Jelinek >=20 > PR tree-optimization/106433 > * cgraph.cc (set_const_flag_1): Recurse on simd clones too. > (cgraph_node::set_pure_flag): Call set_pure_flag_1 on simd clones too. >=20 > * gcc.c-torture/compile/pr106433.c: New test. >=20 > --- gcc/cgraph.cc.jj 2023-02-02 10:54:44.327473492 +0100 > +++ gcc/cgraph.cc 2023-02-06 12:28:22.040593063 +0100 > @@ -2764,6 +2764,9 @@ set_const_flag_1 (cgraph_node *node, boo > if (!set_const || alias->get_availability () > AVAIL_INTERPOSABLE) > set_const_flag_1 (alias, set_const, looping, changed); > } > + for (struct cgraph_node *n =3D node->simd_clones; n !=3D NULL; > + n =3D n->simdclone->next_clone) > + set_const_flag_1 (n, set_const, looping, changed); > for (cgraph_edge *e =3D node->callers; e; e =3D e->next_caller) > if (e->caller->thunk > && (!set_const || e->caller->get_availability () > AVAIL_INTERPOSABLE))= > @@ -2876,6 +2879,9 @@ cgraph_node::set_pure_flag (bool pure, b > { > struct set_pure_flag_info info =3D {pure, looping, false}; > call_for_symbol_thunks_and_aliases (set_pure_flag_1, &info, !pure, true)= ; > + for (struct cgraph_node *n =3D simd_clones; n !=3D NULL; > + n =3D n->simdclone->next_clone) > + set_pure_flag_1 (n, &info); > return info.changed; > } >=20 > --- gcc/testsuite/gcc.c-torture/compile/pr106433.c.jj 2023-02-06 12:37:= 26.963748811 +0100 > +++ gcc/testsuite/gcc.c-torture/compile/pr106433.c 2023-02-06 12:37:06.= 631041918 +0100 > @@ -0,0 +1,24 @@ > +/* PR tree-optimization/106433 */ > + > +int m, *p; > + > +__attribute__ ((simd)) int > +bar (int x) > +{ > + if (x) > + { > + if (m < 1) > + for (m =3D 0; m < 1; ++m) > + ++x; > + p =3D &x; > + for (;;) > + ++m; > + } > + return 0; > +} > + > +__attribute__ ((simd)) int > +foo (int x) > +{ > + return bar (x); > +} >=20 > Jakub >=20