From patchwork Wed Aug 3 01:35:19 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Takayuki 'January June' Suwa X-Patchwork-Id: 365 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:6a10:b5d6:b0:2b9:3548:2db5 with SMTP id v22csp53506pxt; Tue, 2 Aug 2022 18:39:14 -0700 (PDT) X-Google-Smtp-Source: AA6agR5FpLXt+pdPyhM2aej4sZh+VYuo8cLNG3AodIXxj/PK54zG3ke52gA80IG5x4E29J+aozHr X-Received: by 2002:a05:6402:2691:b0:43d:ba10:854b with SMTP id w17-20020a056402269100b0043dba10854bmr10174525edd.158.1659490754290; Tue, 02 Aug 2022 18:39:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659490754; cv=none; d=google.com; s=arc-20160816; b=WpOP3bTYE1FfiGSw858FwsoZHUbUYAvSKryAcjx1/1iWqA3s4LgxzamxxlqEvCM9Yv mLkm8XadnIyYbVonSyLR7ydgUGCdYVHGeV2LadrvMh+4PObMj1vIEL67OTSdBAb9kaxk UzQ3gPFbjM/GPrEDbuqmkwIWzebctc/PGt/979KPgLwJkDHIixIr62G1XYE7YP0UCLmQ Swn59tiVhQ7wjRiBzkZVeVCJok/pjXujA2tMB8P9SSR4wzoW1t/rlNO2KyzTD7YFH3IG KxxRa8J5LufKQ9GtYqZpo/8DVZdMrmh4LTUEhv/kfRz6FB3ip4ZM7qyIhNlMcFFSYiyO ORtg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:subject:to:user-agent:mime-version:date :message-id:dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=dRBRtst5wrBt8s/zviW2gP2R2/1M0qyOFNH6KxL28lE=; b=YlXR4UKOXCWixC5bx0zUrbw8obqoUkIYzYtdfuWjAAKvHBcQ3wMmeh4JS8a5o8Y+US 4zxpEP8Pp6J2MU2bHMCl3RiIU14SFu6ibpVMuy6prq4e7BQ7p5VTSl8631hJK1Zj2CGZ YJjEwLp8JkutNz+flZQR4I2aqW34vaBmr8F2s5tH+HTjX14nVWYt34KupPUiKj+Dkk/T PlgcnqdFCyKLRoxyPKL11eBuF/I5nK7kOsBpR6vMN5QjwV5I69aFJGfm1rr22c6p9/BF xFSDmz96Qnb5IViVSbNgc8mIvrLzHwVqn9mwpTdZ2C9xfDXASDXvX2PJO2ZiFTODR8ER SWHw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=HfrU0dSd; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id a20-20020a509b54000000b0043cdab5f1a4si13719795edj.350.2022.08.02.18.39.13 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Aug 2022 18:39:14 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=HfrU0dSd; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E4B7038582BD for ; Wed, 3 Aug 2022 01:39:12 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E4B7038582BD DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1659490752; bh=dRBRtst5wrBt8s/zviW2gP2R2/1M0qyOFNH6KxL28lE=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=HfrU0dSds32LnwD8EehlkUxmnoZZz4QvipBnsgttJamqPYOEy0l1gE50mfary/AAy 2IIyCufpeyhqY8kvimqlXOrfYm5NkocG8X/PpnCg4VuSEt34185/t/JjrlUUL6tQ2r X78PjlNfZn0A/U9UCui9yV+rZ+5c83XDFl052ATk= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from nh605-vm3.bullet.mail.ssk.yahoo.co.jp (nh605-vm3.bullet.mail.ssk.yahoo.co.jp [182.22.90.76]) by sourceware.org (Postfix) with SMTP id 4754F3858D33 for ; Wed, 3 Aug 2022 01:38:26 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 4754F3858D33 Received: from [182.22.66.106] by nh605.bullet.mail.ssk.yahoo.co.jp with NNFMP; 03 Aug 2022 01:38:23 -0000 Received: from [182.22.91.131] by t604.bullet.mail.ssk.yahoo.co.jp with NNFMP; 03 Aug 2022 01:38:23 -0000 Received: from [127.0.0.1] by omp604.mail.ssk.yahoo.co.jp with NNFMP; 03 Aug 2022 01:38:23 -0000 X-Yahoo-Newman-Property: ymail-3 X-Yahoo-Newman-Id: 692827.18559.bm@omp604.mail.ssk.yahoo.co.jp Received: (qmail 58254 invoked by alias); 3 Aug 2022 01:38:23 -0000 Received: from unknown (HELO ?192.168.2.3?) (175.177.45.188 with ) by smtp6009.mail.ssk.ynwp.yahoo.co.jp with SMTP; 3 Aug 2022 01:38:23 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aKz pv3SHlpsFsIh3S1WPNVL31k6fq0Tnqr4OWjBujeN0Js7JgwxaKIPqtSh2zgl gs_M971dqjo7GvBII Message-ID: Date: Wed, 3 Aug 2022 10:35:19 +0900 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.1.0 To: GCC Patches Subject: [PATCH] lower-subreg, expr: Mitigate inefficiencies derived from "(clobber (reg X))" followed by "(set (subreg (reg X)) (...))" X-Spam-Status: No, score=-12.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, 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 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: Takayuki 'January June' Suwa via Gcc-patches From: Takayuki 'January June' Suwa Reply-To: Takayuki 'January June' Suwa Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1740102177096184607?= X-GMAIL-MSGID: =?utf-8?q?1740102177096184607?= Emitting "(clobber (reg X))" before "(set (subreg (reg X)) (...))" keeps data flow consistent, but it also increases register allocation pressure and thus often creates many unwanted register-to-register moves that cannot be optimized away. It seems just analogous to partial register stall which is a famous problem on processors that do register renaming. In my opinion, when the register to be clobbered is a composite of hard ones, we should clobber the individual elements separetely, otherwise clear the entire to zero prior to use as the "init-regs" pass does (like partial register stall workarounds on x86 CPUs). Such redundant zero constant assignments will be removed later in the "cprop_hardreg" pass. This patch may give better output code quality for the reasons above, especially on architectures that don't have DFmode hard registers (On architectures with such hard registers, this patch changes virtually nothing). For example (Espressif ESP8266, Xtensa without FP hard regs): /* example */ double _Complex conjugate(double _Complex z) { __imag__(z) *= -1; return z; } ;; before conjugate: movi.n a6, -1 slli a6, a6, 31 mov.n a8, a2 mov.n a9, a3 mov.n a7, a4 xor a6, a5, a6 mov.n a2, a8 mov.n a3, a9 mov.n a4, a7 mov.n a5, a6 ret.n ;; after conjugate: movi.n a6, -1 slli a6, a6, 31 xor a6, a5, a6 mov.n a5, a6 ret.n gcc/ChangeLog: * lower-subreg.cc (resolve_simple_move): Add zero clear of the entire register immediately after the clobber. * expr.cc (emit_move_complex_parts): Change to clobber the real and imaginary parts separately instead of the whole complex register if possible. --- gcc/expr.cc | 26 ++++++++++++++++++++------ gcc/lower-subreg.cc | 7 ++++++- 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/gcc/expr.cc b/gcc/expr.cc index 80bb1b8a4c5..9732e8fd4e5 100644 --- a/gcc/expr.cc +++ b/gcc/expr.cc @@ -3775,15 +3775,29 @@ emit_move_complex_push (machine_mode mode, rtx x, rtx y) rtx_insn * emit_move_complex_parts (rtx x, rtx y) { - /* Show the output dies here. This is necessary for SUBREGs - of pseudos since we cannot track their lifetimes correctly; - hard regs shouldn't appear here except as return values. */ - if (!reload_completed && !reload_in_progress - && REG_P (x) && !reg_overlap_mentioned_p (x, y)) - emit_clobber (x); + rtx_insn *re_insn, *im_insn; write_complex_part (x, read_complex_part (y, false), false, true); + re_insn = get_last_insn (); write_complex_part (x, read_complex_part (y, true), true, false); + im_insn = get_last_insn (); + + /* Show the output dies here. This is necessary for SUBREGs + of pseudos since we cannot track their lifetimes correctly. */ + if (can_create_pseudo_p () + && REG_P (x) && ! reg_overlap_mentioned_p (x, y)) + { + /* Hard regs shouldn't appear here except as return values. */ + if (HARD_REGISTER_P (x) && REG_NREGS (x) % 2 == 0) + { + emit_insn_before (gen_clobber (SET_DEST (PATTERN (re_insn))), + re_insn); + emit_insn_before (gen_clobber (SET_DEST (PATTERN (im_insn))), + im_insn); + } + else + emit_insn_before (gen_clobber (x), re_insn); + } return get_last_insn (); } diff --git a/gcc/lower-subreg.cc b/gcc/lower-subreg.cc index 03e9326c663..4ff0a7d1556 100644 --- a/gcc/lower-subreg.cc +++ b/gcc/lower-subreg.cc @@ -1086,7 +1086,12 @@ resolve_simple_move (rtx set, rtx_insn *insn) unsigned int i; if (REG_P (dest) && !HARD_REGISTER_NUM_P (REGNO (dest))) - emit_clobber (dest); + { + emit_clobber (dest); + /* We clear the entire of dest with zero after the clobber, + similar to the "init-regs" pass. */ + emit_move_insn (dest, CONST0_RTX (GET_MODE (dest))); + } for (i = 0; i < words; ++i) {