From patchwork Thu Apr 25 10:48:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Botcazou X-Patchwork-Id: 88981 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E9FC138449C7 for ; Thu, 25 Apr 2024 10:48:59 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-lf1-x12e.google.com (mail-lf1-x12e.google.com [IPv6:2a00:1450:4864:20::12e]) by sourceware.org (Postfix) with ESMTPS id 54C5A384641E for ; Thu, 25 Apr 2024 10:48:29 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 54C5A384641E Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=adacore.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 54C5A384641E Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::12e ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714042112; cv=none; b=jjWPBuf4IVOI/81LC2QiH9dpZ923iWj6E+qSUJ7azXdb43DPFERBkGypH1ksGsPX250/+Cpv+1vaACppQmGQCwaWPYXgvClGQw5IfhI4yXKX81XqvwxV8cEoM1Buu5X4DxsYWfZRzWCJXADZIZz9J/qJCD+e6renpRmH5WXWvnE= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714042112; c=relaxed/simple; bh=wSpXT5DKVQNoPB0FKcDPz+3LL2xwiJwoOcJOw81JIFo=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=lxEYvik7nEtVnZLgtdHv6BQJ7c6GDSXzYFPmY5B7r/qiEFrfg0y2Hd/Ttmlpxed49QlP7WbNskPGSezy5Y6TLJIzy/P/i//YyRno9lDSAl3mwLI5l6CVmYFllu4sqyXjdzW1JhfwmzizqxuH7MQLSM+t2EE5HFBPTJHe3nk5tQk= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-lf1-x12e.google.com with SMTP id 2adb3069b0e04-5171a529224so990098e87.0 for ; Thu, 25 Apr 2024 03:48:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1714042108; x=1714646908; darn=gcc.gnu.org; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:from:to:cc:subject:date:message-id:reply-to; bh=0PSNTtWp8hVzS3ebO+/5xRHx+0UBf1/N9MxKsiBToRU=; b=gZZyUWZQmtNb988LP4tyBSS67xU4C8+2ub4R4zWLCvCB8OR6E9Lof3ldj7xTmglWE7 Fx1Op9fqmoEqNpSVxfd/bU0iJakernn0dv/BysjuUt9aVdh2Z4SceKtCgVD21N4Hv1ig OU3c2IJiKpBkxGGgk5UxLCGOdBhS+uWOLIMv8v66bab+XHfmr0/S1vi/AfsWeia4MoNm seQ2endyMkiS5DDYxy/OHsLv4a6QKH1RS68jPZr2lSzklxHBduUpK5DbIi6tBYD5ZKzc qaasIa+OJT+DWUdzxCOEJT9D9o2KktwZtD7mm1WfCiLJH39K1JPWvmgUTiA7YBPbde1U h6mw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714042108; x=1714646908; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=0PSNTtWp8hVzS3ebO+/5xRHx+0UBf1/N9MxKsiBToRU=; b=twEiXGj4QavZFvhE5QbmaYNcSqMpsa+wjz/hY9ZD+/phiNf3sgZsPvbTICKUlk9Tqx FAYyxqbGYaL/qcrShjnHhslyKm0GiM4TzHlyI4VGaUYBKgHYFdBVawsHVRPMIYowKpc8 NfwdcmIyuXWu3b7iilGLixIedS/DNmVEspLmz6cAfwBrLMOpx7Dsu3Q0cLbBOybXf2RV 6aVbVB9P+C3ebI+JqWYCZPEnLn0sa3IRwnbwHieN+IFjZ8VWgDg+eX2cRA4W9nrYNgnZ aVs+eL685XCg8TojtZWHtj/msxo+EXy6YG1hHYq9IPhMLyTAc9S2Fdu6LNHrJkwkrCHv gkxg== X-Gm-Message-State: AOJu0Yy9xWpUMMkqFu29pwsKxitpt1YTFRLRxdPN3i9f6/5ye5E0cAKn fF+7plie2pDJ6O9fDfONCbsDbzL02WHQ4z9NAzol9DoLXcqeJYR1bz6c0hgbQ3A0nm9jBJVk/X4 = X-Google-Smtp-Source: AGHT+IFxnXtdy4XDpgeS62U6xWKnmkkYeWuJmh79SDRtORod9+LLDwnVd8IOV5K0sUF1pUYjvH0GnA== X-Received: by 2002:a05:6512:3da9:b0:51a:f596:9d53 with SMTP id k41-20020a0565123da900b0051af5969d53mr4377186lfv.42.1714042107606; Thu, 25 Apr 2024 03:48:27 -0700 (PDT) Received: from fomalhaut.localnet ([2a01:e0a:8d5:d990:e654:e8ff:fe8f:2ce6]) by smtp.gmail.com with ESMTPSA id n40-20020a05600c502800b0041b4c293f75sm1713784wmr.13.2024.04.25.03.48.26 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Apr 2024 03:48:27 -0700 (PDT) From: Eric Botcazou X-Google-Original-From: Eric Botcazou To: gcc-patches@gcc.gnu.org Subject: [SPARC] Fix PR target/114416 Date: Thu, 25 Apr 2024 12:48:26 +0200 Message-ID: <2933447.e9J7NaK4W3@fomalhaut> MIME-Version: 1.0 X-Spam-Status: No, score=-10.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_NUMSUBJECT, KAM_SHORT, 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+patchwork=sourceware.org@gcc.gnu.org For the 20th anniversary of https://gcc.gnu.org/gcc-3.4/sparc-abi.html, a new calling convention incompatibility with the vendor compiler (and the ABI) has been discovered in 64-bit mode, affecting small structures containing arrays of floating-point components. The decision has been made to fix it on Solaris only at this point. Bootstrapped/regtested on SPARC/Solaris 11.4 and SPARC64/Linux by Rainer (many thanks again) and applied on the mainline. 2024-04-25 Eric Botcazou PR target/114416 * config/sparc/sparc.h (SUN_V9_ABI_COMPATIBILITY): New macro. * config/sparc/sol2.h (SUN_V9_ABI_COMPATIBILITY): Redefine it. * config/sparc/sparc.cc (fp_type_for_abi): New predicate. (traverse_record_type): Use it to spot floating-point types. (compute_fp_layout): Also deal with array types. 2024-04-25 Eric Botcazou * gcc.target/sparc/small-struct-1.c: New test. diff --git a/gcc/config/sparc/sol2.h b/gcc/config/sparc/sol2.h index e849af9038b..552f58b2cc8 100644 --- a/gcc/config/sparc/sol2.h +++ b/gcc/config/sparc/sol2.h @@ -456,3 +456,6 @@ extern const char *host_detect_local_cpu (int argc, const char **argv); #undef SPARC_LOW_FE_EXCEPT_VALUES #define SPARC_LOW_FE_EXCEPT_VALUES 1 + +#undef SUN_V9_ABI_COMPATIBILITY +#define SUN_V9_ABI_COMPATIBILITY 1 diff --git a/gcc/config/sparc/sparc.cc b/gcc/config/sparc/sparc.cc index 30fa4474bbd..8a5f76c8885 100644 --- a/gcc/config/sparc/sparc.cc +++ b/gcc/config/sparc/sparc.cc @@ -6782,6 +6782,22 @@ sparc_pass_by_reference (cumulative_args_t, const function_arg_info &arg) || GET_MODE_SIZE (mode) > 16); } +/* Return true if TYPE is considered as a floating-point type by the ABI. */ + +static bool +fp_type_for_abi (const_tree type) +{ + /* This is the original GCC implementation. */ + if (FLOAT_TYPE_P (type) || VECTOR_TYPE_P (type)) + return true; + + /* This has been introduced in GCC 14 to match the vendor compiler. */ + if (SUN_V9_ABI_COMPATIBILITY && TREE_CODE (type) == ARRAY_TYPE) + return fp_type_for_abi (TREE_TYPE (type)); + + return false; +} + /* Traverse the record TYPE recursively and call FUNC on its fields. NAMED is true if this is for a named parameter. DATA is passed to FUNC for each field. OFFSET is the starting position and @@ -6820,8 +6836,7 @@ traverse_record_type (const_tree type, bool named, T *data, packed); else { - const bool fp_type - = FLOAT_TYPE_P (field_type) || VECTOR_TYPE_P (field_type); + const bool fp_type = fp_type_for_abi (field_type); Func (field, bitpos, fp_type && named && !packed && TARGET_FPU, data); } @@ -7072,6 +7087,13 @@ compute_fp_layout (const_tree field, int bitpos, assign_data_t *data, mode = TYPE_MODE (TREE_TYPE (TREE_TYPE (field))); nregs = 2; } + else if (TREE_CODE (TREE_TYPE (field)) == ARRAY_TYPE) + { + tree elt_type = strip_array_types (TREE_TYPE (field)); + mode = TYPE_MODE (elt_type); + nregs + = int_size_in_bytes (TREE_TYPE (field)) / int_size_in_bytes (elt_type); + } else nregs = 1; diff --git a/gcc/config/sparc/sparc.h b/gcc/config/sparc/sparc.h index fb074808d30..232ecb30ddc 100644 --- a/gcc/config/sparc/sparc.h +++ b/gcc/config/sparc/sparc.h @@ -1700,3 +1700,6 @@ extern int sparc_indent_opcode; #define SPARC_LOW_FE_EXCEPT_VALUES 0 #define TARGET_SUPPORTS_WIDE_INT 1 + +/* Define this to 1 to accept ABI changes to match the vendor compiler. */ +#define SUN_V9_ABI_COMPATIBILITY 0