From patchwork Fri Aug 18 07:49:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Manos Anagnostakis X-Patchwork-Id: 135989 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b82d:0:b0:3f2:4152:657d with SMTP id z13csp1226857vqi; Fri, 18 Aug 2023 00:50:51 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGk+88nmrZPaBBla4nvENsuuM0yHwy5zUxoz+UJHoCLG/NL9OTIEWh+dIOpZLN81i21cPmI X-Received: by 2002:a17:906:cd1:b0:99b:5abb:8caf with SMTP id l17-20020a1709060cd100b0099b5abb8cafmr1336427ejh.44.1692345051202; Fri, 18 Aug 2023 00:50:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1692345051; cv=none; d=google.com; s=arc-20160816; b=GNuXaIQX2yZREXNsNIYlrZ5uq0znyvoBECQbuKPRaaqlY+sUfHwe1WbHoNJ18nJUAI 65B5TfVQU8PEuwWqA+d3jpVOtMBi1uz9Fy8WWliBuLO98Dxq71bHifH+WaqgbxsSJztB SQQn7k180LkTmf0hlr9RAHUct21xsA8U5HIQKH+mTQO4AgtagkPR29tS6sYf4eE/k0/2 9MfeInvNWT2uShkTjEZm9aZvCBKAg5VmlrMHQm6URY16iKaFxajhuvtGBxbEu791rEab 1BwSHNouh3mlkipVbIh+rpNbuCK1r5uFERovodpW62+F6G5Atf5u2uL2Tfqlz0eqJu+5 efwA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:cc:to:from:dkim-signature :dmarc-filter:delivered-to; bh=/fGT+kl+S8eX0ePqAe/c3YWlYCLSJ/f0PlMJLs+Rhys=; fh=bzSjk3nm7+yiuYnwWB606PycMriQmgMAzPYbvSiSTZY=; b=uGxdyF6bT5QEg56NrBqx9yVwTQ1V+Fw8+mu7yNVUgXVP5IN0GNGzx0uWDZ9g2pCB7Q tsL+CBLnkkgZn1OwwLA/HLBMkn5HpeGh4xDuzdmt0pA3RGwsaFEbin4jY4avlfW/7yQx doxyW+OShh8ur0ZC9tLqzX6V+FEJjQX/+012D7RbupSsqL4CzYmreOCqwwGGuJfTOdIv ON9xlG3si2IxdO6XH8nd2Sw+xgEmNFKdPlOrWKoWm3d4ZQ3AlDyX/yUXoIoWTRpBM7Nw xGz5ZVH2npEoJKUXrz7td+Ye6r1ruyF71ySznylK1DEeoh0kNmofjlaAhL64KhIRPB96 4btg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@vrull.eu header.s=google header.b="l0DGG74/"; 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" Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id z24-20020a170906815800b0099d6d4c11d4si970131ejw.782.2023.08.18.00.50.50 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Aug 2023 00:50:51 -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=@vrull.eu header.s=google header.b="l0DGG74/"; 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" Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 71EAA38515D7 for ; Fri, 18 Aug 2023 07:50:37 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x32f.google.com (mail-wm1-x32f.google.com [IPv6:2a00:1450:4864:20::32f]) by sourceware.org (Postfix) with ESMTPS id 61745385B512 for ; Fri, 18 Aug 2023 07:50:08 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 61745385B512 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=vrull.eu Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=vrull.eu Received: by mail-wm1-x32f.google.com with SMTP id 5b1f17b1804b1-3fe8a1591c7so6074355e9.3 for ; Fri, 18 Aug 2023 00:50:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vrull.eu; s=google; t=1692345007; x=1692949807; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=/fGT+kl+S8eX0ePqAe/c3YWlYCLSJ/f0PlMJLs+Rhys=; b=l0DGG74/xskLH8t1sWhzM3DWOM3BrErWHJ3YNxxKmaDEE8CyvSrI36w1i5V9l/9qv6 4oK5IP195qmkbVPT2lJMc9oehh9Fd5ICiZ3u7XH1JHhe8rdWPb+ftyPGacMpG6dolf0x SR4OpK5eEYhr/hsBf5rbESOb/cBUGDCzjYPTXA2aOaNJlps+vCD2y/WgStIU+qlkT+1N Ssd25r0fxpHXsQVu5BbmsS4Ii5R/02vGeJDQSvqWugbQRCuj02PSDE4RRMykurJp4DJA URnk/gkgSyG75nTnW64FDLNucQYjST+snlJI0O1ADpbcgEOdUjgeXLoTkO35kx/oq+Ss nYlg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692345007; x=1692949807; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=/fGT+kl+S8eX0ePqAe/c3YWlYCLSJ/f0PlMJLs+Rhys=; b=jnb23uWkGIukL3YYBd9c3EjCQkSQnJm4lLgqdrNdVM51IDfdq0QP4yQ0w4PIynWgoG Gye9oPOJFBF7mU8mQcgUlEwU5pQlASlqbZTU8MkS2J+eGAd6b162J8I5onkct9KKJA6h hHl2c4VNmiVspOmpZ2XLJicHbamV5H+PnAdYVyaxXua6O83W0RIMUjax8MsAA/u0+BC6 h8vOb5YsWvO8nZQydx/ibK6DKT3kY+64z5I156iYYL8FD9qRdgIEeR8nNSKzdSiz9fmn NgQuhnBkYEh2ycreC9cOZGXkvGhNrj+mvCJ6NWFtzpwiuC18H82gb7SFbJSmL3SC/nSc 10nw== X-Gm-Message-State: AOJu0YyGUrAyFrSRsQOBQ+mB4RKG0cfDOwVfJpyB5xQVllmsXgAh8b0+ hPhMaKikkScd9hJqerszdD76aen7t+4LEQcDYNY= X-Received: by 2002:a7b:cbd0:0:b0:3f8:fac0:ad40 with SMTP id n16-20020a7bcbd0000000b003f8fac0ad40mr1589108wmi.29.1692345006115; Fri, 18 Aug 2023 00:50:06 -0700 (PDT) Received: from manos-laptop.. ([188.73.238.65]) by smtp.gmail.com with ESMTPSA id y12-20020a5d4acc000000b003143801f8d8sm1847817wrs.103.2023.08.18.00.50.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Aug 2023 00:50:05 -0700 (PDT) From: Manos Anagnostakis To: gcc-patches@gcc.gnu.org Cc: Kyrylo Tkachov , Philipp Tomsich , Manos Anagnostakis Subject: [PATCH] aarch64: Fine-grained ldp and stp policies with test-cases. Date: Fri, 18 Aug 2023 10:49:43 +0300 Message-Id: <20230818074943.41754-1-manos.anagnostakis@vrull.eu> X-Mailer: git-send-email 2.34.1 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, JMQ_SPF_NEUTRAL, KAM_SHORT, RCVD_IN_BARRACUDACENTRAL, 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.29 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 Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1774552404605499740 X-GMAIL-MSGID: 1774552404605499740 This patch implements the following TODO in gcc/config/aarch64/aarch64.cc to provide the requested behaviour for handling ldp and stp: /* Allow the tuning structure to disable LDP instruction formation from combining instructions (e.g., in peephole2). TODO: Implement fine-grained tuning control for LDP and STP: 1. control policies for load and store separately; 2. support the following policies: - default (use what is in the tuning structure) - always - never - aligned (only if the compiler can prove that the load will be aligned to 2 * element_size) */ It provides two new and concrete command-line options -mldp-policy and -mstp-policy to give the ability to control load and store policies seperately as stated in part 1 of the TODO. The accepted values for both options are: - default: Use the ldp/stp policy defined in the corresponding tuning structure. - always: Emit ldp/stp regardless of alignment. - never: Do not emit ldp/stp. - aligned: In order to emit ldp/stp, first check if the load/store will be aligned to 2 * element_size. gcc/ChangeLog: * config/aarch64/aarch64-protos.h (struct tune_params): Add appropriate enums for the policies. * config/aarch64/aarch64-tuning-flags.def (AARCH64_EXTRA_TUNING_OPTION): Remove superseded tuning options. * config/aarch64/aarch64.cc (aarch64_parse_ldp_policy): New function to parse ldp-policy option. (aarch64_parse_stp_policy): New function to parse stp-policy option. (aarch64_override_options_internal): Call parsing functions. (aarch64_operands_ok_for_ldpstp): Add option-value check and alignment check and remove superseded ones (aarch64_operands_adjust_ok_for_ldpstp): Add option-value check and alignment check and remove superseded ones. * config/aarch64/aarch64.opt: Add options. gcc/testsuite/ChangeLog: * gcc.target/aarch64/ldp_aligned.c: New test. * gcc.target/aarch64/ldp_always.c: New test. * gcc.target/aarch64/ldp_never.c: New test. * gcc.target/aarch64/stp_aligned.c: New test. * gcc.target/aarch64/stp_always.c: New test. * gcc.target/aarch64/stp_never.c: New test. Signed-off-by: Manos Anagnostakis --- gcc/config/aarch64/aarch64-protos.h | 24 ++ gcc/config/aarch64/aarch64-tuning-flags.def | 8 - gcc/config/aarch64/aarch64.cc | 229 ++++++++++++++---- gcc/config/aarch64/aarch64.opt | 8 + .../gcc.target/aarch64/ldp_aligned.c | 64 +++++ gcc/testsuite/gcc.target/aarch64/ldp_always.c | 64 +++++ gcc/testsuite/gcc.target/aarch64/ldp_never.c | 64 +++++ .../gcc.target/aarch64/stp_aligned.c | 60 +++++ gcc/testsuite/gcc.target/aarch64/stp_always.c | 60 +++++ gcc/testsuite/gcc.target/aarch64/stp_never.c | 60 +++++ 10 files changed, 580 insertions(+), 61 deletions(-) create mode 100644 gcc/testsuite/gcc.target/aarch64/ldp_aligned.c create mode 100644 gcc/testsuite/gcc.target/aarch64/ldp_always.c create mode 100644 gcc/testsuite/gcc.target/aarch64/ldp_never.c create mode 100644 gcc/testsuite/gcc.target/aarch64/stp_aligned.c create mode 100644 gcc/testsuite/gcc.target/aarch64/stp_always.c create mode 100644 gcc/testsuite/gcc.target/aarch64/stp_never.c diff --git a/gcc/config/aarch64/aarch64-protos.h b/gcc/config/aarch64/aarch64-protos.h index 70303d6fd95..be1d73490ed 100644 --- a/gcc/config/aarch64/aarch64-protos.h +++ b/gcc/config/aarch64/aarch64-protos.h @@ -568,6 +568,30 @@ struct tune_params /* Place prefetch struct pointer at the end to enable type checking errors when tune_params misses elements (e.g., from erroneous merges). */ const struct cpu_prefetch_tune *prefetch; +/* An enum specifying how to handle load pairs using a fine-grained policy: + - LDP_POLICY_ALIGNED: Emit ldp if the source pointer is aligned + to at least double the alignment of the type. + - LDP_POLICY_ALWAYS: Emit ldp regardless of alignment. + - LDP_POLICY_NEVER: Do not emit ldp. */ + + enum aarch64_ldp_policy_model + { + LDP_POLICY_ALIGNED, + LDP_POLICY_ALWAYS, + LDP_POLICY_NEVER + } ldp_policy_model; +/* An enum specifying how to handle store pairs using a fine-grained policy: + - STP_POLICY_ALIGNED: Emit stp if the source pointer is aligned + to at least double the alignment of the type. + - STP_POLICY_ALWAYS: Emit stp regardless of alignment. + - STP_POLICY_NEVER: Do not emit stp. */ + + enum aarch64_stp_policy_model + { + STP_POLICY_ALIGNED, + STP_POLICY_ALWAYS, + STP_POLICY_NEVER + } stp_policy_model; }; /* Classifies an address. diff --git a/gcc/config/aarch64/aarch64-tuning-flags.def b/gcc/config/aarch64/aarch64-tuning-flags.def index 52112ba7c48..774568e9106 100644 --- a/gcc/config/aarch64/aarch64-tuning-flags.def +++ b/gcc/config/aarch64/aarch64-tuning-flags.def @@ -30,11 +30,6 @@ AARCH64_EXTRA_TUNING_OPTION ("rename_fma_regs", RENAME_FMA_REGS) -/* Don't create non-8 byte aligned load/store pair. That is if the -two load/stores are not at least 8 byte aligned don't create load/store -pairs. */ -AARCH64_EXTRA_TUNING_OPTION ("slow_unaligned_ldpw", SLOW_UNALIGNED_LDPW) - /* Some of the optional shift to some arthematic instructions are considered cheap. Logical shift left <=4 with or without a zero extend are considered cheap. Sign extend; non logical shift left @@ -44,9 +39,6 @@ AARCH64_EXTRA_TUNING_OPTION ("cheap_shift_extend", CHEAP_SHIFT_EXTEND) /* Disallow load/store pair instructions on Q-registers. */ AARCH64_EXTRA_TUNING_OPTION ("no_ldp_stp_qregs", NO_LDP_STP_QREGS) -/* Disallow load-pair instructions to be formed in combine/peephole. */ -AARCH64_EXTRA_TUNING_OPTION ("no_ldp_combine", NO_LDP_COMBINE) - AARCH64_EXTRA_TUNING_OPTION ("rename_load_regs", RENAME_LOAD_REGS) AARCH64_EXTRA_TUNING_OPTION ("cse_sve_vl_constants", CSE_SVE_VL_CONSTANTS) diff --git a/gcc/config/aarch64/aarch64.cc b/gcc/config/aarch64/aarch64.cc index 560e5431636..51c94804f12 100644 --- a/gcc/config/aarch64/aarch64.cc +++ b/gcc/config/aarch64/aarch64.cc @@ -1356,7 +1356,9 @@ static const struct tune_params generic_tunings = Neoverse V1. It does not have a noticeable effect on A64FX and should have at most a very minor effect on SVE2 cores. */ (AARCH64_EXTRA_TUNE_CSE_SVE_VL_CONSTANTS), /* tune_flags. */ - &generic_prefetch_tune + &generic_prefetch_tune, + tune_params::LDP_POLICY_ALWAYS, /* ldp_policy_model. */ + tune_params::STP_POLICY_ALWAYS /* stp_policy_model. */ }; static const struct tune_params cortexa35_tunings = @@ -1390,7 +1392,9 @@ static const struct tune_params cortexa35_tunings = 0, /* max_case_values. */ tune_params::AUTOPREFETCHER_WEAK, /* autoprefetcher_model. */ (AARCH64_EXTRA_TUNE_NONE), /* tune_flags. */ - &generic_prefetch_tune + &generic_prefetch_tune, + tune_params::LDP_POLICY_ALWAYS, /* ldp_policy_model. */ + tune_params::STP_POLICY_ALWAYS /* stp_policy_model. */ }; static const struct tune_params cortexa53_tunings = @@ -1424,7 +1428,9 @@ static const struct tune_params cortexa53_tunings = 0, /* max_case_values. */ tune_params::AUTOPREFETCHER_WEAK, /* autoprefetcher_model. */ (AARCH64_EXTRA_TUNE_NONE), /* tune_flags. */ - &generic_prefetch_tune + &generic_prefetch_tune, + tune_params::LDP_POLICY_ALWAYS, /* ldp_policy_model. */ + tune_params::STP_POLICY_ALWAYS /* stp_policy_model. */ }; static const struct tune_params cortexa57_tunings = @@ -1458,7 +1464,9 @@ static const struct tune_params cortexa57_tunings = 0, /* max_case_values. */ tune_params::AUTOPREFETCHER_WEAK, /* autoprefetcher_model. */ (AARCH64_EXTRA_TUNE_RENAME_FMA_REGS), /* tune_flags. */ - &generic_prefetch_tune + &generic_prefetch_tune, + tune_params::LDP_POLICY_ALWAYS, /* ldp_policy_model. */ + tune_params::STP_POLICY_ALWAYS /* stp_policy_model. */ }; static const struct tune_params cortexa72_tunings = @@ -1492,7 +1500,9 @@ static const struct tune_params cortexa72_tunings = 0, /* max_case_values. */ tune_params::AUTOPREFETCHER_WEAK, /* autoprefetcher_model. */ (AARCH64_EXTRA_TUNE_NONE), /* tune_flags. */ - &generic_prefetch_tune + &generic_prefetch_tune, + tune_params::LDP_POLICY_ALWAYS, /* ldp_policy_model. */ + tune_params::STP_POLICY_ALWAYS /* stp_policy_model. */ }; static const struct tune_params cortexa73_tunings = @@ -1526,7 +1536,9 @@ static const struct tune_params cortexa73_tunings = 0, /* max_case_values. */ tune_params::AUTOPREFETCHER_WEAK, /* autoprefetcher_model. */ (AARCH64_EXTRA_TUNE_NONE), /* tune_flags. */ - &generic_prefetch_tune + &generic_prefetch_tune, + tune_params::LDP_POLICY_ALWAYS, /* ldp_policy_model. */ + tune_params::STP_POLICY_ALWAYS /* stp_policy_model. */ }; @@ -1561,7 +1573,9 @@ static const struct tune_params exynosm1_tunings = 48, /* max_case_values. */ tune_params::AUTOPREFETCHER_WEAK, /* autoprefetcher_model. */ (AARCH64_EXTRA_TUNE_NONE), /* tune_flags. */ - &exynosm1_prefetch_tune + &exynosm1_prefetch_tune, + tune_params::LDP_POLICY_ALWAYS, /* ldp_policy_model. */ + tune_params::STP_POLICY_ALWAYS /* stp_policy_model. */ }; static const struct tune_params thunderxt88_tunings = @@ -1593,8 +1607,10 @@ static const struct tune_params thunderxt88_tunings = 2, /* min_div_recip_mul_df. */ 0, /* max_case_values. */ tune_params::AUTOPREFETCHER_OFF, /* autoprefetcher_model. */ - (AARCH64_EXTRA_TUNE_SLOW_UNALIGNED_LDPW), /* tune_flags. */ - &thunderxt88_prefetch_tune + (AARCH64_EXTRA_TUNE_NONE), /* tune_flags. */ + &thunderxt88_prefetch_tune, + tune_params::LDP_POLICY_ALIGNED, /* ldp_policy_model. */ + tune_params::STP_POLICY_ALIGNED /* stp_policy_model. */ }; static const struct tune_params thunderx_tunings = @@ -1626,9 +1642,10 @@ static const struct tune_params thunderx_tunings = 2, /* min_div_recip_mul_df. */ 0, /* max_case_values. */ tune_params::AUTOPREFETCHER_OFF, /* autoprefetcher_model. */ - (AARCH64_EXTRA_TUNE_SLOW_UNALIGNED_LDPW - | AARCH64_EXTRA_TUNE_CHEAP_SHIFT_EXTEND), /* tune_flags. */ - &thunderx_prefetch_tune + (AARCH64_EXTRA_TUNE_CHEAP_SHIFT_EXTEND), /* tune_flags. */ + &thunderx_prefetch_tune, + tune_params::LDP_POLICY_ALIGNED, /* ldp_policy_model. */ + tune_params::STP_POLICY_ALIGNED /* stp_policy_model. */ }; static const struct tune_params tsv110_tunings = @@ -1662,7 +1679,9 @@ static const struct tune_params tsv110_tunings = 0, /* max_case_values. */ tune_params::AUTOPREFETCHER_WEAK, /* autoprefetcher_model. */ (AARCH64_EXTRA_TUNE_NONE), /* tune_flags. */ - &tsv110_prefetch_tune + &tsv110_prefetch_tune, + tune_params::LDP_POLICY_ALWAYS, /* ldp_policy_model. */ + tune_params::STP_POLICY_ALWAYS /* stp_policy_model. */ }; static const struct tune_params xgene1_tunings = @@ -1695,7 +1714,9 @@ static const struct tune_params xgene1_tunings = 17, /* max_case_values. */ tune_params::AUTOPREFETCHER_OFF, /* autoprefetcher_model. */ (AARCH64_EXTRA_TUNE_NO_LDP_STP_QREGS), /* tune_flags. */ - &xgene1_prefetch_tune + &xgene1_prefetch_tune, + tune_params::LDP_POLICY_ALWAYS, /* ldp_policy_model. */ + tune_params::STP_POLICY_ALWAYS /* stp_policy_model. */ }; static const struct tune_params emag_tunings = @@ -1728,7 +1749,9 @@ static const struct tune_params emag_tunings = 17, /* max_case_values. */ tune_params::AUTOPREFETCHER_OFF, /* autoprefetcher_model. */ (AARCH64_EXTRA_TUNE_NO_LDP_STP_QREGS), /* tune_flags. */ - &xgene1_prefetch_tune + &xgene1_prefetch_tune, + tune_params::LDP_POLICY_ALWAYS, /* ldp_policy_model. */ + tune_params::STP_POLICY_ALWAYS /* stp_policy_model. */ }; static const struct tune_params qdf24xx_tunings = @@ -1762,7 +1785,9 @@ static const struct tune_params qdf24xx_tunings = 0, /* max_case_values. */ tune_params::AUTOPREFETCHER_WEAK, /* autoprefetcher_model. */ AARCH64_EXTRA_TUNE_RENAME_LOAD_REGS, /* tune_flags. */ - &qdf24xx_prefetch_tune + &qdf24xx_prefetch_tune, + tune_params::LDP_POLICY_ALWAYS, /* ldp_policy_model. */ + tune_params::STP_POLICY_ALWAYS /* stp_policy_model. */ }; /* Tuning structure for the Qualcomm Saphira core. Default to falkor values @@ -1798,7 +1823,9 @@ static const struct tune_params saphira_tunings = 0, /* max_case_values. */ tune_params::AUTOPREFETCHER_WEAK, /* autoprefetcher_model. */ (AARCH64_EXTRA_TUNE_NONE), /* tune_flags. */ - &generic_prefetch_tune + &generic_prefetch_tune, + tune_params::LDP_POLICY_ALWAYS, /* ldp_policy_model. */ + tune_params::STP_POLICY_ALWAYS /* stp_policy_model. */ }; static const struct tune_params thunderx2t99_tunings = @@ -1832,7 +1859,9 @@ static const struct tune_params thunderx2t99_tunings = 0, /* max_case_values. */ tune_params::AUTOPREFETCHER_WEAK, /* autoprefetcher_model. */ (AARCH64_EXTRA_TUNE_NONE), /* tune_flags. */ - &thunderx2t99_prefetch_tune + &thunderx2t99_prefetch_tune, + tune_params::LDP_POLICY_ALWAYS, /* ldp_policy_model. */ + tune_params::STP_POLICY_ALWAYS /* stp_policy_model. */ }; static const struct tune_params thunderx3t110_tunings = @@ -1866,7 +1895,9 @@ static const struct tune_params thunderx3t110_tunings = 0, /* max_case_values. */ tune_params::AUTOPREFETCHER_WEAK, /* autoprefetcher_model. */ (AARCH64_EXTRA_TUNE_NONE), /* tune_flags. */ - &thunderx3t110_prefetch_tune + &thunderx3t110_prefetch_tune, + tune_params::LDP_POLICY_ALWAYS, /* ldp_policy_model. */ + tune_params::STP_POLICY_ALWAYS /* stp_policy_model. */ }; static const struct tune_params neoversen1_tunings = @@ -1899,7 +1930,9 @@ static const struct tune_params neoversen1_tunings = 0, /* max_case_values. */ tune_params::AUTOPREFETCHER_WEAK, /* autoprefetcher_model. */ (AARCH64_EXTRA_TUNE_CHEAP_SHIFT_EXTEND), /* tune_flags. */ - &generic_prefetch_tune + &generic_prefetch_tune, + tune_params::LDP_POLICY_ALWAYS, /* ldp_policy_model. */ + tune_params::STP_POLICY_ALWAYS /* stp_policy_model. */ }; static const struct tune_params ampere1_tunings = @@ -1935,8 +1968,10 @@ static const struct tune_params ampere1_tunings = 2, /* min_div_recip_mul_df. */ 0, /* max_case_values. */ tune_params::AUTOPREFETCHER_WEAK, /* autoprefetcher_model. */ - (AARCH64_EXTRA_TUNE_NO_LDP_COMBINE), /* tune_flags. */ - &ere1_prefetch_tune + (AARCH64_EXTRA_TUNE_NONE), /* tune_flags. */ + &ere1_prefetch_tune, + tune_params::LDP_POLICY_ALIGNED, /* ldp_policy_model. */ + tune_params::STP_POLICY_ALIGNED /* stp_policy_model. */ }; static const struct tune_params ampere1a_tunings = @@ -1973,8 +2008,10 @@ static const struct tune_params ampere1a_tunings = 2, /* min_div_recip_mul_df. */ 0, /* max_case_values. */ tune_params::AUTOPREFETCHER_WEAK, /* autoprefetcher_model. */ - (AARCH64_EXTRA_TUNE_NO_LDP_COMBINE), /* tune_flags. */ - &ere1_prefetch_tune + (AARCH64_EXTRA_TUNE_NONE), /* tune_flags. */ + &ere1_prefetch_tune, + tune_params::LDP_POLICY_ALIGNED, /* ldp_policy_model. */ + tune_params::STP_POLICY_ALIGNED /* stp_policy_model. */ }; static const advsimd_vec_cost neoversev1_advsimd_vector_cost = @@ -2155,7 +2192,9 @@ static const struct tune_params neoversev1_tunings = | AARCH64_EXTRA_TUNE_USE_NEW_VECTOR_COSTS | AARCH64_EXTRA_TUNE_MATCHED_VECTOR_THROUGHPUT | AARCH64_EXTRA_TUNE_CHEAP_SHIFT_EXTEND), /* tune_flags. */ - &generic_prefetch_tune + &generic_prefetch_tune, + tune_params::LDP_POLICY_ALWAYS, /* ldp_policy_model. */ + tune_params::STP_POLICY_ALWAYS /* stp_policy_model. */ }; static const sve_vec_cost neoverse512tvb_sve_vector_cost = @@ -2292,7 +2331,9 @@ static const struct tune_params neoverse512tvb_tunings = (AARCH64_EXTRA_TUNE_CSE_SVE_VL_CONSTANTS | AARCH64_EXTRA_TUNE_USE_NEW_VECTOR_COSTS | AARCH64_EXTRA_TUNE_MATCHED_VECTOR_THROUGHPUT), /* tune_flags. */ - &generic_prefetch_tune + &generic_prefetch_tune, + tune_params::LDP_POLICY_ALWAYS, /* ldp_policy_model. */ + tune_params::STP_POLICY_ALWAYS /* stp_policy_model. */ }; static const advsimd_vec_cost neoversen2_advsimd_vector_cost = @@ -2482,7 +2523,9 @@ static const struct tune_params neoversen2_tunings = | AARCH64_EXTRA_TUNE_CSE_SVE_VL_CONSTANTS | AARCH64_EXTRA_TUNE_USE_NEW_VECTOR_COSTS | AARCH64_EXTRA_TUNE_MATCHED_VECTOR_THROUGHPUT), /* tune_flags. */ - &generic_prefetch_tune + &generic_prefetch_tune, + tune_params::LDP_POLICY_ALWAYS, /* ldp_policy_model. */ + tune_params::STP_POLICY_ALWAYS /* stp_policy_model. */ }; static const advsimd_vec_cost neoversev2_advsimd_vector_cost = @@ -2672,7 +2715,9 @@ static const struct tune_params neoversev2_tunings = | AARCH64_EXTRA_TUNE_CSE_SVE_VL_CONSTANTS | AARCH64_EXTRA_TUNE_USE_NEW_VECTOR_COSTS | AARCH64_EXTRA_TUNE_MATCHED_VECTOR_THROUGHPUT), /* tune_flags. */ - &generic_prefetch_tune + &generic_prefetch_tune, + tune_params::LDP_POLICY_ALWAYS, /* ldp_policy_model. */ + tune_params::STP_POLICY_ALWAYS /* stp_policy_model. */ }; static const struct tune_params a64fx_tunings = @@ -2705,7 +2750,9 @@ static const struct tune_params a64fx_tunings = 0, /* max_case_values. */ tune_params::AUTOPREFETCHER_WEAK, /* autoprefetcher_model. */ (AARCH64_EXTRA_TUNE_NONE), /* tune_flags. */ - &a64fx_prefetch_tune + &a64fx_prefetch_tune, + tune_params::LDP_POLICY_ALWAYS, /* ldp_policy_model. */ + tune_params::STP_POLICY_ALWAYS /* stp_policy_model. */ }; /* Support for fine-grained override of the tuning structures. */ @@ -17645,6 +17692,50 @@ aarch64_parse_tune (const char *to_parse, const struct processor **res) return AARCH_PARSE_INVALID_ARG; } +/* Validate a command-line -mldp-policy option. Parse the policy + specified in STR and throw errors if appropriate. */ + +static bool +aarch64_parse_ldp_policy (const char *str, struct tune_params* tune) +{ + /* Check the value of the option to be one of the accepted. */ + if (strcmp (str, "always") == 0) + tune->ldp_policy_model = tune_params::LDP_POLICY_ALWAYS; + else if (strcmp (str, "never") == 0) + tune->ldp_policy_model = tune_params::LDP_POLICY_NEVER; + else if (strcmp (str, "aligned") == 0) + tune->ldp_policy_model = tune_params::LDP_POLICY_ALIGNED; + else if (strcmp (str, "default") != 0) + { + error ("unknown value %qs for %<-mldp-policy%>", str); + return false; + } + + return true; +} + +/* Validate a command-line -mstp-policy option. Parse the policy + specified in STR and throw errors if appropriate. */ + +static bool +aarch64_parse_stp_policy (const char *str, struct tune_params* tune) +{ + /* Check the value of the option to be one of the accepted. */ + if (strcmp (str, "always") == 0) + tune->stp_policy_model = tune_params::STP_POLICY_ALWAYS; + else if (strcmp (str, "never") == 0) + tune->stp_policy_model = tune_params::STP_POLICY_NEVER; + else if (strcmp (str, "aligned") == 0) + tune->stp_policy_model = tune_params::STP_POLICY_ALIGNED; + else if (strcmp (str, "default") != 0) + { + error ("unknown value %qs for %<-mstp-policy%>", str); + return false; + } + + return true; +} + /* Parse TOKEN, which has length LENGTH to see if it is an option described in FLAG. If it is, return the index bit for that fusion type. If not, error (printing OPTION_NAME) and return zero. */ @@ -17993,6 +18084,14 @@ aarch64_override_options_internal (struct gcc_options *opts) aarch64_parse_override_string (opts->x_aarch64_override_tune_string, &aarch64_tune_params); + if (opts->x_aarch64_ldp_policy_string) + aarch64_parse_ldp_policy (opts->x_aarch64_ldp_policy_string, + &aarch64_tune_params); + + if (opts->x_aarch64_stp_policy_string) + aarch64_parse_stp_policy (opts->x_aarch64_stp_policy_string, + &aarch64_tune_params); + /* This target defaults to strict volatile bitfields. */ if (opts->x_flag_strict_volatile_bitfields < 0 && abi_version_at_least (2)) opts->x_flag_strict_volatile_bitfields = 1; @@ -26301,18 +26400,14 @@ aarch64_operands_ok_for_ldpstp (rtx *operands, bool load, enum reg_class rclass_1, rclass_2; rtx mem_1, mem_2, reg_1, reg_2; - /* Allow the tuning structure to disable LDP instruction formation - from combining instructions (e.g., in peephole2). - TODO: Implement fine-grained tuning control for LDP and STP: - 1. control policies for load and store separately; - 2. support the following policies: - - default (use what is in the tuning structure) - - always - - never - - aligned (only if the compiler can prove that the - load will be aligned to 2 * element_size) */ - if (load && (aarch64_tune_params.extra_tuning_flags - & AARCH64_EXTRA_TUNE_NO_LDP_COMBINE)) + /* If we have LDP_POLICY_NEVER, reject the load pair. */ + if (load + && aarch64_tune_params.ldp_policy_model == tune_params::LDP_POLICY_NEVER) + return false; + + /* If we have STP_POLICY_NEVER, reject the store pair. */ + if (!load + && aarch64_tune_params.stp_policy_model == tune_params::STP_POLICY_NEVER) return false; if (load) @@ -26339,13 +26434,22 @@ aarch64_operands_ok_for_ldpstp (rtx *operands, bool load, if (MEM_VOLATILE_P (mem_1) || MEM_VOLATILE_P (mem_2)) return false; - /* If we have SImode and slow unaligned ldp, - check the alignment to be at least 8 byte. */ - if (mode == SImode - && (aarch64_tune_params.extra_tuning_flags - & AARCH64_EXTRA_TUNE_SLOW_UNALIGNED_LDPW) + /* If we have LDP_POLICY_ALIGNED, + do not emit the load pair unless the alignment is checked to be + at least double the alignment of the type. */ + if (load + && aarch64_tune_params.ldp_policy_model == tune_params::LDP_POLICY_ALIGNED && !optimize_size - && MEM_ALIGN (mem_1) < 8 * BITS_PER_UNIT) + && MEM_ALIGN (mem_1) < 2 * GET_MODE_ALIGNMENT (mode)) + return false; + + /* If we have STP_POLICY_ALIGNED, + do not emit the store pair unless the alignment is checked to be + at least double the alignment of the type. */ + if (!load + && aarch64_tune_params.stp_policy_model == tune_params::STP_POLICY_ALIGNED + && !optimize_size + && MEM_ALIGN (mem_1) < 2 * GET_MODE_ALIGNMENT (mode)) return false; /* Check if the addresses are in the form of [base+offset]. */ @@ -26475,6 +26579,16 @@ aarch64_operands_adjust_ok_for_ldpstp (rtx *operands, bool load, HOST_WIDE_INT offvals[num_insns], msize; rtx mem[num_insns], reg[num_insns], base[num_insns], offset[num_insns]; + /* If we have LDP_POLICY_NEVER, reject the load pair. */ + if (load + && aarch64_tune_params.ldp_policy_model == tune_params::LDP_POLICY_NEVER) + return false; + + /* If we have STP_POLICY_NEVER, reject the store pair. */ + if (!load + && aarch64_tune_params.stp_policy_model == tune_params::STP_POLICY_NEVER) + return false; + if (load) { for (int i = 0; i < num_insns; i++) @@ -26564,13 +26678,22 @@ aarch64_operands_adjust_ok_for_ldpstp (rtx *operands, bool load, if (offvals[0] % msize != offvals[2] % msize) return false; - /* If we have SImode and slow unaligned ldp, - check the alignment to be at least 8 byte. */ - if (mode == SImode - && (aarch64_tune_params.extra_tuning_flags - & AARCH64_EXTRA_TUNE_SLOW_UNALIGNED_LDPW) + /* If we have LDP_POLICY_ALIGNED, + do not emit the load pair unless the alignment is checked to be + at least double the alignment of the type. */ + if (load + && aarch64_tune_params.ldp_policy_model == tune_params::LDP_POLICY_ALIGNED + && !optimize_size + && MEM_ALIGN (mem[0]) < 2 * GET_MODE_ALIGNMENT (mode)) + return false; + + /* If we have STP_POLICY_ALIGNED, + do not emit the store pair unless the alignment is checked to be + at least double the alignment of the type. */ + if (!load + && aarch64_tune_params.stp_policy_model == tune_params::STP_POLICY_ALIGNED && !optimize_size - && MEM_ALIGN (mem[0]) < 8 * BITS_PER_UNIT) + && MEM_ALIGN (mem[0]) < 2 * GET_MODE_ALIGNMENT (mode)) return false; return true; diff --git a/gcc/config/aarch64/aarch64.opt b/gcc/config/aarch64/aarch64.opt index 4a0580435a8..e5302947ce7 100644 --- a/gcc/config/aarch64/aarch64.opt +++ b/gcc/config/aarch64/aarch64.opt @@ -205,6 +205,14 @@ msign-return-address= Target WarnRemoved RejectNegative Joined Enum(aarch_ra_sign_scope_t) Var(aarch_ra_sign_scope) Init(AARCH_FUNCTION_NONE) Save Select return address signing scope. +mldp-policy= +Target RejectNegative Joined Var(aarch64_ldp_policy_string) Save +Fine-grained policy for load pairs. + +mstp-policy= +Target RejectNegative Joined Var(aarch64_stp_policy_string) Save +Fine-grained policy for store pairs. + Enum Name(aarch_ra_sign_scope_t) Type(enum aarch_function_type) Supported AArch64 return address signing scope (for use with -msign-return-address= option): diff --git a/gcc/testsuite/gcc.target/aarch64/ldp_aligned.c b/gcc/testsuite/gcc.target/aarch64/ldp_aligned.c new file mode 100644 index 00000000000..895018f6b53 --- /dev/null +++ b/gcc/testsuite/gcc.target/aarch64/ldp_aligned.c @@ -0,0 +1,64 @@ +/* { dg-options "-O3 -mldp-policy=aligned" } */ + +#include +#include + +typedef int v4si __attribute__ ((vector_size (16))); + +#define LDP_TEST_ALIGNED(TYPE) \ +TYPE ldp_aligned_##TYPE(char* ptr){ \ + TYPE a_0, a_1; \ + TYPE *arr = (TYPE*) ((uintptr_t)ptr & ~(2 * 8 * _Alignof(TYPE) - 1)); \ + a_0 = arr[0]; \ + a_1 = arr[1]; \ + return a_0 + a_1; \ +} + +#define LDP_TEST_UNALIGNED(TYPE) \ +TYPE ldp_unaligned_##TYPE(char* ptr){ \ + TYPE a_0, a_1; \ + TYPE *arr = (TYPE*) ((uintptr_t)ptr & ~(2 * 8 * _Alignof(TYPE) - 1)); \ + TYPE *a = arr+1; \ + a_0 = a[0]; \ + a_1 = a[1]; \ + return a_0 + a_1; \ +} + +#define LDP_TEST_ADJUST_ALIGNED(TYPE) \ +TYPE ldp_aligned_adjust_##TYPE(char* ptr){ \ + TYPE a_0, a_1, a_2, a_3; \ + TYPE *arr = (TYPE*) ((uintptr_t)ptr & ~(2 * 8 * _Alignof(TYPE) - 1)); \ + a_0 = arr[100]; \ + a_1 = arr[101]; \ + a_2 = arr[102]; \ + a_3 = arr[103]; \ + return a_0 + a_1 + a_2 + a_3; \ +} + +#define LDP_TEST_ADJUST_UNALIGNED(TYPE) \ +TYPE ldp_unaligned_adjust_##TYPE(char* ptr){ \ + TYPE a_0, a_1, a_2, a_3; \ + TYPE *arr = (TYPE*) ((uintptr_t)ptr & ~(2 * 8 * _Alignof(TYPE) - 1)); \ + TYPE *a = arr+1; \ + a_0 = a[100]; \ + a_1 = a[101]; \ + a_2 = a[102]; \ + a_3 = a[103]; \ + return a_0 + a_1 + a_2 + a_3; \ +} + +LDP_TEST_ALIGNED(int32_t); +LDP_TEST_ALIGNED(int64_t); +LDP_TEST_ALIGNED(v4si); +LDP_TEST_UNALIGNED(int32_t); +LDP_TEST_UNALIGNED(int64_t); +LDP_TEST_UNALIGNED(v4si); +LDP_TEST_ADJUST_ALIGNED(int32_t); +LDP_TEST_ADJUST_ALIGNED(int64_t); +LDP_TEST_ADJUST_UNALIGNED(int32_t); +LDP_TEST_ADJUST_UNALIGNED(int64_t); + +/* { dg-final { scan-assembler-times "ldp\tw\[0-9\]+, w\[0-9\]" 3 } } */ +/* { dg-final { scan-assembler-times "ldp\tx\[0-9\]+, x\[0-9\]" 3 } } */ +/* { dg-final { scan-assembler-times "ldp\tq\[0-9\]+, q\[0-9\]" 1 } } */ + diff --git a/gcc/testsuite/gcc.target/aarch64/ldp_always.c b/gcc/testsuite/gcc.target/aarch64/ldp_always.c new file mode 100644 index 00000000000..ead4fe41891 --- /dev/null +++ b/gcc/testsuite/gcc.target/aarch64/ldp_always.c @@ -0,0 +1,64 @@ +/* { dg-options "-O3 -mldp-policy=always" } */ + +#include +#include + +typedef int v4si __attribute__ ((vector_size (16))); + +#define LDP_TEST_ALIGNED(TYPE) \ +TYPE ldp_aligned_##TYPE(char* ptr){ \ + TYPE a_0, a_1; \ + TYPE *arr = (TYPE*) ((uintptr_t)ptr & ~(2 * 8 * _Alignof(TYPE) - 1)); \ + a_0 = arr[0]; \ + a_1 = arr[1]; \ + return a_0 + a_1; \ +} + +#define LDP_TEST_UNALIGNED(TYPE) \ +TYPE ldp_unaligned_##TYPE(char* ptr){ \ + TYPE a_0, a_1; \ + TYPE *arr = (TYPE*) ((uintptr_t)ptr & ~(2 * 8 * _Alignof(TYPE) - 1)); \ + TYPE *a = arr+1; \ + a_0 = a[0]; \ + a_1 = a[1]; \ + return a_0 + a_1; \ +} + +#define LDP_TEST_ADJUST_ALIGNED(TYPE) \ +TYPE ldp_aligned_adjust_##TYPE(char* ptr){ \ + TYPE a_0, a_1, a_2, a_3; \ + TYPE *arr = (TYPE*) ((uintptr_t)ptr & ~(2 * 8 * _Alignof(TYPE) - 1)); \ + a_0 = arr[100]; \ + a_1 = arr[101]; \ + a_2 = arr[102]; \ + a_3 = arr[103]; \ + return a_0 + a_1 + a_2 + a_3; \ +} + +#define LDP_TEST_ADJUST_UNALIGNED(TYPE) \ +TYPE ldp_unaligned_adjust_##TYPE(char* ptr){ \ + TYPE a_0, a_1, a_2, a_3; \ + TYPE *arr = (TYPE*) ((uintptr_t)ptr & ~(2 * 8 * _Alignof(TYPE) - 1)); \ + TYPE *a = arr+1; \ + a_0 = a[100]; \ + a_1 = a[101]; \ + a_2 = a[102]; \ + a_3 = a[103]; \ + return a_0 + a_1 + a_2 + a_3; \ +} + +LDP_TEST_ALIGNED(int32_t); +LDP_TEST_ALIGNED(int64_t); +LDP_TEST_ALIGNED(v4si); +LDP_TEST_UNALIGNED(int32_t); +LDP_TEST_UNALIGNED(int64_t); +LDP_TEST_UNALIGNED(v4si); +LDP_TEST_ADJUST_ALIGNED(int32_t); +LDP_TEST_ADJUST_ALIGNED(int64_t); +LDP_TEST_ADJUST_UNALIGNED(int32_t); +LDP_TEST_ADJUST_UNALIGNED(int64_t); + +/* { dg-final { scan-assembler-times "ldp\tw\[0-9\]+, w\[0-9\]" 6 } } */ +/* { dg-final { scan-assembler-times "ldp\tx\[0-9\]+, x\[0-9\]" 6 } } */ +/* { dg-final { scan-assembler-times "ldp\tq\[0-9\]+, q\[0-9\]" 2 } } */ + diff --git a/gcc/testsuite/gcc.target/aarch64/ldp_never.c b/gcc/testsuite/gcc.target/aarch64/ldp_never.c new file mode 100644 index 00000000000..aae2f087241 --- /dev/null +++ b/gcc/testsuite/gcc.target/aarch64/ldp_never.c @@ -0,0 +1,64 @@ +/* { dg-options "-O3 -mldp-policy=never" } */ + +#include +#include + +typedef int v4si __attribute__ ((vector_size (16))); + +#define LDP_TEST_ALIGNED(TYPE) \ +TYPE ldp_aligned_##TYPE(char* ptr){ \ + TYPE a_0, a_1; \ + TYPE *arr = (TYPE*) ((uintptr_t)ptr & ~(2 * 8 * _Alignof(TYPE) - 1)); \ + a_0 = arr[0]; \ + a_1 = arr[1]; \ + return a_0 + a_1; \ +} + +#define LDP_TEST_UNALIGNED(TYPE) \ +TYPE ldp_unaligned_##TYPE(char* ptr){ \ + TYPE a_0, a_1; \ + TYPE *arr = (TYPE*) ((uintptr_t)ptr & ~(2 * 8 * _Alignof(TYPE) - 1)); \ + TYPE *a = arr+1; \ + a_0 = a[0]; \ + a_1 = a[1]; \ + return a_0 + a_1; \ +} + +#define LDP_TEST_ADJUST_ALIGNED(TYPE) \ +TYPE ldp_aligned_adjust_##TYPE(char* ptr){ \ + TYPE a_0, a_1, a_2, a_3; \ + TYPE *arr = (TYPE*) ((uintptr_t)ptr & ~(2 * 8 * _Alignof(TYPE) - 1)); \ + a_0 = arr[100]; \ + a_1 = arr[101]; \ + a_2 = arr[102]; \ + a_3 = arr[103]; \ + return a_0 + a_1 + a_2 + a_3; \ +} + +#define LDP_TEST_ADJUST_UNALIGNED(TYPE) \ +TYPE ldp_unaligned_adjust_##TYPE(char* ptr){ \ + TYPE a_0, a_1, a_2, a_3; \ + TYPE *arr = (TYPE*) ((uintptr_t)ptr & ~(2 * 8 * _Alignof(TYPE) - 1)); \ + TYPE *a = arr+1; \ + a_0 = a[100]; \ + a_1 = a[101]; \ + a_2 = a[102]; \ + a_3 = a[103]; \ + return a_0 + a_1 + a_2 + a_3; \ +} + +LDP_TEST_ALIGNED(int32_t); +LDP_TEST_ALIGNED(int64_t); +LDP_TEST_ALIGNED(v4si); +LDP_TEST_UNALIGNED(int32_t); +LDP_TEST_UNALIGNED(int64_t); +LDP_TEST_UNALIGNED(v4si); +LDP_TEST_ADJUST_ALIGNED(int32_t); +LDP_TEST_ADJUST_ALIGNED(int64_t); +LDP_TEST_ADJUST_UNALIGNED(int32_t); +LDP_TEST_ADJUST_UNALIGNED(int64_t); + +/* { dg-final { scan-assembler-times "ldp\tw\[0-9\]+, w\[0-9\]" 0 } } */ +/* { dg-final { scan-assembler-times "ldp\tx\[0-9\]+, x\[0-9\]" 0 } } */ +/* { dg-final { scan-assembler-times "ldp\tq\[0-9\]+, q\[0-9\]" 0 } } */ + diff --git a/gcc/testsuite/gcc.target/aarch64/stp_aligned.c b/gcc/testsuite/gcc.target/aarch64/stp_aligned.c new file mode 100644 index 00000000000..07b49629292 --- /dev/null +++ b/gcc/testsuite/gcc.target/aarch64/stp_aligned.c @@ -0,0 +1,60 @@ +/* { dg-options "-O3 -mstp-policy=aligned" } */ + +#include +#include + +typedef int v4si __attribute__ ((vector_size (16))); + +#define STP_TEST_ALIGNED(TYPE) \ +TYPE *stp_aligned_##TYPE(char* ptr, TYPE x){ \ + TYPE *arr = (TYPE*) ((uintptr_t)ptr & ~(2 * 8 * _Alignof(TYPE) - 1)); \ + arr[0] = x; \ + arr[1] = x; \ + return arr; \ +} + +#define STP_TEST_UNALIGNED(TYPE) \ +TYPE *stp_unaligned_##TYPE(char* ptr, TYPE x){ \ + TYPE *arr = (TYPE*) ((uintptr_t)ptr & ~(2 * 8 * _Alignof(TYPE) - 1)); \ + TYPE *a = arr+1; \ + a[0] = x; \ + a[1] = x; \ + return a; \ +} + +#define STP_TEST_ADJUST_ALIGNED(TYPE) \ +TYPE *stp_aligned_adjust_##TYPE(char* ptr, TYPE x){ \ + TYPE *arr = (TYPE*) ((uintptr_t)ptr & ~(2 * 8 * _Alignof(TYPE) - 1)); \ + arr[100] = x; \ + arr[101] = x; \ + arr[102] = x; \ + arr[103] = x; \ + return arr; \ +} + +#define STP_TEST_ADJUST_UNALIGNED(TYPE) \ +TYPE *stp_unaligned_adjust_##TYPE(char* ptr, TYPE x){ \ + TYPE *arr = (TYPE*) ((uintptr_t)ptr & ~(2 * 8 * _Alignof(TYPE) - 1)); \ + TYPE *a = arr+1; \ + a[100] = x; \ + a[101] = x; \ + a[102] = x; \ + a[103] = x; \ + return a; \ +} + +STP_TEST_ALIGNED(int32_t); +STP_TEST_ALIGNED(int64_t); +STP_TEST_ALIGNED(v4si); +STP_TEST_UNALIGNED(int32_t); +STP_TEST_UNALIGNED(int64_t); +STP_TEST_UNALIGNED(v4si); +STP_TEST_ADJUST_ALIGNED(int32_t); +STP_TEST_ADJUST_ALIGNED(int64_t); +STP_TEST_ADJUST_UNALIGNED(int32_t); +STP_TEST_ADJUST_UNALIGNED(int64_t); + +/* { dg-final { scan-assembler-times "stp\tw\[0-9\]+, w\[0-9\]" 3 } } */ +/* { dg-final { scan-assembler-times "stp\tx\[0-9\]+, x\[0-9\]" 3 } } */ +/* { dg-final { scan-assembler-times "stp\tq\[0-9\]+, q\[0-9\]" 1 } } */ + diff --git a/gcc/testsuite/gcc.target/aarch64/stp_always.c b/gcc/testsuite/gcc.target/aarch64/stp_always.c new file mode 100644 index 00000000000..6a1c671f02c --- /dev/null +++ b/gcc/testsuite/gcc.target/aarch64/stp_always.c @@ -0,0 +1,60 @@ +/* { dg-options "-O3 -mstp-policy=always" } */ + +#include +#include + +typedef int v4si __attribute__ ((vector_size (16))); + +#define STP_TEST_ALIGNED(TYPE) \ +TYPE *stp_aligned_##TYPE(char* ptr, TYPE x){ \ + TYPE *arr = (TYPE*) ((uintptr_t)ptr & ~(2 * 8 * _Alignof(TYPE) - 1)); \ + arr[0] = x; \ + arr[1] = x; \ + return arr; \ +} + +#define STP_TEST_UNALIGNED(TYPE) \ +TYPE *stp_unaligned_##TYPE(char* ptr, TYPE x){ \ + TYPE *arr = (TYPE*) ((uintptr_t)ptr & ~(2 * 8 * _Alignof(TYPE) - 1)); \ + TYPE *a = arr+1; \ + a[0] = x; \ + a[1] = x; \ + return a; \ +} + +#define STP_TEST_ADJUST_ALIGNED(TYPE) \ +TYPE *stp_aligned_adjust_##TYPE(char* ptr, TYPE x){ \ + TYPE *arr = (TYPE*) ((uintptr_t)ptr & ~(2 * 8 * _Alignof(TYPE) - 1)); \ + arr[100] = x; \ + arr[101] = x; \ + arr[102] = x; \ + arr[103] = x; \ + return arr; \ +} + +#define STP_TEST_ADJUST_UNALIGNED(TYPE) \ +TYPE *stp_unaligned_adjust_##TYPE(char* ptr, TYPE x){ \ + TYPE *arr = (TYPE*) ((uintptr_t)ptr & ~(2 * 8 * _Alignof(TYPE) - 1)); \ + TYPE *a = arr+1; \ + a[100] = x; \ + a[101] = x; \ + a[102] = x; \ + a[103] = x; \ + return a; \ +} + +STP_TEST_ALIGNED(int32_t); +STP_TEST_ALIGNED(int64_t); +STP_TEST_ALIGNED(v4si); +STP_TEST_UNALIGNED(int32_t); +STP_TEST_UNALIGNED(int64_t); +STP_TEST_UNALIGNED(v4si); +STP_TEST_ADJUST_ALIGNED(int32_t); +STP_TEST_ADJUST_ALIGNED(int64_t); +STP_TEST_ADJUST_UNALIGNED(int32_t); +STP_TEST_ADJUST_UNALIGNED(int64_t); + +/* { dg-final { scan-assembler-times "stp\tw\[0-9\]+, w\[0-9\]" 6 } } */ +/* { dg-final { scan-assembler-times "stp\tx\[0-9\]+, x\[0-9\]" 6 } } */ +/* { dg-final { scan-assembler-times "stp\tq\[0-9\]+, q\[0-9\]" 2 } } */ + diff --git a/gcc/testsuite/gcc.target/aarch64/stp_never.c b/gcc/testsuite/gcc.target/aarch64/stp_never.c new file mode 100644 index 00000000000..9cd703995b7 --- /dev/null +++ b/gcc/testsuite/gcc.target/aarch64/stp_never.c @@ -0,0 +1,60 @@ +/* { dg-options "-O3 -mstp-policy=never" } */ + +#include +#include + +typedef int v4si __attribute__ ((vector_size (16))); + +#define STP_TEST_ALIGNED(TYPE) \ +TYPE *stp_aligned_##TYPE(char* ptr, TYPE x){ \ + TYPE *arr = (TYPE*) ((uintptr_t)ptr & ~(2 * 8 * _Alignof(TYPE) - 1)); \ + arr[0] = x; \ + arr[1] = x; \ + return arr; \ +} + +#define STP_TEST_UNALIGNED(TYPE) \ +TYPE *stp_unaligned_##TYPE(char* ptr, TYPE x){ \ + TYPE *arr = (TYPE*) ((uintptr_t)ptr & ~(2 * 8 * _Alignof(TYPE) - 1)); \ + TYPE *a = arr+1; \ + a[0] = x; \ + a[1] = x; \ + return a; \ +} + +#define STP_TEST_ADJUST_ALIGNED(TYPE) \ +TYPE *stp_aligned_adjust_##TYPE(char* ptr, TYPE x){ \ + TYPE *arr = (TYPE*) ((uintptr_t)ptr & ~(2 * 8 * _Alignof(TYPE) - 1)); \ + arr[100] = x; \ + arr[101] = x; \ + arr[102] = x; \ + arr[103] = x; \ + return arr; \ +} + +#define STP_TEST_ADJUST_UNALIGNED(TYPE) \ +TYPE *stp_unaligned_adjust_##TYPE(char* ptr, TYPE x){ \ + TYPE *arr = (TYPE*) ((uintptr_t)ptr & ~(2 * 8 * _Alignof(TYPE) - 1)); \ + TYPE *a = arr+1; \ + a[100] = x; \ + a[101] = x; \ + a[102] = x; \ + a[103] = x; \ + return a; \ +} + +STP_TEST_ALIGNED(int32_t); +STP_TEST_ALIGNED(int64_t); +STP_TEST_ALIGNED(v4si); +STP_TEST_UNALIGNED(int32_t); +STP_TEST_UNALIGNED(int64_t); +STP_TEST_UNALIGNED(v4si); +STP_TEST_ADJUST_ALIGNED(int32_t); +STP_TEST_ADJUST_ALIGNED(int64_t); +STP_TEST_ADJUST_UNALIGNED(int32_t); +STP_TEST_ADJUST_UNALIGNED(int64_t); + +/* { dg-final { scan-assembler-times "stp\tw\[0-9\]+, w\[0-9\]" 0 } } */ +/* { dg-final { scan-assembler-times "stp\tx\[0-9\]+, x\[0-9\]" 0 } } */ +/* { dg-final { scan-assembler-times "stp\tq\[0-9\]+, q\[0-9\]" 0 } } */ +