From patchwork Tue Mar 28 01:30:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans-Peter Nilsson X-Patchwork-Id: 75757 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1902313vqo; Mon, 27 Mar 2023 18:31:24 -0700 (PDT) X-Google-Smtp-Source: AKy350absDFbqhbbLJOpDchHYs45cvSBOBcXpaFcGMNZh6woj09t5nhZaA9a9OG141UhW+OYXq9l X-Received: by 2002:a50:fc03:0:b0:500:58d8:b339 with SMTP id i3-20020a50fc03000000b0050058d8b339mr13966682edr.20.1679967084514; Mon, 27 Mar 2023 18:31:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679967084; cv=none; d=google.com; s=arc-20160816; b=kGhR8OJlDdfxfogXCp36/DBkEaQYzAzxrEjQHFKc59D3GfFEg4izjKHBrZPbW0NQcX IYjB2k0TIuQsRCrtMEtl5xDaFXQjECtfqwBwfjwNvfaRzettCGHEDEQZnovGFWlYyzCS 4niXrLK01abkUZ/Xn8cX5mT+SGUnndLrM6PKpiRcCZxsmFSfRyJ8HOrx9TbXGej4y11y rRSuab54/c3m78EV+Vjr/AhsVHqD7f3uT+WMbzZ/u4K5AkzBHWNmfg21/zZ8iIHaQl+l tDNwYMgbMcfqK/FPoL9jR0sLUwyLrrjO2GhFUiEdzVSVthrhw6JB83+fyUjdxrHPNN6k riKQ== 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:date:message-id :content-transfer-encoding:mime-version:subject:to:dmarc-filter :delivered-to:dkim-signature:dkim-filter; bh=2j0Adyp/S7Cbr6hli1jHK8K7AzDW3aovUp0NzGwZE60=; b=g9yTDWuzXRe5cPzMvFtiBUt5SUJE+yeg2enDPbLkDD3JIVRj/KHPFPf5BaIEgAm7wX DU2WD5/knkBwW5fU6lmyEpoMb7NaSuRp636qMCPh/2Zbkgw08xa+Io/V9AmseWKacXf5 gCg0EFaPkkqEmjcSAZsd2QJIn7Bpe3hHca5F47ZcSG5rHH94OysVUHjsQjp+99+I4s/Z 2F81b0V6wA5f4VKHR52x/HC1ntjGwnJiSP+4J5WxOMaiHVbXA/2HQcQGg7UQnTjYliDO ik14ca7uQe5wI5lTmN+NQzroJwNDJHPM/feFOh5Zi1QTI3+Bjqm4oKYPWZgcZDYePLyQ fWrg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=kfQWuLnB; 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 e3-20020a50fb83000000b004ad7203a2c6si31200382edq.230.2023.03.27.18.31.24 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Mar 2023 18:31:24 -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=kfQWuLnB; 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 296463858C54 for ; Tue, 28 Mar 2023 01:31:23 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 296463858C54 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1679967083; bh=2j0Adyp/S7Cbr6hli1jHK8K7AzDW3aovUp0NzGwZE60=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=kfQWuLnBHiNiglAy/J1puT4XOzFgWf0wHwNwu7Ax17QVMV+TNOIFTynYDQWvJvtbl gzBi/tgVY5mvnOJ7EvobuSh8EIfMOjYA7lfVfLWe9sSDse62pYlvaB00I8dZWwL5Wz 3242FHZNspxBc6cpIbMBBqUpH71ZMJN3eGX+4i6Q= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from smtp1.axis.com (smtp1.axis.com [195.60.68.17]) by sourceware.org (Postfix) with ESMTPS id 18CC23858430 for ; Tue, 28 Mar 2023 01:30:39 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 18CC23858430 To: Subject: [committed] CRIS: Add peephole2 to handle gcc.target/cris/rld-legit1.c for LRA MIME-Version: 1.0 Message-ID: <20230328013037.3EFE020417@pchp3.se.axis.com> Date: Tue, 28 Mar 2023 03:30:37 +0200 X-Spam-Status: No, score=-11.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, SPF_HELO_PASS, 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: Hans-Peter Nilsson via Gcc-patches From: Hans-Peter Nilsson Reply-To: Hans-Peter Nilsson 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?1761573165302770241?= X-GMAIL-MSGID: =?utf-8?q?1761573165302770241?= The test-case gcc.target/cris/rld-legit1.c is a reduced test-case that required defining LEGITIMIZE_RELOAD_ADDRESS to stop the address from being decomposed into several insns by reload. Valid but suboptimal code was generated. (Before implementing that hook for CRIS, the same test-case also exposed a bug in reload, and a fix was committed to avoid an ICE; see e.g. git r0-71992-gff0d9879ab0f30 and related commits. But, post-cc0, reload no longer handles this test-case without LEGITIMIZE_RELOAD_ADDRESS helping and there'd again an be ICE for CRIS (again: only if LEGITIMIZE_RELOAD_ADDRESS is disabled). There's a patch to reload to fix that, at https://gcc.gnu.org/pipermail/gcc-patches/2023-February/612039.html) But, LRA also does not handle that test-case gracefully, and like reload without LEGITIMIZE_RELOAD_ADDRESS for CRIS, decomposes the address into a suboptimal (but valid) sequence, about as messy as that from reload, and gcc.target/cris/rld-legit1.c would regress for LRA. There's nothing equivalent to LEGITIMIZE_RELOAD_ADDRESS for LRA. (Stepping through LRA, I can't find an obvious place where to put such a hook. Granted, I haven't seen this kind of messy decomposition in other code, so I'm not insisting a LEGITIMIZE_RELOAD_ADDRESS-like hook is a good idea.) These new peephole2's are required to not regress gcc.target/cris/rld-legit1.c with LRA enabled for CRIS. They don't appear to otherwise make a difference for neither libgcc, newlib libc, my own at-a-glance tests nor coremark, for neither LRA nor reload. * config/cris/cris.md (BW2): New mode-iterator. (lra_szext_decomposed, lra_szext_decomposed_indirect_with_offset): New peephole2s. --- gcc/config/cris/cris.md | 50 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/gcc/config/cris/cris.md b/gcc/config/cris/cris.md index 2bea480a0200..c3de259983c6 100644 --- a/gcc/config/cris/cris.md +++ b/gcc/config/cris/cris.md @@ -183,6 +183,10 @@ (define_mode_iterator SI_ [SI]) (define_mode_iterator WD [SI HI]) (define_mode_iterator BW [HI QI]) + +; Another "BW" for use where an independent iteration is needed. +(define_mode_iterator BW2 [HI QI]) + (define_mode_attr S [(SI "HI") (HI "QI")]) (define_mode_attr s [(SI "hi") (HI "qi")]) (define_mode_attr m [(SI ".d") (HI ".w") (QI ".b")]) @@ -2832,6 +2836,52 @@ (define_peephole2 ; andqu operands[3] = gen_rtx_ZERO_EXTEND (SImode, op1); operands[4] = GEN_INT (trunc_int_for_mode (INTVAL (operands[1]), QImode)); }) + +;; Fix a decomposed szext: fuse it with the memory operand of the +;; load. This is typically the sign-extension part of a decomposed +;; "indirect offset" address. +(define_peephole2 ; lra_szext_decomposed + [(parallel + [(set (match_operand:BW 0 "register_operand") + (match_operand:BW 1 "memory_operand")) + (clobber (reg:CC CRIS_CC0_REGNUM))]) + (parallel + [(set (match_operand:SI 2 "register_operand") (szext:SI (match_dup 0))) + (clobber (reg:CC CRIS_CC0_REGNUM))])] + "REGNO (operands[0]) == REGNO (operands[2]) + || peep2_reg_dead_p (2, operands[0])" + [(parallel + [(set (match_dup 2) (szext:SI (match_dup 1))) + (clobber (reg:CC CRIS_CC0_REGNUM))])]) + +;; Re-compose a decomposed "indirect offset" address for a szext +;; operation. The non-clobbering "addi" is generated by LRA. +;; This and lra_szext_decomposed is covered by cris/rld-legit1.c. +(define_peephole2 ; lra_szext_decomposed_indirect_with_offset + [(parallel + [(set (match_operand:SI 0 "register_operand") + (sign_extend:SI (mem:BW (match_operand:SI 1 "register_operand")))) + (clobber (reg:CC CRIS_CC0_REGNUM))]) + (set (match_dup 0) + (plus:SI (match_dup 0) (match_operand:SI 2 "register_operand"))) + (parallel + [(set (match_operand:SI 3 "register_operand") + (szext:SI (mem:BW2 (match_dup 0)))) + (clobber (reg:CC CRIS_CC0_REGNUM))])] + "(REGNO (operands[0]) == REGNO (operands[3]) + || peep2_reg_dead_p (3, operands[0])) + && (REGNO (operands[0]) == REGNO (operands[1]) + || peep2_reg_dead_p (3, operands[0]))" + [(parallel + [(set + (match_dup 3) + (szext:SI + (mem:BW2 (plus:SI (szext:SI (mem:BW (match_dup 1))) (match_dup 2))))) + (clobber (reg:CC CRIS_CC0_REGNUM))])]) + +;; Add operations with similar or same decomposed addresses here, when +;; encountered - but only when covered by mentioned test-cases for at +;; least one of the cases generalized in the pattern. ;; Local variables: ;; mode:emacs-lisp