From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2001:67c:2178:6::1d]) by sourceware.org (Postfix) with ESMTPS id 97C2F3858D35 for ; Thu, 16 Mar 2023 16:30:39 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 97C2F3858D35 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=suse.cz Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=suse.cz 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-out2.suse.de (Postfix) with ESMTPS id 6E9191FE15; Thu, 16 Mar 2023 16:30:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1678984238; 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=Kw3KZWUo8OryMca4NAjbcgfj/Sw2dUgq07rwVIfa/L8=; b=h1PadNHOMz+ayla1zmyzcFAUtqdQaHaURXjpK3TtJVpkrGtHkYN7EQ+Ln8rXvm9yZDnBf+ UgRkcpAXh7NBiw9n1g8BQFvKLxgrPJpaEj851MWlABhZDmXS4lM8sOX0mCfTtrt7zlh1+j rHAxoFkhvTomb9LHw32yUna82ZYZjGk= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1678984238; 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=Kw3KZWUo8OryMca4NAjbcgfj/Sw2dUgq07rwVIfa/L8=; b=6XPChmQ9peT/LgLFDsaB2H+FJ9zp4zHDswROaRsG+IHDDzj5AiH1PccOW9/3Q3XG65h3Dj ZvMpseRMoyeXTPDw== 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 5E5C1133E0; Thu, 16 Mar 2023 16:30:38 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id gcbLFi5EE2QZLQAAMHmgww (envelope-from ); Thu, 16 Mar 2023 16:30:38 +0000 From: Martin Jambor To: Pierrick Philippe , gcc@gcc.gnu.org Cc: Subject: Re: [Tree-SSA] Question from observation, bogus SSA form? In-Reply-To: References: User-Agent: Notmuch/0.37 (https://notmuchmail.org) Emacs/28.2 (x86_64-suse-linux-gnu) Date: Thu, 16 Mar 2023 17:30:37 +0100 Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-3.9 required=5.0 tests=BAYES_00,BODY_8BITS,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_SOFTFAIL,TXREP autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Hello Pierrick, On Thu, Mar 16 2023, Pierrick Philippe wrote: > Hi everyone, > > I was working around with the analyzer, but I usually dump the SSA-tree=20 > to get a view of the analyzed code. > This is how I noticed something wrong, at least in the sense of the=20 > definition of SSA form. please note that only some DECLs are put into a SSA form in GCC, these are sometimes referred to as "gimple registers" and you can query the predicate is_gimple_reg to figure out whether a DECL is one (putting aside "virtual operands" which are a special construct of alias analysis, are in an SSA form but the predicate returns false for them for some reason). This means that global variables, volatile variables, aggregates, variables which are not considered aggregates but are nevertheless partially modified (think insertion into a vector) or variables which need to live in memory (most probably because their address was taken) are not put into an SSA form. It may not be easily possible. > > I'm using a version of gcc build from a /trunk/ branch (/20230309/). > > Here is an example code: > > ''' > int main(void) { > =C2=A0=C2=A0=C2=A0 int x =3D 42; > =C2=A0=C2=A0=C2=A0 int * y =3D &x; Here you take address of x which therefore has to live in memory at least as long as y is not optimized away. > =C2=A0=C2=A0=C2=A0 x =3D 6; > =C2=A0=C2=A0=C2=A0 return x; > } > ''' > > And here is the output from -fdump-tree-ssa-vops: > > ''' > ;; Function main (main, funcdef_no=3D0, decl_uid=3D2739, cgraph_uid=3D1,= =20 > symbol_order=3D0) > > int main () > { > =C2=A0 int * y; > =C2=A0 int x; > =C2=A0 int D.2744; > =C2=A0 int _5; > > =C2=A0 : > =C2=A0 # .MEM_2 =3D VDEF <.MEM_1(D)> > =C2=A0 x =3D 42;=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2= =A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0 /= / First assignment=20 > to var_decl x > =C2=A0 y_3 =3D &x; > =C2=A0 # .MEM_4 =3D VDEF <.MEM_2> > =C2=A0 x =3D 6;=C2=A0=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0= =C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2= =A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0= =C2=A0=C2=A0 // Second=20 > assignment to var_decl x > =C2=A0 # VUSE <.MEM_4> > =C2=A0 _5 =3D x; > =C2=A0 # .MEM_6 =3D VDEF <.MEM_4> > =C2=A0 x =3D{v} {CLOBBER(eol)}; > > =C2=A0 : > : > =C2=A0 # VUSE <.MEM_6> > =C2=A0 return _5; > > } > ''' > > The thing is, there is two distinct assignment to the same LHS tree at=20 > two different gimple statement, which is by definition not supposed to=20 > happened in SSA form. I think it is now clear that x is not in SSA form because (at this stage of the compilation) it is still considered to need to live in memory. > Is there any particular reason this happen? Is that because the address=20 > of x is taken and stored? > > I have to precise, I did not dig into the SSA form transformation and am= =20 > a newbie to gcc source code. > So maybe my question is a bit naive or a known issue. No worries, we know these important details are not straightforward when you see them for the first time. Good luck with your gcc hacking! Martin