From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id A07A8389683B; Thu, 30 Apr 2020 08:09:10 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A07A8389683B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1588234150; bh=SiunAwvifV9oZGs6imqDUBx5OPnwViJ2ZiQuJ0+BWJU=; h=From:To:Subject:Date:In-Reply-To:References:From; b=QGudC1RFpJmLRZBmXmW4BX29qSjtdgIWnUS9Mu58mXQKpnoYr1z7kgxg8llW7nAhp bmzCSu5X05OZubNNtvJmjpDAoRmFBnpv3iKAxm9tUh0m6ZD8Wxj6sYJxlnJ2HOQt2S BH8+l1CsnKOezCHfLojwTlbPi9lOAYHYRhnaFfWs= From: "rguenth at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/94836] Failure to optimize condition based on known value of static variable Date: Thu, 30 Apr 2020 08:09:10 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: tree-optimization X-Bugzilla-Version: 10.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: rguenth at gcc dot gnu.org X-Bugzilla-Status: ASSIGNED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: rguenth at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 30 Apr 2020 08:09:10 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D94836 --- Comment #2 from Richard Biener --- OK, so it's not that easy to do. Consider int f(int x) { static int s; if (!s) s =3D x; return s; } which we cannot optimize in this way. VN would need to work in a way assigning the value 0 to 's' optimistically and if it eventually arrives at s =3D x it would need to invalidate that optimistic assumption and iterate. That is it would need to see the function as int f(int x) { static int s; # s =3D PHI <0, s'> if (!s) s =3D x; return s; s' =3D s; goto start; } with the goto of course not explicit. I suppose rather than integrating the feature into their value-numbering scheme compilers implement special purpose optimization (IIRC this pattern appears in SPEC).=