From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1666) id 5105A383B6DA; Tue, 13 Dec 2022 14:17:36 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5105A383B6DA DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1670941056; bh=+GzTiSXL42SBMDYwZiWpnsVPcmYKjSFSTcw1yz12GX0=; h=From:To:Subject:Date:From; b=JqDgQOVTQTlQOtxEim0v/qd//REeM0Co9o8QIGF2XeY5GIhUe3EjGGqw/rVWWZV7B k3uc7ZCJMAgZ7ML3VWFCrBiBEswzH1TZ7Lo6VellkdOXZ7rS0UK8SnfdprmsrsO2NB AvM4WXKXwmuEyusjB95cEk4WMYm0Q48oswNiIQvk= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Richard Biener To: gcc-cvs@gcc.gnu.org Subject: [gcc r13-4678] tree-optimization/105801 - CCP and .DEFERRED_INIT X-Act-Checkin: gcc X-Git-Author: Richard Biener X-Git-Refname: refs/heads/master X-Git-Oldrev: edc676cfe8988c62c81b0df224c7fe82583012b1 X-Git-Newrev: 8f4634fb82d5670183d0ee42de9dae3b55ab5087 Message-Id: <20221213141736.5105A383B6DA@sourceware.org> Date: Tue, 13 Dec 2022 14:17:36 +0000 (GMT) List-Id: https://gcc.gnu.org/g:8f4634fb82d5670183d0ee42de9dae3b55ab5087 commit r13-4678-g8f4634fb82d5670183d0ee42de9dae3b55ab5087 Author: Richard Biener Date: Tue Dec 13 14:24:02 2022 +0100 tree-optimization/105801 - CCP and .DEFERRED_INIT 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. Diff: --- 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(-) 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;