From patchwork Thu Oct 31 16:08:16 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Richard Earnshaw \(lists\)" X-Patchwork-Id: 178206 Delivered-To: patch@linaro.org Received: by 2002:a92:409a:0:0:0:0:0 with SMTP id d26csp3052422ill; Thu, 31 Oct 2019 09:08:34 -0700 (PDT) X-Google-Smtp-Source: APXvYqzWGCQlM9HpCGlYOHhfL57XWUGR356uQIGwLXKbNYRzuj7X6yX4iytDtD0/Tm0V5+JC0K45 X-Received: by 2002:a50:f096:: with SMTP id v22mr7114824edl.149.1572538114435; Thu, 31 Oct 2019 09:08:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1572538114; cv=none; d=google.com; s=arc-20160816; b=ltGXCEToJ1cTilc1V471aSjq49XmmFcl/hXR5A6/TtgeaYxay1I2WMaO/gOM9a3QCV W5SZmiLJxOMcKLQgspkrwgkJUviSwd72DiD6j/UGKfHQmIivKvypKePpHuYsPFg3lhbY 5vO48ioaa6eLMduJcVcsrl5Stb3ke+PFFGbkwqGeI1czgoIdAP7yBKDMUuWYCwBIz6Wy y6dUojIXYV3eKPTyTgaZmqFUT3POLfv6iz8td9MndD+IoMxKLbTeVkfSyEosI3bWM95p qnzO3ExuBnw62A67aoGOlIb4KqiMrJ6vfBrO0WbZXmGX2jYHLtAdd6DFs4uYg0AHbjVa /FKQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:user-agent:date:message-id:subject:from:to :delivered-to:sender:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:mailing-list:dkim-signature :domainkey-signature; bh=bKCXk7f2ec6oqzyDrOGPobKPSG83GSJ/XettmMihip4=; b=chfXeSdQCz7+v7z/W6h/mHxK7EPjEuQCpdUbkC6lK8aNdPT8xSPXkZjL3jnDRJosKx YMmwbYnGnePXQf8ULeIosOwakoG1PdCaNi+mro3ylWQB4wNAGAqv4x90E2ovlqR02hx1 HwNo3vg4Zk8L4yR90TVd++zeUN4MdwKBg6lI+snNebh+LCjybrBAxxTyy6mT82K7B72k zUhvZe/4fjkJi8aSyoBNCtNUxUQo7bmEfXhDdznfQ9DlfXo0hIFZ5xz7Wqi0De4fBCOm cDHHBdUoV9cFSIfcbgaTlnmn3Q420rRmTL30PKjklwOs7DL+KIL5XvDcf+M8RY47g9Ta FTig== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=pwWYYWI2; spf=pass (google.com: domain of gcc-patches-return-512164-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom="gcc-patches-return-512164-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 f29si4114159ejj.110.2019.10.31.09.08.33 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 31 Oct 2019 09:08:34 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-return-512164-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=pwWYYWI2; spf=pass (google.com: domain of gcc-patches-return-512164-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom="gcc-patches-return-512164-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:to :from:subject:message-id:date:mime-version:content-type; q=dns; s=default; b=cmd4FMxcuF0DN+ya8mlN1AcXjqZh6eRNqFL6Ev09GaP+OEDlBu +Zplgwfg8qDaeSYAmAbUimnA1ma9/3E2AzSp1KzzrXLzNTPBLYBOdpndJDxZKLCb bQGYv+RuX2wHICzYn+3lhbJktafm4pWrFmqDTTiv1vGXnoK1K7KeB1YC0= 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:to :from:subject:message-id:date:mime-version:content-type; s= default; bh=BeCEgic+GQt0ayBBGsSE2meq/Fk=; b=pwWYYWI2UibiWv6/Rg45 hMYtTmU44jCoo2d0AdQTmWHYB/YpJ83kmLgZJBR2aScMpixG3La9SONwmLbUNPhj /wbNBoWJ4kxLcP6rY2pjZklFwS4fSt/yjmk3dXRZLFWOOVBN55XSoAmz48CzHSP3 fxHRdtcImBE0X//UvT6vhn0= Received: (qmail 101154 invoked by alias); 31 Oct 2019 16:08:21 -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 101146 invoked by uid 89); 31 Oct 2019 16:08:20 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-19.0 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_NUMSUBJECT, KAM_SHORT, SPF_PASS autolearn=ham version=3.3.1 spammy=machine_mode, 2076, intval, CONST_INT X-HELO: foss.arm.com Received: from foss.arm.com (HELO foss.arm.com) (217.140.110.172) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 31 Oct 2019 16:08:19 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id A32F01F1; Thu, 31 Oct 2019 09:08:17 -0700 (PDT) Received: from e120077-lin.cambridge.arm.com (e120077-lin.cambridge.arm.com [10.2.206.225]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 3B76E3F71E; Thu, 31 Oct 2019 09:08:17 -0700 (PDT) To: "gcc-patches@gcc.gnu.org" From: "Richard Earnshaw (lists)" Subject: [arm] Avoid using negative offsets for 'immediate' addresses when compiling for Thumb2 Message-ID: <824f3c08-c718-c2e0-7216-d4df8d871d11@arm.com> Date: Thu, 31 Oct 2019 16:08:16 +0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.8.0 MIME-Version: 1.0 Thumb2 code now uses the Arm implementation of legitimize_address. That code has a case to handle addresses that are absolute CONST_INT values, which is a common use case in deeply embedded targets (eg: void *p = (void*)0x12345678). Since thumb has very limited negative offsets from a constant, we want to avoid forming a CSE base that will then be used with a negative value. This was reported upstream originally in https://gcc.gnu.org/ml/gcc-help/2019-10/msg00122.html For example, void test1(void) { volatile uint32_t * const p = (uint32_t *) 0x43fe1800; p[3] = 1; p[4] = 2; p[1] = 3; p[7] = 4; p[0] = 6; } With the new code, instead of ldr r3, .L2 subw r2, r3, #2035 movs r1, #1 str r1, [r2] subw r2, r3, #2031 movs r1, #2 str r1, [r2] subw r2, r3, #2043 movs r1, #3 str r1, [r2] subw r2, r3, #2019 movs r1, #4 subw r3, r3, #2047 str r1, [r2] movs r2, #6 str r2, [r3] bx lr We now get ldr r3, .L2 movs r2, #1 str r2, [r3, #2060] movs r2, #2 str r2, [r3, #2064] movs r2, #3 str r2, [r3, #2052] movs r2, #4 str r2, [r3, #2076] movs r2, #6 str r2, [r3, #2048] bx lr * config/arm/arm.c (arm_legitimize_address): Don't form negative offsets from a CONST_INT address when TARGET_THUMB2. Committed. diff --git a/gcc/config/arm/arm.c b/gcc/config/arm/arm.c index 5c2c48f4253..833381903d2 100644 --- a/gcc/config/arm/arm.c +++ b/gcc/config/arm/arm.c @@ -9038,17 +9038,20 @@ arm_legitimize_address (rtx x, rtx orig_x, machine_mode mode) HOST_WIDE_INT mask, base, index; rtx base_reg; - /* ldr and ldrb can use a 12-bit index, ldrsb and the rest can only - use a 8-bit index. So let's use a 12-bit index for SImode only and - hope that arm_gen_constant will enable ldrb to use more bits. */ + /* LDR and LDRB can use a 12-bit index, ldrsb and the rest can + only use a 8-bit index. So let's use a 12-bit index for + SImode only and hope that arm_gen_constant will enable LDRB + to use more bits. */ bits = (mode == SImode) ? 12 : 8; mask = (1 << bits) - 1; base = INTVAL (x) & ~mask; index = INTVAL (x) & mask; - if (bit_count (base & 0xffffffff) > (32 - bits)/2) - { - /* It'll most probably be more efficient to generate the base - with more bits set and use a negative index instead. */ + if (TARGET_ARM && bit_count (base & 0xffffffff) > (32 - bits)/2) + { + /* It'll most probably be more efficient to generate the + base with more bits set and use a negative index instead. + Don't do this for Thumb as negative offsets are much more + limited. */ base |= mask; index -= mask; }