From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1251) id 980B23858D38; Tue, 13 Jun 2023 16:22:14 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 980B23858D38 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1686673334; bh=AI/1D6PyWtxW5LUy1kV3P03U6WVs7sB1mCs2DuHEDYw=; h=From:To:Subject:Date:From; b=wwHt3vsaaED0HGRqpCMAvenmtLir/cgQ4HJZwYiQd8GR4PZLODlUX4JntHFm0yDr0 +p1uRPp5gNdtIhv1c21F3YXJiiCEjJYuPxgWx+/Er9p4+sSgnG4rFNfql/g813X3io eDGbOKB/AOlN3Qgt0zU01umL8900nrBRVFfXeQQ4= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Roger Sayle To: gcc-cvs@gcc.gnu.org Subject: [gcc r14-1791] Avoid duplicate vector initializations during RTL expansion. X-Act-Checkin: gcc X-Git-Author: Roger Sayle X-Git-Refname: refs/heads/master X-Git-Oldrev: 06a0f07220cea449b4683f9bb9cce2e5de1e5a35 X-Git-Newrev: 40eafcd83d6ee644ec48985fd5a9696921ea10e7 Message-Id: <20230613162214.980B23858D38@sourceware.org> Date: Tue, 13 Jun 2023 16:22:14 +0000 (GMT) List-Id: https://gcc.gnu.org/g:40eafcd83d6ee644ec48985fd5a9696921ea10e7 commit r14-1791-g40eafcd83d6ee644ec48985fd5a9696921ea10e7 Author: Roger Sayle Date: Tue Jun 13 17:20:31 2023 +0100 Avoid duplicate vector initializations during RTL expansion. This middle-end patch avoids some redundant RTL for vector initialization during RTL expansion. For the simple test case: typedef __int128 v1ti __attribute__ ((__vector_size__ (16))); __int128 key; v1ti foo() { return (v1ti){key}; } the middle-end currently expands: (set (reg:V1TI 85) (const_vector:V1TI [ (const_int 0) ])) (set (reg:V1TI 85) (mem/c:V1TI (symbol_ref:DI ("key")))) where we create a dead instruction that initializes the vector to zero, immediately followed by a set of the entire vector. This patch skips this zeroing instruction when the vector has only a single element. It also updates the code to indicate when we've cleared the vector, so that we don't need to initialize zero elements. 2023-06-13 Roger Sayle gcc/ChangeLog * expr.cc (store_constructor) : Don't bother clearing vectors with only a single element. Set CLEARED if the vector was initialized to zero. Diff: --- gcc/expr.cc | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/gcc/expr.cc b/gcc/expr.cc index 868fa6e4cca..62cd8facf75 100644 --- a/gcc/expr.cc +++ b/gcc/expr.cc @@ -7531,8 +7531,11 @@ store_constructor (tree exp, rtx target, int cleared, poly_int64 size, } /* Inform later passes that the old value is dead. */ - if (!cleared && !vector && REG_P (target)) - emit_move_insn (target, CONST0_RTX (mode)); + if (!cleared && !vector && REG_P (target) && maybe_gt (n_elts, 1u)) + { + emit_move_insn (target, CONST0_RTX (mode)); + cleared = 1; + } if (MEM_P (target)) alias = MEM_ALIAS_SET (target);