]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
tree-optimization/105801 - CCP and .DEFERRED_INIT
authorRichard Biener <rguenther@suse.de>
Tue, 13 Dec 2022 13:24:02 +0000 (14:24 +0100)
committerRichard Biener <rguenther@suse.de>
Tue, 13 Dec 2022 13:36:02 +0000 (14:36 +0100)
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.

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
gcc/testsuite/gcc.dg/tree-ssa/ssa-ccp-43.c [new file with mode: 0644]
gcc/tree-ssa-ccp.cc

index cb40b38b73af0ce311e0d65c721a176dc15e06c2..13371972fd1cfb605f805f45896c689fbc29a68e 100644 (file)
@@ -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 (file)
index 0000000..3e0a3d6
--- /dev/null
@@ -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" } } */
index 68e69bfe129b40756fd00448ca5af8e16998521b..0d47289b31d8f358cc7eefd52a851be819ce7857 100644 (file)
@@ -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;