From patchwork Wed Feb 14 08:30:50 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sameera Deshpande X-Patchwork-Id: 128323 Delivered-To: patch@linaro.org Received: by 10.46.124.24 with SMTP id x24csp363149ljc; Wed, 14 Feb 2018 00:31:08 -0800 (PST) X-Google-Smtp-Source: AH8x224LWdhWWqEMymWBP+rHgRiqyAeTmKGac4Kzu3tnUkWa6eRr7tDVH3GZeMkumnUP5zEhy9dS X-Received: by 2002:a17:902:aa8e:: with SMTP id d14-v6mr3645124plr.94.1518597067950; Wed, 14 Feb 2018 00:31:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518597067; cv=none; d=google.com; s=arc-20160816; b=nExFrdilKJyTHHEhj0fH57BUuxN+NdCfs/sLgP8IVuymcmNbEdnRdMX2L/NExin+oT k0EKa4uSEhNl1/Zkx4Lbr8oQFHGSiLdltLadn5VmVfMTNDi73V9VEJ0t6Ai+rNmon3s6 qSxaWPrJvOHkiHvwhcf+hSXA1IyOM86A/REnar89477mPHIvLgPjO9OaNJMcYlcStNgH wh/WHAnUJR7LG8bAhxlD/Uvwvsheuwd9G5+veIVTcOsxXkYQ89P3kOTqAKU5WhcBIArm /16IVCyZycX7t1okOglYB0cej7oVIQaTke+zHEHBNvHJMPpHxpNgzfT11oMHoHjBrLvG HkPg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:subject:message-id:date:from:mime-version:delivered-to:sender :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:mailing-list:dkim-signature:domainkey-signature :arc-authentication-results; bh=eirZ5jbtpK9QkMn73FnVznkswF5LAFoAHrj5dASjUUY=; b=ootv+8VOWQMBc7gUY43RTxKiaEnVn8galpnGSHhyyK3tvT6jMqU0F5/qihamavNFns RGA0005SDPvXAUn5X43bjjpp/dH6SdamoP3fVXydgM/QsYxedC1wtMC0JJXhk+H386+5 DfwJNOuryNA57gmZ9zKN32ePmSqY84AQx7ErN5xk+O/4ZaI8UPuqx19JCT7l5/RSv/zy 6JjPfMaGmu61YnIRspyRDI1UkcXjV31ht47EARB3XzJZf5jUrac1FFF++zUY4UGmY2tZ sty1mPQ8zjXTCUPR0JTHqMvrt/j3pW/QEAf02kIYKPjkoWaxxeWiTXhrhF+IP/swxfwG /gcA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=J1uLZ3D7; spf=pass (google.com: domain of gcc-patches-return-473247-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-473247-patch=linaro.org@gcc.gnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id 3-v6si2902723plo.59.2018.02.14.00.31.07 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 14 Feb 2018 00:31:07 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-return-473247-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=J1uLZ3D7; spf=pass (google.com: domain of gcc-patches-return-473247-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-473247-patch=linaro.org@gcc.gnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :mime-version:from:date:message-id:subject:to:cc:content-type; q=dns; s=default; b=OQbNxn+hUw1H980ol8cJxkIec+fGuLmPORPvGjbDYE2 /fRSoyPD7ZuffehHbn0/DFNtOcO1dGzQmNk1YpOgMNlCfbFu2DWDnxEErs94b7R/ gBNETuoIPcf6up4EFzgiUxnGQBoT7F5ylfUCwfM8RnV7lMuVI8t2GPbBOm1L5tM8 = 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 :mime-version:from:date:message-id:subject:to:cc:content-type; s=default; bh=ocBsPrcB4zfArnFBkE63Hd0VXgc=; b=J1uLZ3D7V0eJyUpHq 3jH4qlW+gmVsgOa6nAzhnxRUJSqq46JKNM7MuNyIt3RSY6v5tjACTh33qcwAdI8r zKb4aMg+ItCg28KFQk1QKvfq+HjsWulmoBKpigz1SzPCfv/0hHcpyL62kuRRIdRw sDU//xrYSfMw/EoptoXFEmOCC0= Received: (qmail 81652 invoked by alias); 14 Feb 2018 08:30:56 -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 81630 invoked by uid 89); 14 Feb 2018 08:30:55 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-10.6 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy=HX-Received:Wed, Hence, H*r:10.223.135 X-HELO: mail-wm0-f45.google.com Received: from mail-wm0-f45.google.com (HELO mail-wm0-f45.google.com) (74.125.82.45) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 14 Feb 2018 08:30:53 +0000 Received: by mail-wm0-f45.google.com with SMTP id v71so20522732wmv.2 for ; Wed, 14 Feb 2018 00:30:53 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to:cc; bh=KjP/IukFPzzfF0oU1apv+nYrap0LNYHDK8igFgrTems=; b=Hm7EZX92VIg9hQYLh6Hwkqjo8KsTVrPloM88dLZDkTEvPUXBGq9h16LZ4qDS5/yW0Y dK1N11zVaxQAnT9qLM66qliX0CoAqD7h0aDAXOj1OcXnRht9vpdLAU6i0SAygAWTHo3W JeLU4RHUy3ZIjoPBbGU7mjvglzsSz6a2qNfsrhA6eloc83GkJBoA5iCBtUZjQYp34Hb/ Hb4q1aLrroY7J4yH5Syd2mRV80liOs7s6mzsj+tH+bOgVrOo+1bNEFe9+FZ5zWvT6l4i CmWK7FIqfptRdDJ73ZIAh5JUhVak0CBgmg10eG8pedYdX0FDUI4X3bVcFSIvys8aAMUj Gk0g== X-Gm-Message-State: APf1xPCEWkobRnC4TmnJ4PPNyWV6Pa4sWJFKaI+I+B3aHK8Danm0mdMs 74+PWvPrY3S3/bloXIsGmCg57sC7XEEhaxUNOfj/VA== X-Received: by 10.28.170.71 with SMTP id t68mr3746898wme.31.1518597051711; Wed, 14 Feb 2018 00:30:51 -0800 (PST) MIME-Version: 1.0 Received: by 10.223.135.54 with HTTP; Wed, 14 Feb 2018 00:30:50 -0800 (PST) From: Sameera Deshpande Date: Wed, 14 Feb 2018 14:00:50 +0530 Message-ID: Subject: [Aarch64] Fix conditional branches with target far away. To: james.greenhalgh@arm.com, Richard Earnshaw , Richard Sandiford , marcus.shawcroft@arm.com Cc: gcc-patches@gcc.gnu.org Hi! Please find attached the patch to fix bug in branches with offsets over 1MiB. There has been an attempt to fix this issue in commit 050af05b9761f1979f11c151519e7244d5becd7c However, the far_branch attribute defined in above patch used insn_length - which computes incorrect offset. Hence, eliminated the attribute completely, and computed the offset from insn_addresses instead. Ok for trunk? gcc/Changelog 2018-02-13 Sameera Deshpande * config/aarch64/aarch64.md (far_branch): Remove attribute. Eliminate all the dependencies on the attribute from RTL patterns. -- - Thanks and regards, Sameera D. Index: gcc/config/aarch64/aarch64.md =================================================================== --- gcc/config/aarch64/aarch64.md (revision 257620) +++ gcc/config/aarch64/aarch64.md (working copy) @@ -244,13 +244,6 @@ (const_string "no") ] (const_string "yes"))) -;; Attribute that specifies whether we are dealing with a branch to a -;; label that is far away, i.e. further away than the maximum/minimum -;; representable in a signed 21-bits number. -;; 0 :=: no -;; 1 :=: yes -(define_attr "far_branch" "" (const_int 0)) - ;; Strictly for compatibility with AArch32 in pipeline models, since AArch64 has ;; no predicated insns. (define_attr "predicated" "yes,no" (const_string "no")) @@ -448,12 +441,7 @@ (if_then_else (and (ge (minus (match_dup 2) (pc)) (const_int -1048576)) (lt (minus (match_dup 2) (pc)) (const_int 1048572))) (const_int 4) - (const_int 8))) - (set (attr "far_branch") - (if_then_else (and (ge (minus (match_dup 2) (pc)) (const_int -1048576)) - (lt (minus (match_dup 2) (pc)) (const_int 1048572))) - (const_int 0) - (const_int 1)))] + (const_int 8)))] ) ;; For a 24-bit immediate CST we can optimize the compare for equality @@ -670,12 +658,7 @@ (if_then_else (and (ge (minus (match_dup 1) (pc)) (const_int -1048576)) (lt (minus (match_dup 1) (pc)) (const_int 1048572))) (const_int 4) - (const_int 8))) - (set (attr "far_branch") - (if_then_else (and (ge (minus (match_dup 2) (pc)) (const_int -1048576)) - (lt (minus (match_dup 2) (pc)) (const_int 1048572))) - (const_int 0) - (const_int 1)))] + (const_int 8)))] ) (define_insn "*tb1" @@ -692,7 +675,11 @@ { if (get_attr_length (insn) == 8) { - if (get_attr_far_branch (insn) == 1) + long long int offset; + offset = INSN_ADDRESSES (INSN_UID (XEXP (operands[2], 0))) + - INSN_ADDRESSES (INSN_UID (insn)); + + if (offset <= -1048576 || offset >= 1048572) return aarch64_gen_far_branch (operands, 2, "Ltb", "\\t%0, %1, "); else @@ -709,12 +696,7 @@ (if_then_else (and (ge (minus (match_dup 2) (pc)) (const_int -32768)) (lt (minus (match_dup 2) (pc)) (const_int 32764))) (const_int 4) - (const_int 8))) - (set (attr "far_branch") - (if_then_else (and (ge (minus (match_dup 2) (pc)) (const_int -1048576)) - (lt (minus (match_dup 2) (pc)) (const_int 1048572))) - (const_int 0) - (const_int 1)))] + (const_int 8)))] ) @@ -727,8 +709,12 @@ "" { if (get_attr_length (insn) == 8) - { - if (get_attr_far_branch (insn) == 1) + { + long long int offset; + offset = INSN_ADDRESSES (INSN_UID (XEXP (operands[1], 0))) + - INSN_ADDRESSES (INSN_UID (insn)); + + if (offset <= -1048576 || offset >= 1048572) return aarch64_gen_far_branch (operands, 1, "Ltb", "\\t%0, , "); else @@ -740,7 +726,7 @@ output_asm_insn (buf, operands); return "\t%l1"; } - } + } else return "\t%0, , %l1"; } @@ -749,12 +735,7 @@ (if_then_else (and (ge (minus (match_dup 1) (pc)) (const_int -32768)) (lt (minus (match_dup 1) (pc)) (const_int 32764))) (const_int 4) - (const_int 8))) - (set (attr "far_branch") - (if_then_else (and (ge (minus (match_dup 1) (pc)) (const_int -1048576)) - (lt (minus (match_dup 1) (pc)) (const_int 1048572))) - (const_int 0) - (const_int 1)))] + (const_int 8)))] ) ;; -------------------------------------------------------------------