From patchwork Mon Oct 4 11:44:28 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 1536071 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=N+Jf2Sp0; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4HNJnK0Llnz9t25 for ; Mon, 4 Oct 2021 22:45:41 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E20613857807 for ; Mon, 4 Oct 2021 11:45:37 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E20613857807 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1633347937; bh=Eg0ab9zKAwPKpF1SAFbqHLjqnm1eG4ADYl3ZIpyAW40=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=N+Jf2Sp0PdrHEYDeohSuPwA8znJRm7RBIx0q6PcbkdsXTtx6zRoKFWDZCPaiCQTXL nb0NsjdLb0nyZa0pmENrjCJoamj5SFlSW7eXtLCVnXazlGqW7bYe9f42y2tbqnPa1Z JR/wykYgF1omgIGA/mRubw1jAZFN5xsA6QRTvErg= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by sourceware.org (Postfix) with ESMTPS id E9ED83858020 for ; Mon, 4 Oct 2021 11:44:29 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org E9ED83858020 Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id A2913201E1 for ; Mon, 4 Oct 2021 11:44:28 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id DFD801348D for ; Mon, 4 Oct 2021 11:44:02 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id 5qpXNQLpWmHPCQAAMHmgww (envelope-from ) for ; Mon, 04 Oct 2021 11:44:02 +0000 Date: Mon, 4 Oct 2021 13:44:28 +0200 (CEST) To: gcc-patches@gcc.gnu.org Subject: [PATCH] middle-end/102285 - refine .DEFERRED_INIT expansion Message-ID: <8445pq45-80n1-p8q1-37q5-nr6163op9021@fhfr.qr> MIME-Version: 1.0 X-Spam-Status: No, score=-11.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Richard Biener via Gcc-patches From: Richard Biener Reply-To: Richard Biener Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" This refines the way we figure whether we are facing a register that cannot be initialized by emitting a memset away from inspecting expanded RTL of the LHS to using the predicates expand_assignment is using to detect decls or MEM_REFs with non-memory DECL_RTL. Bootstrapped and tested on x86_64-unknown-linux-gnu, I'm double-checking the testsuite with -ftrivial-auto-var-init=zero right now. Richard. 2021-10-04 Richard Biener * expr.h (non_mem_decl_p): Declare. (mem_ref_refers_to_non_mem_p): Likewise. * expr.c (non_mem_decl_p): Export. (mem_ref_refers_to_non_mem_p): Likewise. * internal-fn.c (expand_DEFERRED_INIT): Do not expand the LHS but check the base with mem_ref_refers_to_non_mem_p and non_mem_decl_p. * c-c++-common/pr102285.c: New testcase. --- gcc/expr.c | 4 ++-- gcc/expr.h | 3 +++ gcc/internal-fn.c | 7 +++++-- gcc/testsuite/c-c++-common/pr102285.c | 10 ++++++++++ 4 files changed, 20 insertions(+), 4 deletions(-) create mode 100644 gcc/testsuite/c-c++-common/pr102285.c diff --git a/gcc/expr.c b/gcc/expr.c index e0bcbccd905..eb33643bd77 100644 --- a/gcc/expr.c +++ b/gcc/expr.c @@ -5305,7 +5305,7 @@ get_bit_range (poly_uint64_pod *bitstart, poly_uint64_pod *bitend, tree exp, has non-BLKmode. DECL_RTL must not be a MEM; if DECL_RTL was not set yet, return false. */ -static inline bool +bool non_mem_decl_p (tree base) { if (!DECL_P (base) @@ -5322,7 +5322,7 @@ non_mem_decl_p (tree base) /* Returns true if REF refers to an object that does not reside in memory and has non-BLKmode. */ -static inline bool +bool mem_ref_refers_to_non_mem_p (tree ref) { tree base; diff --git a/gcc/expr.h b/gcc/expr.h index 94a85b40dca..890ec19ac7e 100644 --- a/gcc/expr.h +++ b/gcc/expr.h @@ -346,4 +346,7 @@ extern void expand_operands (tree, tree, rtx, rtx*, rtx*, /* Return an rtx for the size in bytes of the value of an expr. */ extern rtx expr_size (tree); +extern bool mem_ref_refers_to_non_mem_p (tree); +extern bool non_mem_decl_p (tree); + #endif /* GCC_EXPR_H */ diff --git a/gcc/internal-fn.c b/gcc/internal-fn.c index ef5dc90db56..110145218b9 100644 --- a/gcc/internal-fn.c +++ b/gcc/internal-fn.c @@ -3015,8 +3015,11 @@ expand_DEFERRED_INIT (internal_fn, gcall *stmt) reg_lhs = true; else { - rtx tem = expand_expr (lhs, NULL_RTX, VOIDmode, EXPAND_WRITE); - reg_lhs = !MEM_P (tem); + tree lhs_base = lhs; + while (handled_component_p (lhs_base)) + lhs_base = TREE_OPERAND (lhs_base, 0); + reg_lhs = (mem_ref_refers_to_non_mem_p (lhs_base) + || non_mem_decl_p (lhs_base)); } if (!reg_lhs) diff --git a/gcc/testsuite/c-c++-common/pr102285.c b/gcc/testsuite/c-c++-common/pr102285.c new file mode 100644 index 00000000000..644054ba585 --- /dev/null +++ b/gcc/testsuite/c-c++-common/pr102285.c @@ -0,0 +1,10 @@ +/* { dg-do compile } */ +/* { dg-options "-O -ftrivial-auto-var-init=zero -Wuninitialized" } */ + +int +qy (void) +{ + int tw = 4; + int fb[tw]; + return fb[2]; /* { dg-warning "uninitialized" } */ +}