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 06C39383D5DE for ; Tue, 13 Dec 2022 14:10:11 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 06C39383D5DE Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.de Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out2.suse.de (Postfix) with ESMTP id EF9FA1FDD9; Tue, 13 Dec 2022 14:10:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1670940609; h=from:from:reply-to:date:date:to:to:cc:cc:mime-version:mime-version: content-type:content-type; bh=Uto7mV+ldQqbKlOUxz45zL2uH2VmfbxCscCknePtAcs=; b=hWKaj/1mgO6yKui8D1OUvDt2nA7fKdLuxjrwBM2yOMyUzosS0iyrYsUMf9qeFZqhFC++Ew tJC28xm//7GAa75oIiFEDtZCW5QhmpwE+JdIlts0vVZjbMF7zzHMcGaIlebYaFLZfcb+5U 0SEKyc3ziH5QDYtGg3gM7dC3XBNql7E= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1670940609; h=from:from:reply-to:date:date:to:to:cc:cc:mime-version:mime-version: content-type:content-type; bh=Uto7mV+ldQqbKlOUxz45zL2uH2VmfbxCscCknePtAcs=; b=8iyRsoXVOrEOJ9zFEz8TTtwlIMgYWGJqxvt7P9EuN7Ku1M3FuIqdlWKy0c1tvH2QuQyYVZ yn6cumbT2uQd3HCA== Received: from wotan.suse.de (wotan.suse.de [10.160.0.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by relay2.suse.de (Postfix) with ESMTPS id E89272C141; Tue, 13 Dec 2022 14:10:09 +0000 (UTC) Date: Tue, 13 Dec 2022 14:10:09 +0000 (UTC) From: Richard Biener To: gcc-patches@gcc.gnu.org cc: keescook@chromium.org Subject: [PATCH] tree-optimization/105801 - CCP and .DEFERRED_INIT User-Agent: Alpine 2.22 (LSU 394 2020-01-19) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-Spam-Status: No, score=-10.6 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,MISSING_MID,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Message-ID: <20221213141009.iYaREhXOCMQjRvfC_sPbtkfebY1gs_H8Wnp_BWva7ds@z> 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