From patchwork Thu Jul 11 11:06:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Georg-Johann Lay X-Patchwork-Id: 1959222 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gjlay.de header.i=@gjlay.de header.a=rsa-sha256 header.s=strato-dkim-0002 header.b=JTww2yr8; dkim=pass header.d=gjlay.de header.i=@gjlay.de header.a=ed25519-sha256 header.s=strato-dkim-0003 header.b=hguSW2Bj; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.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 ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4WKX4Z1tDlz1xpd for ; Thu, 11 Jul 2024 21:07:24 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E4B82384A073 for ; Thu, 11 Jul 2024 11:07:22 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mo4-p00-ob.smtp.rzone.de (mo4-p00-ob.smtp.rzone.de [81.169.146.162]) by sourceware.org (Postfix) with ESMTPS id BE8BF384AB7A for ; Thu, 11 Jul 2024 11:07:01 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org BE8BF384AB7A Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gjlay.de Authentication-Results: sourceware.org; spf=none smtp.mailfrom=gjlay.de ARC-Filter: OpenARC Filter v1.0.0 sourceware.org BE8BF384AB7A Authentication-Results: server2.sourceware.org; arc=pass smtp.remote-ip=81.169.146.162 ARC-Seal: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1720696024; cv=pass; b=Qs/eDSoWuLgFCTsMZy6T67nEO9gmkK1am+8ek12sP7HusQUhIOOfeyvxEgWEYM3XR8f9mbzmvU5wVZMEJzSLdK4EP2kC3cTyMygEJBEldJno4s7n6ELWPCDnHcRGCZaP8kupLNa9IEjpqk8dXQ1B9BPhpku51vM9FTcVU5smpfM= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1720696024; c=relaxed/simple; bh=SqmFEHQcnkkJL/BcqWme/a0NTZX+Uxbgq9knUsDN3xw=; h=DKIM-Signature:DKIM-Signature:Message-ID:Date:MIME-Version:From: To:Subject; b=FmAY2UTcLQgzEMNBAcgrzzLWPfCdWFfNgTrsH8oNgsdrI+lGvFOzd1H4FPRnir2snnsIEb5V9NlvDnhkVjSj7jjmuaHU8jHSLe/58rqYv6EM4rm5RWvfAfOFtdQvojLTU7xAVis9m93hzYcbw7CI9+xNQ4NqmkfaH6Sd1XeD2Cw= ARC-Authentication-Results: i=2; server2.sourceware.org ARC-Seal: i=1; a=rsa-sha256; t=1720696020; cv=none; d=strato.com; s=strato-dkim-0002; b=N0dot71hatRoDZe8Q2tmMxZWjYOQjrVFeD0eW8I0DxmCmRP+yuuwLV+8vyUsUDgu76 Y5co7t528T45FsHUuZh2O3TnbT9Ya5UDIUyqXyd3hojcI0zv+FtrrmlbmySBzO5YopE9 yiJESMaZz807uM53Cqo+sFaePpDf5bbrUzBqL5tH96Leu48A3U3uhN2FgkfY8BRa3wP9 E0jQ6Yv8z8gXAVoNDvtfhKAqLYAC3psyKZSiM4lnrCuKOXEJ5odUUKhffU4dt1lrtXhX cEMtYevtMV7TQQPfgBsC3gAT6KRYWdq6l5VfwdtNWGQZulfKaQGvUNz+Pe96W5gsjbS4 HCpg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; t=1720696020; s=strato-dkim-0002; d=strato.com; h=Subject:To:From:Date:Message-ID:Cc:Date:From:Subject:Sender; bh=k/e7rIXGLNvZHwQ/LyakmZM+2NTHn7agM/A1tmY7TSk=; b=JVSD47OGhHmnVAT/h3QhbJXz8qdz8MWOrDqkOtpIOOhGvN6PUEE7HQEfcrhbrAsz0r tlQiqAjUjHeZyGb7iDyfK+fUBHJbegecg8XV+zCJsgZUrb6Bg68vZ4Zlle8aAuVQkC4/ l8lqlAjUJIyTlDjQ4F9SO5WFVvPJuKT09d/OAg+gpPR80jhG312k3n2MUluC7xcPDGKY W5vh1MF6ntPL6HaPx/vE4Fb0GhTINCoKxR05vfhrqTd486FhBpnOjJ7QOFNCho/etwmg dmE5EEotVlQ06wfZfFyc81ZTTk/8C2UWF4DQVIP4sfwWsCT+o5Up+l9KTgQ4G3CabE/m Cz9A== ARC-Authentication-Results: i=1; strato.com; arc=none; dkim=none X-RZG-CLASS-ID: mo00 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1720696020; s=strato-dkim-0002; d=gjlay.de; h=Subject:To:From:Date:Message-ID:Cc:Date:From:Subject:Sender; bh=k/e7rIXGLNvZHwQ/LyakmZM+2NTHn7agM/A1tmY7TSk=; b=JTww2yr8wU7PogUMCeghG1iC3Lv50eD4z4g+KZYy4oFR/IdGANNfSssWZHbuN6EILF V6FZvxYX/TGE4EWblnq8aTJHxXwuZZ2k5RMk7Kt5OtRQNSNq77p0g20xoBkLfwknt/qB 6n5eEkHfb5ZphDkcOoBb2T1/CVMABA0eeS/yqslqIKr49NhzQUBAcSXxCh0dtgXKcZ+Y omRC6Nz+nMoqEOUMBtvjao4swtkAlGYJn4FqQ9IiZ16eZ6ykNtjKp9J4QfxZyzObW4Ar mZBT+VaB68008J+NRiIw4kR2ef3gFyO0TE0rt4HIjOvoiJPGMfsgnpuTylUwFobqSiRF fsHw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; t=1720696020; s=strato-dkim-0003; d=gjlay.de; h=Subject:To:From:Date:Message-ID:Cc:Date:From:Subject:Sender; bh=k/e7rIXGLNvZHwQ/LyakmZM+2NTHn7agM/A1tmY7TSk=; b=hguSW2BjjFAsrXk9Nfk0wHeqTCM63Yc9+qu26TCvurFC8Hkhir5xiSzRgX+2mE8dyE XS57Q1Wnt6q1M8x6wYAQ== X-RZG-AUTH: ":LXoWVUeid/7A29J/hMvvT3koxZnKT7Qq0xotTetVnKkbjtK7q2y9LkX3jYYP" Received: from [192.168.2.102] by smtp.strato.de (RZmta 50.5.0 DYNA|AUTH) with ESMTPSA id x0577806BB702g1 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256 bits)) (Client did not present a certificate) for ; Thu, 11 Jul 2024 13:07:00 +0200 (CEST) Message-ID: <8081850b-ee2b-4837-9ebd-6cd7b3116810@gjlay.de> Date: Thu, 11 Jul 2024 13:06:57 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird From: Georg-Johann Lay Content-Language: en-US To: "gcc-patches@gcc.gnu.org" Subject: [patch,avr,applied] Tidy up subtract + zero_extend insns X-Spam-Status: No, score=-11.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_PASS, SPF_NONE, 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.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org There are currently five insns and five splits that handle subtraction where the subtrahend is zero-extended to the mode of the minuend. This patch represents them as one insn (and one split) using mode iterators. Applied as obvious. Johann --- AVR: Tidy up subtract-and-zero_extend insns. There are these insns that subtract and zero-extend where the subtrahend is zero-extended to the mode of the minuend. This patch uses one insn (and split) with mode iterators instead of spelling out each variant individually. This has the additional benefit that u32 - u24 is also supported, which previously wasn't. gcc/ * config/avr/avr-protos.h (avr_out_minus): New prototype. * config/avr/avr.cc (avr_out_minus): New function. * config/avr/avr.md (*sub3.zero_extend.) (*sub3.zero_extend._split): New insns. (*subpsi3_zero_extend.qi_split): Remove isns_and_split. (*subpsi3_zero_extend.hi_split): Remove insn_and_split. (*subhi3_zero_extend1_split): Remove insn_and_split. (*subsi3_zero_extend_split): Remove insn_and_split. (*subsi3_zero_extend.hi_split): Remove insn_and_split. (*subpsi3_zero_extend.qi): Remove insn. (*subpsi3_zero_extend.hi): Remove insn. (*subhi3_zero_extend1): Remove insn. (*subsi3_zero_extend): Remove insn. (*subsi3_zero_extend.hi): Remove insn. gcc/testsuite/ * gcc.target/avr/torture/sub-zerox.c: New test. diff --git a/gcc/config/avr/avr-protos.h b/gcc/config/avr/avr-protos.h index dc23cfbf461..6e02161759c 100644 --- a/gcc/config/avr/avr-protos.h +++ b/gcc/config/avr/avr-protos.h @@ -95,6 +95,7 @@ extern void avr_output_addr_vec (rtx_insn*, rtx); extern const char *avr_out_sbxx_branch (rtx_insn *insn, rtx operands[]); extern const char* avr_out_bitop (rtx, rtx*, int*); extern const char* avr_out_plus (rtx, rtx*, int* =NULL, bool =true); +extern const char* avr_out_minus (rtx*); extern const char* avr_out_round (rtx_insn *, rtx*, int* =NULL); extern const char* avr_out_addto_sp (rtx*, int*); extern const char* avr_out_xload (rtx_insn *, rtx*, int*); diff --git a/gcc/config/avr/avr.cc b/gcc/config/avr/avr.cc index d299fceb782..4a7cbd0e7bc 100644 --- a/gcc/config/avr/avr.cc +++ b/gcc/config/avr/avr.cc @@ -8843,6 +8843,36 @@ lshrsi3_out (rtx_insn *insn, rtx operands[], int *len) } +/* Output subtraction of integer registers XOP[0] and XOP[2] and return "" + + XOP[0] = XOP[0] - XOP[2] + + where the mode of XOP[0] is in { HI, PSI, SI }, and the mode of + XOP[2] is in { QI, HI, PSI }. When the mode of XOP[0] is larger + than the mode of XOP[2], then the latter is zero-extended on the fly. + The number of instructions will be the mode size of XOP[0]. */ + +const char * +avr_out_minus (rtx *xop) +{ + int n_bytes0 = GET_MODE_SIZE (GET_MODE (xop[0])); + int n_bytes2 = GET_MODE_SIZE (GET_MODE (xop[2])); + + output_asm_insn ("sub %0,%2", xop); + + for (int i = 1; i < n_bytes0; ++i) + { + rtx op[2]; + op[0] = all_regs_rtx[i + REGNO (xop[0])]; + op[1] = (i < n_bytes2) ? all_regs_rtx[i + REGNO (xop[2])] : zero_reg_rtx; + + output_asm_insn ("sbc %0,%1", op); + } + + return ""; +} + + /* Output addition of register XOP[0] and compile time constant XOP[2]. INSN is a single_set insn or an insn pattern. CODE == PLUS: perform addition by using ADD instructions or @@ -12717,7 +12747,7 @@ avr_rtx_costs_1 (rtx x, machine_mode mode, int outer_code, *total = COSTS_N_INSNS (2); return true; } - // *sub3_zero_extend1 + // *sub3.zero_extend. if (REG_P (XEXP (x, 0)) && GET_CODE (XEXP (x, 1)) == ZERO_EXTEND) { diff --git a/gcc/config/avr/avr.md b/gcc/config/avr/avr.md index 2783b8c986f..8c3e55a91ee 100644 --- a/gcc/config/avr/avr.md +++ b/gcc/config/avr/avr.md @@ -2030,47 +2030,6 @@ (define_insn "*subpsi3" "sub %0,%2\;sbc %B0,%B2\;sbc %C0,%C2" [(set_attr "length" "3")]) -(define_insn_and_split "*subpsi3_zero_extend.qi_split" - [(set (match_operand:PSI 0 "register_operand" "=r") - (minus:PSI (match_operand:SI 1 "register_operand" "0") - (zero_extend:PSI (match_operand:QI 2 "register_operand" "r"))))] - "" - "#" - "&& reload_completed" - [(parallel [(set (match_dup 0) - (minus:PSI (match_dup 1) - (zero_extend:PSI (match_dup 2)))) - (clobber (reg:CC REG_CC))])]) - -(define_insn "*subpsi3_zero_extend.qi" - [(set (match_operand:PSI 0 "register_operand" "=r") - (minus:PSI (match_operand:SI 1 "register_operand" "0") - (zero_extend:PSI (match_operand:QI 2 "register_operand" "r")))) - (clobber (reg:CC REG_CC))] - "reload_completed" - "sub %A0,%2\;sbc %B0,__zero_reg__\;sbc %C0,__zero_reg__" - [(set_attr "length" "3")]) - -(define_insn_and_split "*subpsi3_zero_extend.hi_split" - [(set (match_operand:PSI 0 "register_operand" "=r") - (minus:PSI (match_operand:PSI 1 "register_operand" "0") - (zero_extend:PSI (match_operand:HI 2 "register_operand" "r"))))] - "" - "#" - "&& reload_completed" - [(parallel [(set (match_dup 0) - (minus:PSI (match_dup 1) - (zero_extend:PSI (match_dup 2)))) - (clobber (reg:CC REG_CC))])]) - -(define_insn "*subpsi3_zero_extend.hi" - [(set (match_operand:PSI 0 "register_operand" "=r") - (minus:PSI (match_operand:PSI 1 "register_operand" "0") - (zero_extend:PSI (match_operand:HI 2 "register_operand" "r")))) - (clobber (reg:CC REG_CC))] - "reload_completed" - "sub %A0,%2\;sbc %B0,%B2\;sbc %C0,__zero_reg__" - [(set_attr "length" "3")]) (define_insn_and_split "*subpsi3_sign_extend.hi_split" [(set (match_operand:PSI 0 "register_operand" "=r") @@ -2154,26 +2113,6 @@ (define_insn "*sub3" } [(set_attr "adjust_len" "plus")]) -(define_insn_and_split "*subhi3_zero_extend1_split" - [(set (match_operand:HI 0 "register_operand" "=r") - (minus:HI (match_operand:HI 1 "register_operand" "0") - (zero_extend:HI (match_operand:QI 2 "register_operand" "r"))))] - "" - "#" - "&& reload_completed" - [(parallel [(set (match_dup 0) - (minus:HI (match_dup 1) - (zero_extend:HI (match_dup 2)))) - (clobber (reg:CC REG_CC))])]) - -(define_insn "*subhi3_zero_extend1" - [(set (match_operand:HI 0 "register_operand" "=r") - (minus:HI (match_operand:HI 1 "register_operand" "0") - (zero_extend:HI (match_operand:QI 2 "register_operand" "r")))) - (clobber (reg:CC REG_CC))] - "reload_completed" - "sub %A0,%2\;sbc %B0,__zero_reg__" - [(set_attr "length" "2")]) (define_insn_and_split "*subhi3.sign_extend2_split" [(set (match_operand:HI 0 "register_operand" "=r") @@ -2231,48 +2170,39 @@ (define_insn "*sub3" } [(set_attr "adjust_len" "plus")]) -(define_insn_and_split "*subsi3_zero_extend_split" - [(set (match_operand:SI 0 "register_operand" "=r") - (minus:SI (match_operand:SI 1 "register_operand" "0") - (zero_extend:SI (match_operand:QI 2 "register_operand" "r"))))] - "" - "#" - "&& reload_completed" - [(parallel [(set (match_dup 0) - (minus:SI (match_dup 1) - (zero_extend:SI (match_dup 2)))) - (clobber (reg:CC REG_CC))])]) -(define_insn "*subsi3_zero_extend" - [(set (match_operand:SI 0 "register_operand" "=r") - (minus:SI (match_operand:SI 1 "register_operand" "0") - (zero_extend:SI (match_operand:QI 2 "register_operand" "r")))) - (clobber (reg:CC REG_CC))] - "reload_completed" - "sub %A0,%2\;sbc %B0,__zero_reg__\;sbc %C0,__zero_reg__\;sbc %D0,__zero_reg__" - [(set_attr "length" "4") - ]) - -(define_insn_and_split "*subsi3_zero_extend.hi_split" - [(set (match_operand:SI 0 "register_operand" "=r") - (minus:SI (match_operand:SI 1 "register_operand" "0") - (zero_extend:SI (match_operand:HI 2 "register_operand" "r"))))] - "" +;; "*subhi3.zero_extend.qi_split" +;; "*subpsi3.zero_extend.qi_split" "*subpsi3.zero_extend.hi_split" +;; "*subsi3.zero_extend.qi_split" "*subsi3.zero_extend.hi_split" +;; "*subsi3.zero_extend.psi_split" +(define_insn_and_split "*sub3.zero_extend._split" + [(set (match_operand:HISI 0 "register_operand" "=r") + (minus:HISI (match_operand:HISI 1 "register_operand" "0") + (zero_extend:HISI (match_operand:QIPSI 2 "register_operand" "r"))))] + "GET_MODE_SIZE (mode) > GET_MODE_SIZE (mode)" "#" "&& reload_completed" [(parallel [(set (match_dup 0) - (minus:SI (match_dup 1) - (zero_extend:SI (match_dup 2)))) + (minus:HISI (match_dup 1) + (zero_extend:HISI (match_dup 2)))) (clobber (reg:CC REG_CC))])]) -(define_insn "*subsi3_zero_extend.hi" - [(set (match_operand:SI 0 "register_operand" "=r") - (minus:SI (match_operand:SI 1 "register_operand" "0") - (zero_extend:SI (match_operand:HI 2 "register_operand" "r")))) +;; "*subhi3.zero_extend.qi" +;; "*subpsi3.zero_extend.qi" "*subpsi3.zero_extend.hi" +;; "*subsi3.zero_extend.qi" "*subsi3.zero_extend.hi" +;; "*subsi3.zero_extend.psi" +(define_insn "*sub3.zero_extend." + [(set (match_operand:HISI 0 "register_operand" "=r") + (minus:HISI (match_operand:HISI 1 "register_operand" "0") + (zero_extend:HISI (match_operand:QIPSI 2 "register_operand" "r")))) (clobber (reg:CC REG_CC))] - "reload_completed" - "sub %A0,%2\;sbc %B0,%B2\;sbc %C0,__zero_reg__\;sbc %D0,__zero_reg__" - [(set_attr "length" "4")]) + "reload_completed + && GET_MODE_SIZE (mode) > GET_MODE_SIZE (mode)" + { + return avr_out_minus (operands); + } + [(set_attr "length" "")]) + ;****************************************************************************** ; mul diff --git a/gcc/testsuite/gcc.target/avr/torture/sub-zerox.c b/gcc/testsuite/gcc.target/avr/torture/sub-zerox.c new file mode 100644 index 00000000000..435fc7065f0 --- /dev/null +++ b/gcc/testsuite/gcc.target/avr/torture/sub-zerox.c @@ -0,0 +1,15 @@ +/* { dg-do compile } */ + +typedef __UINT8_TYPE__ u8; +typedef __UINT16_TYPE__ u16; +typedef __uint24 u24; +typedef __UINT32_TYPE__ u32; + +u32 sub_32_8 (u32 a, u8 b) { return a - b; } +u32 sub_32_16 (u32 a, u16 b) { return a - b; } +u32 sub_32_24 (u32 a, u24 b) { return a - b; } + +u24 sub_24_8 (u24 a, u8 b) { return a - b; } +u24 sub_24_16 (u24 a, u16 b) { return a - b; } + +u16 sub_16_8 (u16 a, u8 b) { return a - b; }