public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Richard Biener <rguenther@suse.de>
To: gcc-patches@gcc.gnu.org
Cc: keescook@chromium.org
Subject: [PATCH] tree-optimization/105801 - CCP and .DEFERRED_INIT
Date: Tue, 13 Dec 2022 14:10:09 +0000 (UTC)	[thread overview]
Message-ID: <20221213141009.iYaREhXOCMQjRvfC_sPbtkfebY1gs_H8Wnp_BWva7ds@z> (raw)

This makes sure we treat .DEFERRED_INIT as producing UNDEFINED so
we can continue optimizing uninitialized uses the same as without
-ftrivial-auto-var-init=zero.  For the testcase this means we
catch the return 1 optimization opportunity at CCP rather than
only at FRE which already does the right thing here.

Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed to
trunk sofar.

Richard.

	PR tree-optimization/105801
	* tree-ssa-ccp.cc (likely_value): .DEFERRED_INIT produces
	UNDEFINED.
	* doc/invoke.texi (ftrivial-auto-var-init): Explicitely
	mention we treat variables without an initializer as
	undefined also for optimization purposes.

	* gcc.dg/tree-ssa/ssa-ccp-43.c: New testcase.
---
 gcc/doc/invoke.texi                        |  3 ++-
 gcc/testsuite/gcc.dg/tree-ssa/ssa-ccp-43.c | 12 ++++++++++++
 gcc/tree-ssa-ccp.cc                        |  4 ++++
 3 files changed, 18 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/ssa-ccp-43.c

diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index cb40b38b73a..13371972fd1 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -13208,7 +13208,8 @@ disclosure and use.
 GCC still considers an automatic variable that doesn't have an explicit
 initializer as uninitialized, @option{-Wuninitialized} and
 @option{-Wanalyzer-use-of-uninitialized-value} will still report
-warning messages on such automatic variables.
+warning messages on such automatic variables and the compiler will
+perform optimization as if the variable were uninitialized.
 With this option, GCC will also initialize any padding of automatic variables
 that have structure or union types to zeroes.
 However, the current implementation cannot initialize automatic variables that
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/ssa-ccp-43.c b/gcc/testsuite/gcc.dg/tree-ssa/ssa-ccp-43.c
new file mode 100644
index 00000000000..3e0a3d659d1
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-ssa/ssa-ccp-43.c
@@ -0,0 +1,12 @@
+/* { dg-do compile } */
+/* { dg-options "-O -ftrivial-auto-var-init=zero -fdump-tree-ccp1" } */
+
+int foo (int flag)
+{
+  int i;
+  if (flag)
+    i = 1;
+  return i;
+}
+
+/* { dg-final { scan-tree-dump "return 1;" "ccp1" } } */
diff --git a/gcc/tree-ssa-ccp.cc b/gcc/tree-ssa-ccp.cc
index 68e69bfe129..0d47289b31d 100644
--- a/gcc/tree-ssa-ccp.cc
+++ b/gcc/tree-ssa-ccp.cc
@@ -722,6 +722,10 @@ likely_value (gimple *stmt)
   if (gimple_has_volatile_ops (stmt))
     return VARYING;
 
+  /* .DEFERRED_INIT produces undefined.  */
+  if (gimple_call_internal_p (stmt, IFN_DEFERRED_INIT))
+    return UNDEFINED;
+
   /* Arrive here for more complex cases.  */
   has_constant_operand = false;
   has_undefined_operand = false;
-- 
2.35.3

                 reply	other threads:[~2022-12-13 14:10 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20221213141009.iYaREhXOCMQjRvfC_sPbtkfebY1gs_H8Wnp_BWva7ds@z \
    --to=rguenther@suse.de \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=keescook@chromium.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).