From patchwork Mon Jul 9 16:38:17 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Richard Earnshaw \(lists\)" X-Patchwork-Id: 141473 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp2872922ljj; Mon, 9 Jul 2018 09:41:04 -0700 (PDT) X-Google-Smtp-Source: AAOMgpebsr2XTiLQMJtBtsYQDeBOSkHbEYil+8CNeCLXMU1BKHAvEXAePiZZcotnIvEL8EKyS5nC X-Received: by 2002:a63:7847:: with SMTP id t68-v6mr13348531pgc.329.1531154464837; Mon, 09 Jul 2018 09:41:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531154464; cv=none; d=google.com; s=arc-20160816; b=nFDsORguBGHEVxrf9z8T9f9Z4rjNYMRfYptW/AE4ReKtgNCwEc3m2uKIG27b/UWyyt NgPyZQnISZvEXrDQd5fIVhYAVz9v9mRPo44qDoJ44vbyC5uN19zUI4qFWE89R36ezfNn pvuegbmDvrNco67arSuL03pNC4XmzNCOx7PrMaI0Dp95bf8NbjOmBwoJBXkGvn0J+Bv/ FfQ79TqL1XuRUdkqBoxx7m+6ER/gD8Z+dbPyTL2AD/ehYkz9jPvdgQtOwmSmWQp6fd47 WeGL6JDR9mi6MQjURGFGfxHKQjw1V8TBns2ukC7JSK5+Sh3HRgFM71b6lyS0rfxJm96L 24NA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:delivered-to:sender:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:mailing-list:dkim-signature :domainkey-signature:arc-authentication-results; bh=zjCMsnokAB+WBEEv+Y/3DhR/3pGtxGLCkJa2ub0nkbk=; b=ndMNuwo4E7PAXB2d16jGiWbJ5qQE+LKxT348r8gPD4gmIG8gwG3VQ1HbdmAJmHEiso IZZJsI1xc1lzWWip8FwVRUk7kXMUB7YVMGxwzuAG8HQZph0cRJhqwafmQB6nXn15ierZ vB/U3x9frmYACrF7gPGm1g2SBntYxM7wFH7NCV2Xnwmn0GT1yTiDLOjL0nUamwPALc7b 53NBCuJjnyMvZpdLqPn5KebBKcgZWhs3+Mm2gkSjAFH12dFPrcZhZPffkjlGMLVkPCtp vBC99f5U5znfoh07PKsAgqsaNWltG0oz7Z6g4XgnrD75fHuq+lGrwdiKf558S3BMKVP/ o07A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=aRSgzuE9; spf=pass (google.com: domain of gcc-patches-return-481233-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom="gcc-patches-return-481233-patch=linaro.org@gcc.gnu.org" Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id h17-v6si14119791pgg.218.2018.07.09.09.41.04 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 09 Jul 2018 09:41:04 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-return-481233-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=aRSgzuE9; spf=pass (google.com: domain of gcc-patches-return-481233-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom="gcc-patches-return-481233-patch=linaro.org@gcc.gnu.org" DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-type; q=dns; s=default; b=Gil/DC3b++v2lBuj aI1yVz9bBgD0eN0djgFpbOVdP+l168EXgPz218WDq3kBy++68S9LgQEG7oPohCSZ GzXcsij3DMjVGvD5TlABrYvQ9rNBYMe1gBB+lZnvNO/ROZCWQ+TyEvu5WyE1Cfq2 WIwGmwrrUPdunuUa5XwMGzblr3Q= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-type; s=default; bh=2bp0hhV537A7n4HMgoN/gL 7U2nI=; b=aRSgzuE96MlrJ/xZxpCwUxFwgvsBj8ZR4799mVSx1DgYwnaJfAjYXD Pta2llXdq3617FLQBe5s77qIq7IWgwQhBXIdi9sC2Xkuha3ozqwy+9fYvT8M/8O7 5qOuwQBsajTGp6INY8aVvvxvtNUVren87H9Fc8LVrI26PUJjP+1D0= Received: (qmail 91560 invoked by alias); 9 Jul 2018 16:39:28 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 91332 invoked by uid 89); 9 Jul 2018 16:39:27 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, SPF_FAIL autolearn=ham version=3.3.2 spammy= X-HELO: eggs.gnu.org Received: from eggs.gnu.org (HELO eggs.gnu.org) (208.118.235.92) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 09 Jul 2018 16:39:24 +0000 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fcZC2-0003FS-3c for gcc-patches@gcc.gnu.org; Mon, 09 Jul 2018 12:39:23 -0400 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:42130 helo=foss.arm.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fcZC1-0003Ed-PX for gcc-patches@gcc.gnu.org; Mon, 09 Jul 2018 12:39:18 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 9C7E51713; Mon, 9 Jul 2018 09:39:15 -0700 (PDT) Received: from e120077-lin.cambridge.arm.com (e120077-lin.cambridge.arm.com [10.2.206.23]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id D5F883F589; Mon, 9 Jul 2018 09:39:14 -0700 (PDT) From: Richard Earnshaw To: gcc-patches@gcc.gnu.org Cc: Richard Earnshaw , richard.earnshaw@arm.com Subject: [PATCH 5/7] AArch64 - disable CB[N]Z TB[N]Z when tracking speculation Date: Mon, 9 Jul 2018 17:38:17 +0100 Message-Id: <1531154299-28349-6-git-send-email-Richard.Earnshaw@arm.com> In-Reply-To: <1531154299-28349-1-git-send-email-Richard.Earnshaw@arm.com> References: <1531154299-28349-1-git-send-email-Richard.Earnshaw@arm.com> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 217.140.101.70 The CB[N]Z and TB[N]Z instructions do not expose the comparison through the condition code flags. This makes it impossible to track speculative execution through such a branch. We can handle this relatively easily by simply disabling the patterns in this case. A side effect of this is that the split patterns for the atomic operations need to also avoid generating these instructions. They mostly have simple fall-backs for this already. * config/aarch64/aarch64.md (cb1): Disable when aarch64_track_speculation is true. (tb1): Likewise. * config/aarch64/aarch64.c (aarch64_split_compare_regs): Do not generate CB[N]Z when tracking speculation. (aarch64_split_compare_and_swap): Likewise. (aarch64_split_atomic_op): Likewise. --- gcc/config/aarch64/aarch64.c | 33 ++++++++++++++++++++++++++++++--- gcc/config/aarch64/aarch64.md | 6 +++--- 2 files changed, 33 insertions(+), 6 deletions(-) diff --git a/gcc/config/aarch64/aarch64.c b/gcc/config/aarch64/aarch64.c index 01f35f8..da96afd 100644 --- a/gcc/config/aarch64/aarch64.c +++ b/gcc/config/aarch64/aarch64.c @@ -14465,7 +14465,16 @@ aarch64_split_compare_and_swap (rtx operands[]) if (strong_zero_p) { - x = gen_rtx_NE (VOIDmode, rval, const0_rtx); + if (aarch64_track_speculation) + { + /* Emit an explicit compare instruction, so that we can correctly + track the condition codes. */ + rtx cc_reg = aarch64_gen_compare_reg (NE, rval, const0_rtx); + x = gen_rtx_NE (GET_MODE (cc_reg), cc_reg, const0_rtx); + } + else + x = gen_rtx_NE (VOIDmode, rval, const0_rtx); + x = gen_rtx_IF_THEN_ELSE (VOIDmode, x, gen_rtx_LABEL_REF (Pmode, label2), pc_rtx); aarch64_emit_unlikely_jump (gen_rtx_SET (pc_rtx, x)); @@ -14483,7 +14492,16 @@ aarch64_split_compare_and_swap (rtx operands[]) if (!is_weak) { - x = gen_rtx_NE (VOIDmode, scratch, const0_rtx); + if (aarch64_track_speculation) + { + /* Emit an explicit compare instruction, so that we can correctly + track the condition codes. */ + rtx cc_reg = aarch64_gen_compare_reg (NE, scratch, const0_rtx); + x = gen_rtx_NE (GET_MODE (cc_reg), cc_reg, const0_rtx); + } + else + x = gen_rtx_NE (VOIDmode, scratch, const0_rtx); + x = gen_rtx_IF_THEN_ELSE (VOIDmode, x, gen_rtx_LABEL_REF (Pmode, label1), pc_rtx); aarch64_emit_unlikely_jump (gen_rtx_SET (pc_rtx, x)); @@ -14819,7 +14837,16 @@ aarch64_split_atomic_op (enum rtx_code code, rtx old_out, rtx new_out, rtx mem, aarch64_emit_store_exclusive (mode, cond, mem, gen_lowpart (mode, new_out), model_rtx); - x = gen_rtx_NE (VOIDmode, cond, const0_rtx); + if (aarch64_track_speculation) + { + /* Emit an explicit compare instruction, so that we can correctly + track the condition codes. */ + rtx cc_reg = aarch64_gen_compare_reg (NE, cond, const0_rtx); + x = gen_rtx_NE (GET_MODE (cc_reg), cc_reg, const0_rtx); + } + else + x = gen_rtx_NE (VOIDmode, cond, const0_rtx); + x = gen_rtx_IF_THEN_ELSE (VOIDmode, x, gen_rtx_LABEL_REF (Pmode, label), pc_rtx); aarch64_emit_unlikely_jump (gen_rtx_SET (pc_rtx, x)); diff --git a/gcc/config/aarch64/aarch64.md b/gcc/config/aarch64/aarch64.md index c135ada..259a07d 100644 --- a/gcc/config/aarch64/aarch64.md +++ b/gcc/config/aarch64/aarch64.md @@ -690,7 +690,7 @@ (define_insn "*cb1" (const_int 0)) (label_ref (match_operand 1 "" "")) (pc)))] - "" + "!aarch64_track_speculation" { if (get_attr_length (insn) == 8) return aarch64_gen_far_branch (operands, 1, "Lcb", "\\t%0, "); @@ -720,7 +720,7 @@ (define_insn "*tb1" (label_ref (match_operand 2 "" "")) (pc))) (clobber (reg:CC CC_REGNUM))] - "" + "!aarch64_track_speculation" { if (get_attr_length (insn) == 8) { @@ -756,7 +756,7 @@ (define_insn "*cb1" (label_ref (match_operand 1 "" "")) (pc))) (clobber (reg:CC CC_REGNUM))] - "" + "!aarch64_track_speculation" { if (get_attr_length (insn) == 8) {