From patchwork Fri Dec 22 09:23:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wang Pengcheng X-Patchwork-Id: 182596 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:2483:b0:fb:cd0c:d3e with SMTP id q3csp940410dyi; Fri, 22 Dec 2023 01:24:13 -0800 (PST) X-Google-Smtp-Source: AGHT+IHCug0u+dkthPJ6qfE6bn5iC7MPJh5bPUf9FgHE+a9Ffsd/IPirF9mRd6gpNdI/zssOkVv1 X-Received: by 2002:ae9:c004:0:b0:781:d0b:b2c1 with SMTP id u4-20020ae9c004000000b007810d0bb2c1mr1230321qkk.93.1703237053745; Fri, 22 Dec 2023 01:24:13 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1703237053; cv=pass; d=google.com; s=arc-20160816; b=RYmUilJm/egx0VQts6V3aHtmNDqpz1VA9L/ebkhCP6cmEFtJ7fOWvu9g5l0nTKs/PZ uzxNo0NcGLQqBMUl/pxSy8SPywTb8weBhad7BggaBQKZ1dQ1OypDEX9y/DppOZalohXs s8qq4v8p4/UO+DtUMc2LAFCcSWQAYvJ+r6xYeMV2FOg0yTYseDnmkuPyBGwsmid/ZSla IegofyyyF1F/+729jJaiaQ5kYOc38Vyj8aj2OvZTymQrptvhaUAVihUTO0vFTMGUtogA MA6MSSdrA6x+IPaMlLWxsKNkoU7Rn0PwE8Wbu4F627HZxdjDF4lhluUBboOj/ecbm9MF yqIg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:cc:to:subject:message-id:date :mime-version:from:dkim-signature:arc-filter:dmarc-filter :delivered-to; bh=3eElGaIvXaICgdIiugbyxG/nD3r/u4HI8sgNRbX7ZSg=; fh=wrxqSG4a92/gQ8kvkoGDbdZhA0BNqgix7A9XnCOoOJA=; b=Lxp488RrvYqnIqx02MkN2BUGJ59Ys4jxeXqlyl26J9PXUhbAO0KDfGemEJQxpVLnyd YoG7OvGsnirmZnvRD2ZUL45IBVKBHa07OGpgwYuteHDboW8SeolwZf2BK695eB6JOWjm VigF+BqAZKmsSwhL+Ogp5gD8upOqilQkyndm+C0Yn0vjuyCIoZD1Po17477qZI3vG7So i4yIAmVYGHa4O+Mll4Xmy4we1Y9cVHqM9dnba4yedJqH1io5PGvmoaHZXVJNwZ6UGBF9 iZ6eD7bfZ8TAmc1O1d/bKgOC4dl/eTeYnECyIfnc0HSsMXUWCRiYPaycZFCM4UitAUVp ZQKQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@bytedance.com header.s=google header.b=T2qW8k4b; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=bytedance.com Received: from server2.sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id g4-20020a37e204000000b007810a3353dbsi3798672qki.700.2023.12.22.01.24.13 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Dec 2023 01:24:13 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@bytedance.com header.s=google header.b=T2qW8k4b; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=bytedance.com Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 72CAB3858C60 for ; Fri, 22 Dec 2023 09:24:13 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-oa1-x35.google.com (mail-oa1-x35.google.com [IPv6:2001:4860:4864:20::35]) by sourceware.org (Postfix) with ESMTPS id ED7673858D3C for ; Fri, 22 Dec 2023 09:23:14 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org ED7673858D3C Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=bytedance.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org ED7673858D3C Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2001:4860:4864:20::35 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1703236997; cv=none; b=k23Rv4aRSRCll+wxGsQgMLi6DX5sqC2wQc+jpi4S14hpQzYDrHjBV0hQq7MdY8Jp6WTUUH1FpRsfTVNmEA1ykzXQpx/Akw4H0xfjXQxN2KMcF/6CC2zGv5Ei9/AQF/rYZDx7RTqvONToj6dUviNlXHRka20fDVcVAvtR9TDREZQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1703236997; c=relaxed/simple; bh=TeAxCmwLGJLbsO16zm/zSGm3bUe4Lp9x/K0mcYnpxA4=; h=DKIM-Signature:From:Mime-Version:Date:Message-ID:Subject:To; b=gRmnRqvIu/vWEUalc9TU4FhMfx+R8Eu3OpJHiW6lEm88QoK7cYryQkKy1s7WyTBZyokzipyET8x+54v5I2w86syT8sqS7MaMuV3MaZ0QZYk1QU/eUfFIPD9zfoQWtzpID8/9luZ4pmdTtEuU1wMOD97aPdT/QhDWOEYg5TR9V10= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-oa1-x35.google.com with SMTP id 586e51a60fabf-203fe0e3fefso1018109fac.2 for ; Fri, 22 Dec 2023 01:23:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1703236994; x=1703841794; darn=gcc.gnu.org; h=cc:to:subject:message-id:date:mime-version:from:from:to:cc:subject :date:message-id:reply-to; bh=3eElGaIvXaICgdIiugbyxG/nD3r/u4HI8sgNRbX7ZSg=; b=T2qW8k4bDnWgSl2YrPrbQj9TbhOGpe0KNM3Jk1Fda8VtYNZeV7EAnxSJcxTKrJf3dW aQYk70NWyJac3ZK4ongbhCOvuYOC1d+yc1kAVB4kY0dEnU1NQnpBf46rW80LeNSCXcqc 1fjZBa0vILiPY1UjUfcx8iyXolz8gsisgsPQQcB8ejpNTPuac7QVWLvvnqsikMiKiZUg kTpGxE7UNto1hDJEtzdQj3jYbkZxI83jv+1zChGOUHGW60sKeT98ZZNUdJAlKdi9xJe1 bPxBOteykCcvvSmYQ+ijAJt7+HZ1VTp3fdhwN/OEQClmycCIgVDdgu6jg0LbS0y4DzI1 zb9A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1703236994; x=1703841794; h=cc:to:subject:message-id:date:mime-version:from:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=3eElGaIvXaICgdIiugbyxG/nD3r/u4HI8sgNRbX7ZSg=; b=pWTBrSN0Jm7rX5oam1IiYNEkbBsQ90EjErWlcDg2V0F9BcBHdqHhVGarWyKqGSPcE1 63MBIauJOXvzlFDxFCi8sTFEusBHUg+1app4SerO1xW+vTfvWas9Lxw7ZI+GgQRkEUlf nqvTjVgmv2AnwZd6A+eP1teJRVdS7RszDDaaHuT1Gt/pesuOckEWT5bIh4N+N4JUmHit 713hjkFn4kKBXdjqV85uWpAs6cE8T5NV0PF0jUEKXhwKMei7uXee0eFnoGzKW+4uzSAm n0fiBQfi1C2pTFaTDNf5xK8elsJw0B128PEfIGOpUONubbwiqxxn2uyf8B0vJ8mDFXc+ 6+Uw== X-Gm-Message-State: AOJu0YyCvPM06blx1exzL5h24mjgNjv93j3PLB/dJJOl8tE9fWLXUfr9 BABOjK7JqU+xkddMAXJE1zcERf53WCPRRFPG8HCsyknEFTXxM1ehJbXriTEH X-Received: by 2002:a05:6870:3b0e:b0:204:1204:d2c5 with SMTP id gh14-20020a0568703b0e00b002041204d2c5mr1088910oab.102.1703236993789; Fri, 22 Dec 2023 01:23:13 -0800 (PST) Received: from 44278815321 named unknown by gmailapi.google.com with HTTPREST; Fri, 22 Dec 2023 01:23:13 -0800 From: Wang Pengcheng X-Mailer: git-send-email 2.41.0.windows.1 Mime-Version: 1.0 X-Original-From: Wang Pengcheng Date: Fri, 22 Dec 2023 01:23:13 -0800 Message-ID: Subject: [PATCH] RISC-V: Support -m[no-]unaligned-access To: gcc-patches@gcc.gnu.org Cc: Wang Pengcheng X-Spam-Status: No, score=-9.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, HTML_MESSAGE, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE 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+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785973496865358261 X-GMAIL-MSGID: 1785973496865358261 These two options are negative alias of -m[no-]strict-align. This matches LLVM implmentation. gcc/ChangeLog: * config/riscv/riscv.opt: Add option alias. gcc/testsuite/ChangeLog: * gcc.target/riscv/predef-align-10.c: New test. * gcc.target/riscv/predef-align-7.c: New test. * gcc.target/riscv/predef-align-8.c: New test. * gcc.target/riscv/predef-align-9.c: New test. Signed-off-by: Wang Pengcheng --- gcc/config/riscv/riscv.opt | 4 ++++ gcc/testsuite/gcc.target/riscv/predef-align-10.c | 16 ++++++++++++++++ gcc/testsuite/gcc.target/riscv/predef-align-7.c | 15 +++++++++++++++ gcc/testsuite/gcc.target/riscv/predef-align-8.c | 16 ++++++++++++++++ gcc/testsuite/gcc.target/riscv/predef-align-9.c | 15 +++++++++++++++ 5 files changed, 66 insertions(+) create mode 100644 gcc/testsuite/gcc.target/riscv/predef-align-10.c create mode 100644 gcc/testsuite/gcc.target/riscv/predef-align-7.c create mode 100644 gcc/testsuite/gcc.target/riscv/predef-align-8.c create mode 100644 gcc/testsuite/gcc.target/riscv/predef-align-9.c +} diff --git a/gcc/config/riscv/riscv.opt b/gcc/config/riscv/riscv.opt index cf207d4dcdf..1e22998ce6e 100644 --- a/gcc/config/riscv/riscv.opt +++ b/gcc/config/riscv/riscv.opt @@ -116,6 +116,10 @@ mstrict-align Target Mask(STRICT_ALIGN) Save Do not generate unaligned memory accesses. +munaligned-access +Target Alias(mstrict-align) NegativeAlias +Enable unaligned memory accesses. + Enum Name(code_model) Type(enum riscv_code_model) Known code models (for use with the -mcmodel= option): diff --git a/gcc/testsuite/gcc.target/riscv/predef-align-10.c b/gcc/testsuite/gcc.target/riscv/predef-align-10.c new file mode 100644 index 00000000000..c86b2c7a5ed --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/predef-align-10.c @@ -0,0 +1,16 @@ +/* { dg-do compile } */ +/* { dg-options "-mtune=rocket -munaligned-access" } */ + +int main() { + +/* rocket default is cpu tune param misaligned access slow */ +#if !defined(__riscv_misaligned_slow) +#error "__riscv_misaligned_slow is not set" +#endif + +#if defined(__riscv_misaligned_avoid) || defined(__riscv_misaligned_fast) +#error "__riscv_misaligned_avoid or __riscv_misaligned_fast is unexpectedly set" +#endif + + return 0; +} diff --git a/gcc/testsuite/gcc.target/riscv/predef-align-7.c b/gcc/testsuite/gcc.target/riscv/predef-align-7.c new file mode 100644 index 00000000000..405f3686c2e --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/predef-align-7.c @@ -0,0 +1,15 @@ +/* { dg-do compile } */ +/* { dg-options "-mtune=thead-c906 -mno-unaligned-access" } */ + +int main() { + +#if !defined(__riscv_misaligned_avoid) +#error "__riscv_misaligned_avoid is not set" +#endif + +#if defined(__riscv_misaligned_fast) || defined(__riscv_misaligned_slow) +#error "__riscv_misaligned_fast or __riscv_misaligned_slow is unexpectedly set" +#endif + + return 0; +} diff --git a/gcc/testsuite/gcc.target/riscv/predef-align-8.c b/gcc/testsuite/gcc.target/riscv/predef-align-8.c new file mode 100644 index 00000000000..64072c04a47 --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/predef-align-8.c @@ -0,0 +1,16 @@ +/* { dg-do compile } */ +/* { dg-options "-mtune=thead-c906 -munaligned-access" } */ + +int main() { + +/* thead-c906 default is cpu tune param misaligned access fast */ +#if !defined(__riscv_misaligned_fast) +#error "__riscv_misaligned_fast is not set" +#endif + +#if defined(__riscv_misaligned_avoid) || defined(__riscv_misaligned_slow) +#error "__riscv_misaligned_avoid or __riscv_misaligned_slow is unexpectedly set" +#endif + + return 0; +} diff --git a/gcc/testsuite/gcc.target/riscv/predef-align-9.c b/gcc/testsuite/gcc.target/riscv/predef-align-9.c new file mode 100644 index 00000000000..f5418de87cf --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/predef-align-9.c @@ -0,0 +1,15 @@ +/* { dg-do compile } */ +/* { dg-options "-mtune=rocket -mno-unaligned-access" } */ + +int main() { + +#if !defined(__riscv_misaligned_avoid) +#error "__riscv_misaligned_avoid is not set" +#endif + +#if defined(__riscv_misaligned_fast) || defined(__riscv_misaligned_slow) +#error "__riscv_misaligned_fast or __riscv_misaligned_slow is unexpectedly set" +#endif + + return 0;