From patchwork Fri Mar 24 21:59:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 74750 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp44477vqo; Fri, 24 Mar 2023 15:00:35 -0700 (PDT) X-Google-Smtp-Source: AKy350bKh/oe+QSqlZeFIg0z+iPlzGV7LhzbwgbOdskYWeSYuUIyGB7L3zOrcHXsAiWbzGvpGvE1 X-Received: by 2002:a17:907:3e21:b0:930:f953:9614 with SMTP id hp33-20020a1709073e2100b00930f9539614mr5867890ejc.1.1679695235183; Fri, 24 Mar 2023 15:00:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679695235; cv=none; d=google.com; s=arc-20160816; b=S7x7aGfbtAIvC+RljL1KBWOpNr3JIvSGXNvLlIoIJ9o/iAvYoUg1lIaQnKY3ppmnU2 vNyAXGnp9twESAV9lZuPJzG7SGskTc/xmls70hz48d9kK7NrI4ab4BiABl1JqOPh70uK T7PLHtDbVF/xw5HEsry96ZKWQf0DjwyjY0c3/NB7W5iR1kJlqF58z7humzwaV2BH95u3 gMNHw1iPoH1nko0Cvmc7ltGILy+FG1TnfFoRZe4chkoWGEbMEcxQYANb5xqPDemDXT8O gaaYO5nNy8P+cEG456fbg+u2DakCDcDjsdDSbZOy8TjMFW5vNS6qCkljIHMU0K0hvpp9 qBPg== 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-disposition:mime-version:message-id:subject:cc:to:date :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=+QeIR2Iy6BRljYcSUmrz2C4u44Quu5YriukHK9Mv70M=; b=ZQJHWtmmSLInZzYVaIAFrLCtUVJbUZrkq7ruHCuRUrf0LIshXZEEkEAPY+Ow/nlY3o 57lQqx7UQnMPr091ExG1CgWxoxKYOOXpM4rfx/f8/SKpMDfi3wKM4oSTfflFw4X8KN3j UoHqLKPaaQd4RfyptMGgk3BdycAzcDPepkPl4kVYxHTiZZMFeTf50Pm1Zy8+dQSOYEW3 0NtZVynSqi0Ui8XQbNx/2xLulle4jbaHPL0WsnBpyIWMt8zpx7EHJQ9eHX19U5uaFzj+ O7MEk/IMkB+AyQdgiPIzvbiwOt5tlC9l5TbLIl1iiXxqxkvuVkTinEOjBJ9+ijDkmZPg yCsg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=OTVM2lbE; 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 x20-20020a1709065ad400b008b223aa7a2dsi19103886ejs.734.2023.03.24.15.00.34 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Mar 2023 15:00:35 -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=OTVM2lbE; 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 C2B7B3858C00 for ; Fri, 24 Mar 2023 22:00:33 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C2B7B3858C00 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1679695233; bh=+QeIR2Iy6BRljYcSUmrz2C4u44Quu5YriukHK9Mv70M=; h=Date:To:Cc:Subject:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=OTVM2lbETw0otx8UUxojHwL8g/rlT0Uy073H2EwOzikYhQJDCFi6lVBlA7nVn1vrA NJZmve7mH3WgV8LwgfcGYeCYHHemUDqDqU50lxzJrD5K5YRX6cKHT4q3h2GD8u1Rpn CXMe/a5bzjdUZ4YlKYyFqTcmzvw01ejEkB34F5pc= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 0A1D13851ABD for ; Fri, 24 Mar 2023 21:59:48 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0A1D13851ABD Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-496-Nlh2AxGFMTa_TbVQSH7a9A-1; Fri, 24 Mar 2023 17:59:46 -0400 X-MC-Unique: Nlh2AxGFMTa_TbVQSH7a9A-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id E11C71C0951B; Fri, 24 Mar 2023 21:59:45 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.192.16]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 998A4140EBF4; Fri, 24 Mar 2023 21:59:45 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.17.1/8.17.1) with ESMTPS id 32OLxgwC1095645 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Fri, 24 Mar 2023 22:59:43 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 32OLxfNF1095644; Fri, 24 Mar 2023 22:59:41 +0100 Date: Fri, 24 Mar 2023 22:59:36 +0100 To: Richard Sandiford , Richard Earnshaw Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] aarch64, builtins: Include PR registers in FUNCTION_ARG_REGNO_P etc. [PR109254] Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.7 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-3.7 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, 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.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Jakub Jelinek via Gcc-patches From: Jakub Jelinek Reply-To: Jakub Jelinek 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?1761288111056619867?= X-GMAIL-MSGID: =?utf-8?q?1761288111056619867?= Hi! The testcase in the PR (which unfortunately because of my lack of experience with SVE I'm not able to turn into a runtime testcase that verifies it) is miscompiled on aarch64-linux in the regname pass, because while the function takes arguments in the p0 register, FUNCTION_ARG_REGNO_P doesn't reflect that, so DF doesn't know the register is used in register passing. It sees 2 chains with p1 register and wants to replace the second one and as DF doesn't know p0 is live at the start of the function, it will happily use p0 register even when it is used in subsequent instructions. The following patch fixes that. FUNCTION_ARG_REGNO_P returns non-zero for p0-p3 (unconditionally, seems for the floating/vector registers it doesn't conditionalize them on TARGET_FLOAT either, but if you want, I can conditionalize p0-p3 on TARGET_SVE), similarly targetm.calls.function_value_regno_p returns true for p0 register if TARGET_SVE (again for consistency, that function conditionalizes the float/vector on TARGET_FLOAT); looking at the AAPCS, seems p1-p3 could be also used to return values in case of homogenous aggregates, but it doesn't seem GCC supports putting svbool_t as a member of a structure. Now, that change broke bootstrap in libobjc and some __builtin_apply_args/__builtin_apply/__builtin_return tests. The aarch64_get_reg_raw_mode hook already documents that SVE scalable arg/return passing is fundamentally incompatible with those builtins, but unlike the floating/vector regs where it forces a fixed vector mode, I think there is no fixed mode which could be used for p0-p3. So, I have tweaked the generic code so that it uses VOIDmode return from that hook to signal that a register shouldn't be touched by __builtin_apply_args/__builtin_apply/__builtin_return despite being mentioned in FUNCTION_ARG_REGNO_P or targetm.calls.function_value_regno_p. Bootstrapped/regtested on aarch64-linux, ok for trunk? Could somebody please turn the testcase from the PR into something that can be included into the testsuite? 2023-03-24 Jakub Jelinek PR target/109254 * builtins.cc (apply_args_size): If targetm.calls.get_raw_arg_mode returns VOIDmode, handle it like if the register isn't used for passing arguments at all. (apply_result_size): If targetm.calls.get_raw_result_mode returns VOIDmode, handle it like if the register isn't used for returning results at all. * target.def (get_raw_result_mode, get_raw_arg_mode): Document what it means to return VOIDmode. * doc/tm.texi: Regenerated. * config/aarch64/aarch64.cc (aarch64_function_value_regno_p): Return TARGET_SVE for P0_REGNUM. (aarch64_function_arg_regno_p): Also return true for p0-p3. (aarch64_get_reg_raw_mode): Return VOIDmode for PR_REGNUM_P regs. Jakub --- gcc/builtins.cc.jj 2023-03-24 10:38:40.185097837 +0100 +++ gcc/builtins.cc 2023-03-24 11:06:49.781725290 +0100 @@ -1446,18 +1446,19 @@ apply_args_size (void) { fixed_size_mode mode = targetm.calls.get_raw_arg_mode (regno); - gcc_assert (mode != VOIDmode); - - align = GET_MODE_ALIGNMENT (mode) / BITS_PER_UNIT; - if (size % align != 0) - size = CEIL (size, align) * align; - size += GET_MODE_SIZE (mode); - apply_args_mode[regno] = mode; + if (mode != VOIDmode) + { + align = GET_MODE_ALIGNMENT (mode) / BITS_PER_UNIT; + if (size % align != 0) + size = CEIL (size, align) * align; + size += GET_MODE_SIZE (mode); + apply_args_mode[regno] = mode; + } + else + apply_args_mode[regno] = as_a (VOIDmode); } else - { - apply_args_mode[regno] = as_a (VOIDmode); - } + apply_args_mode[regno] = as_a (VOIDmode); } return size; } @@ -1481,13 +1482,16 @@ apply_result_size (void) { fixed_size_mode mode = targetm.calls.get_raw_result_mode (regno); - gcc_assert (mode != VOIDmode); - - align = GET_MODE_ALIGNMENT (mode) / BITS_PER_UNIT; - if (size % align != 0) - size = CEIL (size, align) * align; - size += GET_MODE_SIZE (mode); - apply_result_mode[regno] = mode; + if (mode != VOIDmode) + { + align = GET_MODE_ALIGNMENT (mode) / BITS_PER_UNIT; + if (size % align != 0) + size = CEIL (size, align) * align; + size += GET_MODE_SIZE (mode); + apply_result_mode[regno] = mode; + } + else + apply_result_mode[regno] = as_a (VOIDmode); } else apply_result_mode[regno] = as_a (VOIDmode); --- gcc/target.def.jj 2023-03-23 10:00:58.722094571 +0100 +++ gcc/target.def 2023-03-24 11:12:46.978585647 +0100 @@ -5324,7 +5324,8 @@ DEFHOOK (get_raw_result_mode, "This target hook returns the mode to be used when accessing raw return\n\ registers in @code{__builtin_return}. Define this macro if the value\n\ -in @var{reg_raw_mode} is not correct.", +in @var{reg_raw_mode} is not correct. Use @code{VOIDmode} if a register\n\ +should be ignored for @code{__builtin_return} purposes.", fixed_size_mode, (int regno), default_get_reg_raw_mode) @@ -5334,7 +5335,8 @@ DEFHOOK (get_raw_arg_mode, "This target hook returns the mode to be used when accessing raw argument\n\ registers in @code{__builtin_apply_args}. Define this macro if the value\n\ -in @var{reg_raw_mode} is not correct.", +in @var{reg_raw_mode} is not correct. Use @code{VOIDmode} if a register\n\ +should be ignored for @code{__builtin_apply_args} purposes.", fixed_size_mode, (int regno), default_get_reg_raw_mode) --- gcc/doc/tm.texi.jj 2023-03-23 10:00:58.631095885 +0100 +++ gcc/doc/tm.texi 2023-03-24 11:12:52.062512496 +0100 @@ -4820,13 +4820,15 @@ nothing when you use @option{-freg-struc @deftypefn {Target Hook} fixed_size_mode TARGET_GET_RAW_RESULT_MODE (int @var{regno}) This target hook returns the mode to be used when accessing raw return registers in @code{__builtin_return}. Define this macro if the value -in @var{reg_raw_mode} is not correct. +in @var{reg_raw_mode} is not correct. Use @code{VOIDmode} if a register +should be ignored for @code{__builtin_return} purposes. @end deftypefn @deftypefn {Target Hook} fixed_size_mode TARGET_GET_RAW_ARG_MODE (int @var{regno}) This target hook returns the mode to be used when accessing raw argument registers in @code{__builtin_apply_args}. Define this macro if the value -in @var{reg_raw_mode} is not correct. +in @var{reg_raw_mode} is not correct. Use @code{VOIDmode} if a register +should be ignored for @code{__builtin_apply_args} purposes. @end deftypefn @deftypefn {Target Hook} bool TARGET_EMPTY_RECORD_P (const_tree @var{type}) --- gcc/config/aarch64/aarch64.cc.jj 2023-03-23 19:50:46.766715343 +0100 +++ gcc/config/aarch64/aarch64.cc 2023-03-24 11:10:29.166568603 +0100 @@ -7388,6 +7388,9 @@ aarch64_function_value_regno_p (const un if (regno >= V0_REGNUM && regno < V0_REGNUM + HA_MAX_NUM_FLDS) return TARGET_FLOAT; + if (regno == P0_REGNUM) + return TARGET_SVE; + return false; } @@ -7959,7 +7962,8 @@ bool aarch64_function_arg_regno_p (unsigned regno) { return ((GP_REGNUM_P (regno) && regno < R0_REGNUM + NUM_ARG_REGS) - || (FP_REGNUM_P (regno) && regno < V0_REGNUM + NUM_FP_ARG_REGS)); + || (FP_REGNUM_P (regno) && regno < V0_REGNUM + NUM_FP_ARG_REGS) + || (PR_REGNUM_P (regno) && regno < P0_REGNUM + NUM_PR_ARG_REGS)); } /* Implement FUNCTION_ARG_BOUNDARY. Every parameter gets at least @@ -7995,6 +7999,10 @@ aarch64_get_reg_raw_mode (int regno) for SVE types are fundamentally incompatible with the __builtin_return/__builtin_apply interface. */ return as_a (V16QImode); + if (PR_REGNUM_P (regno)) + /* For SVE PR regs, indicate that they should be ignored for + __builtin_apply/__builtin_return. */ + return as_a (VOIDmode); return default_get_reg_raw_mode (regno); }