From patchwork Tue Jun 25 17:25:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Law X-Patchwork-Id: 1952195 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=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=JodejPNp; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; 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 [IPv6:2620:52:3:1:0:246e:9693:128c]) (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 4W7sF06jbWz20X6 for ; Wed, 26 Jun 2024 03:26:12 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 1E70338708A6 for ; Tue, 25 Jun 2024 17:26:11 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-ot1-x32f.google.com (mail-ot1-x32f.google.com [IPv6:2607:f8b0:4864:20::32f]) by sourceware.org (Postfix) with ESMTPS id 15F36385DDC6 for ; Tue, 25 Jun 2024 17:25:44 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 15F36385DDC6 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 15F36385DDC6 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::32f ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1719336346; cv=none; b=Z9Qh7FdPQPh69ut69z7/0iFjIMI9xyDAZyXGW30DotAzLb5wZn2zdQzDdn1jxFZPMaKow71jeKkgd5XNG5O1q5Q/J9CUKCEMvDGB0ec0Y7AYeMGj1qoghz9zI6vVto9S3cPBRIk0plWnCeBBjLZ6E3jUMBfGCX0MqFSe+VuUo4I= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1719336346; c=relaxed/simple; bh=bpA2IPJnRSaxYYSEQpW3moqza7OowOZi1wSffjB0Hzw=; h=DKIM-Signature:Message-ID:Date:MIME-Version:From:To:Subject; b=a9sIoJcq2BXot/hDRT6SOZ4myE5jBa/g/2uduCBmk5JPdSy6W5KYBVGwtVIS37cDn7vfOt2c749a+C+hbShK0JJAD4Mu478wPjrkybGK7elk90KHEAxuVjCTPouTqd0Pr/vhAZQzzMzFdv8wFGyNm6KGa2/LlaiqsXaB0voz+HY= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-ot1-x32f.google.com with SMTP id 46e09a7af769-700ce6b4b35so66127a34.0 for ; Tue, 25 Jun 2024 10:25:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1719336342; x=1719941142; darn=gcc.gnu.org; h=subject:to:from:content-language:user-agent:mime-version:date :message-id:from:to:cc:subject:date:message-id:reply-to; bh=bqndJ0Ip82LoXBhQoSYofLx5pAwKJVoX2Fs3OZr1jRg=; b=JodejPNpLtz2a2MAv2a+K1ryDqFofr/tHjeI66lCBtWo9Xlwe6fZi3ofWE5sT3szo+ GiZ4AwJy/bnwinDoPgGVswK7u87THfCDIwNTxtuoWRc4yYB8vyXWGnw/Q9m3wqBkdwXV BMzBbmjX2m1AElzXgXPJnCFr0bObnwnw3OkXKeno6+mRTSQZ+SG7i4LDOdw8RQ1QuWaN mLfIkLmlUIHnFZkK9tiH+g0uAmbVFSbtOqHCmT+O9sHYWnkS69Lr9CnhgwTypYz+OwKr 0P3zp0J540QnpdLmtFolyTX3UtcyU7B5RpHdtH0H00R9MXHNhcyPdDFkDQ26MY+OcDF0 xv9g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719336342; x=1719941142; h=subject:to:from:content-language:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=bqndJ0Ip82LoXBhQoSYofLx5pAwKJVoX2Fs3OZr1jRg=; b=TwXrCfdPvLQwo370F831gI31Z516U3NSjzYB4jzh0OXQGQnb88dpGHJd86r9JWY/ds s0DwofxkAcoamGsIUovTq/mZN41/aX4na+YHk+7qWYnkZXJW+zWXDyMsdtWi+oYd7HFT fpbz9gzje9sHsFZzqNfjB4QGYMqj6cLO9LbgOuejB096NNQ0juSQvP17Fne5J4JpU36Q OtLgodTJU0JhdLnH4k/0NIhaK3zlGTYg4OQK/mOknJJc2lRWDtztagrK4qh0OMPI4zeH Q9tbL6aSJE8QLhvl+zBQkYjA4/o3DoTsANicLSyfH3O7LbLGUMsEqn5bwKb0KlhJUVzn O6FQ== X-Gm-Message-State: AOJu0YyVyuqEm0kGhut8sKxQPW5K15ZB1uSczlCFKo9jaSkXtbnJEx1l R0QpjUHAYGPJXaqMmg5NEtI+LUXz3mfNhvFym3cO9yJf92wImSw0+nAaQw== X-Google-Smtp-Source: AGHT+IGkUI3g4FY0Loo9F+FPVQ36oiRPhpB8tsbqxkNMjmGVyEu1dq60s7pgyrVCxlmuR8EcDWEziQ== X-Received: by 2002:a05:6870:e243:b0:25c:ad11:e7f7 with SMTP id 586e51a60fabf-25cf8a19465mr4076784fac.10.1719336342032; Tue, 25 Jun 2024 10:25:42 -0700 (PDT) Received: from [172.31.0.109] ([136.36.72.243]) by smtp.gmail.com with ESMTPSA id 586e51a60fabf-25cd4c040d9sm2538196fac.52.2024.06.25.10.25.41 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 25 Jun 2024 10:25:41 -0700 (PDT) Message-ID: <58adc0c8-2546-469c-afd1-355aa925d0d0@gmail.com> Date: Tue, 25 Jun 2024 11:25:40 -0600 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Beta Content-Language: en-US From: Jeff Law To: "gcc-patches@gcc.gnu.org" Subject: [committed] Fix fr30-elf newlib build failure with late-combine X-Spam-Status: No, score=-8.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, 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.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 So the late combine work has exposed a latent bug in the fr30 port. The fr30 "call" instruction is pc-relative with a *very* limited range, 12 bits to be precise. With such a limited range its hard to see how we could ever consistently use it in the compiler, with the possible exception of self-recursion. Code generation seemed to be using indirect forms pretty consistently, though the RTL would allow direct calls. With late-combine some of those indirects would be optimized into direct calls. This naturally led to out of range scenarios. With the fr30 port slated for removal unless it gets updated to use LRA and the fundamental problems using direct calls, I took the shortest path to keep things working -- namely forcing all calls to be indirect. Tested in my tester with no regressions (and fixes the newlib build failure with late-combine enabled). Pushed to the trunk. Jeff commit 7c28228cda274484b78611ea4c5cbe4ce08f512e Author: Jeff Law Date: Tue Jun 25 11:22:01 2024 -0600 [committed] Fix fr30-elf newlib build failure with late-combine So the late combine work has exposed a latent bug in the fr30 port. The fr30 "call" instruction is pc-relative with a *very* limited range, 12 bits to be precise. With such a limited range its hard to see how we could ever consistently use it in the compiler, with the possible exception of self-recursion. Even for a call to a locally binding function -ffunction-sections and linker placement of functions may separate the caller/callee. Code generation seemed to be using indirect forms pretty consistently, though the RTL would allow direct calls. With late-combine some of those indirects would be optimized into direct calls. This naturally led to out of range scenarios. With the fr30 port slated for removal unless it gets updated to use LRA and the fundamental problems using direct calls, I took the shortest path to keep things working -- namely forcing all calls to be indirect. Tested in my tester with no regressions (and fixes the newlib build failure with late-combine enabled). Pushed to the trunk. gcc/ * config/fr30/constraints.md (Q): Remove unused constraint. * config/fr30/predicates.md (call_operand): Remove unused predicate. * config/fr30/fr30.md (call, vall_value): Turn into expanders and force the call address into a register. (*call, *call_value): Adjust to only allow indirect calls. Adjust output template accordingly. diff --git a/gcc/config/fr30/constraints.md b/gcc/config/fr30/constraints.md index e4e2be1bfd9..1beee7cc3a2 100644 --- a/gcc/config/fr30/constraints.md +++ b/gcc/config/fr30/constraints.md @@ -63,9 +63,3 @@ (define_constraint "P" "An integer in the range -256 to 255." (and (match_code "const_int") (match_test "IN_RANGE (ival, -256, 255)"))) - -;; Extra constraints. -(define_constraint "Q" - "@internal" - (and (match_code "mem") - (match_code "symbol_ref" "0"))) diff --git a/gcc/config/fr30/fr30.md b/gcc/config/fr30/fr30.md index ecde60b455d..04f6d909054 100644 --- a/gcc/config/fr30/fr30.md +++ b/gcc/config/fr30/fr30.md @@ -1079,12 +1079,19 @@ (define_insn "*branch_false" ;; `SImode', except it is normally a `const_int'); operand 2 is the number of ;; registers used as operands. -(define_insn "call" - [(call (match_operand 0 "call_operand" "Qm") +(define_expand "call" + [(parallel [(call (mem:QI (match_operand:SI 0 "register_operand" "r")) + (match_operand 1 "" "g")) + (clobber (reg:SI 17))])] + "" + " { operands[0] = force_reg (SImode, XEXP (operands[0], 0)); } ") + +(define_insn "*call" + [(call (mem:QI (match_operand:SI 0 "register_operand" "r")) (match_operand 1 "" "g")) (clobber (reg:SI 17))] "" - "call%#\\t%0" + "call%#\\t@%0" [(set_attr "delay_type" "delayed")] ) @@ -1094,14 +1101,21 @@ (define_insn "call" ;; increased by one). ;; Subroutines that return `BLKmode' objects use the `call' insn. +(define_expand "call_value" + [(parallel [(set (match_operand 0 "register_operand" "=r") + (call (mem:QI (match_operand:SI 1 "register_operand" "r")) + (match_operand 2 "" "g"))) + (clobber (reg:SI 17))])] + "" + " { operands[1] = force_reg (SImode, XEXP (operands[1], 0)); } ") -(define_insn "call_value" +(define_insn "*call_value" [(set (match_operand 0 "register_operand" "=r") - (call (match_operand 1 "call_operand" "Qm") + (call (mem:QI (match_operand:SI 1 "register_operand" "r")) (match_operand 2 "" "g"))) (clobber (reg:SI 17))] "" - "call%#\\t%1" + "call%#\\t@%1" [(set_attr "delay_type" "delayed")] ) diff --git a/gcc/config/fr30/predicates.md b/gcc/config/fr30/predicates.md index f67c6097430..2f87a4c81b2 100644 --- a/gcc/config/fr30/predicates.md +++ b/gcc/config/fr30/predicates.md @@ -51,16 +51,6 @@ (define_predicate "low_register_operand" && REGNO (op) <= 7); }) -;; Returns true if OP is suitable for use in a CALL insn. - -(define_predicate "call_operand" - (match_code "mem") -{ - return (GET_CODE (op) == MEM - && (GET_CODE (XEXP (op, 0)) == SYMBOL_REF - || GET_CODE (XEXP (op, 0)) == REG)); -}) - ;; Returns TRUE if OP is a valid operand of a DImode operation. (define_predicate "di_operand"