From patchwork Fri Sep 6 07:13:29 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alan Modra X-Patchwork-Id: 273098 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "www.sourceware.org", Issuer "StartCom Class 1 Primary Intermediate Server CA" (not verified)) by ozlabs.org (Postfix) with ESMTPS id E8F072C00C1 for ; Fri, 6 Sep 2013 17:13:47 +1000 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:subject:message-id:mime-version:content-type; q=dns; s= default; b=WzaAeah+CydadW/aU+SBwHiDWn6/EMeMzroSOuuLkmNyeJqfrmU/n 4/f4KnWvam373zDND8lBzz4dmtjhRQ2OvuMbwpjTQ1ZN9kY11cGELALsLnS58T/O vORcP5Q/xBgZWup31uVAhNxoQfAtMew+WF2YOyBVAzDc9Ys0LxctEU= 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:date :from:to:subject:message-id:mime-version:content-type; s= default; bh=sw5KvJO4srGaWsv604z86wvXiIA=; b=R2vCzf9SkegkkNC3pIyO hFMjRrutIWCGqKA3N9B2zd5OnRaIOqzVasI/qT4gjQlPjoXt83Q5lu6fWjLhyd93 9CIf18CoAtjDnvh3H7GtWvhLk3pMwKMK/RDT/Y1wzVLtm/Keo7T+5M0iFJ3XUBM/ kTUniUeNPvHXLuNgDHoTqJ0= Received: (qmail 545 invoked by alias); 6 Sep 2013 07:13:39 -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 532 invoked by uid 89); 6 Sep 2013 07:13:38 -0000 Received: from mail-pd0-f171.google.com (HELO mail-pd0-f171.google.com) (209.85.192.171) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Fri, 06 Sep 2013 07:13:38 +0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.5 required=5.0 tests=ALL_TRUSTED, AWL, BAYES_00, FREEMAIL_FROM autolearn=ham version=3.3.2 X-HELO: mail-pd0-f171.google.com Received: by mail-pd0-f171.google.com with SMTP id g10so2845534pdj.2 for ; Fri, 06 Sep 2013 00:13:35 -0700 (PDT) X-Received: by 10.66.162.195 with SMTP id yc3mr2278124pab.64.1378451615673; Fri, 06 Sep 2013 00:13:35 -0700 (PDT) Received: from bubble.grove.modra.org ([101.166.26.37]) by mx.google.com with ESMTPSA id im4sm1840476pbc.34.1969.12.31.16.00.00 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 06 Sep 2013 00:13:34 -0700 (PDT) Received: by bubble.grove.modra.org (Postfix, from userid 1000) id CC7F1EA0077; Fri, 6 Sep 2013 16:43:29 +0930 (CST) Date: Fri, 6 Sep 2013 16:43:29 +0930 From: Alan Modra To: David Edelsohn , gcc-patches@gcc.gnu.org Subject: [RS6000] powerpc64 -mcmodel=medium large symbol offsets Message-ID: <20130906071329.GB3430@bubble.grove.modra.org> Mail-Followup-To: David Edelsohn , gcc-patches@gcc.gnu.org MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) X-IsSubscribed: yes The following testcase taken from the linux kernel is miscompiled on powerpc64-linux. /* -m64 -mcmodel=medium -O -S -fno-section-anchors */ static int x; unsigned long foo (void) { return ((unsigned long) &x) - 0xc000000000000000; } generates addis 3,2,x+4611686018427387904@toc@ha addi 3,3,x+4611686018427387904@toc@l blr losing the top 32 bits of the offset. Sadly, the assembler and linker do not complain, which is a hole in the ABI. (@ha and _HA relocs as per the ABI won't complain about overflow since they might be used in a @highesta, @highera sequence loading a 64-bit value.) This patch stops combine merging large offsets into a symbol addend by copying code from reg_or_add_cint_operand to a new predicate, add_cint_operand, and using that to restrict the range of offsets. Bootstrapped and regression tested powerpc64-linux. OK to apply? * config/rs6000/predicates.md (add_cint_operand): New. * config/rs6000/rs6000.md (largetoc_high_plus): Restrict offset using add_cint_operand. (largetoc_high_plus_aix): Likewise. Index: gcc/config/rs6000/predicates.md =================================================================== --- gcc/config/rs6000/predicates.md (revision 202264) +++ gcc/config/rs6000/predicates.md (working copy) @@ -376,6 +376,12 @@ (ior (match_code "const_int") (match_operand 0 "gpc_reg_operand"))) +;; Return 1 if op is a constant integer valid for addition with addis, addi. +(define_predicate "add_cint_operand" + (and (match_code "const_int") + (match_test "(unsigned HOST_WIDE_INT) (INTVAL (op) + 0x80008000) + < (unsigned HOST_WIDE_INT) 0x100000000ll"))) + ;; Return 1 if op is a constant integer valid for addition ;; or non-special register. (define_predicate "reg_or_add_cint_operand" Index: gcc/config/rs6000/rs6000.md =================================================================== --- gcc/config/rs6000/rs6000.md (revision 202264) +++ gcc/config/rs6000/rs6000.md (working copy) @@ -12207,7 +12209,7 @@ (unspec [(match_operand:DI 1 "" "") (match_operand:DI 2 "gpc_reg_operand" "b")] UNSPEC_TOCREL) - (match_operand 3 "const_int_operand" "n"))))] + (match_operand 3 "add_cint_operand" "n"))))] "TARGET_ELF && TARGET_CMODEL != CMODEL_SMALL" "addis %0,%2,%1+%3@toc@ha") @@ -12218,7 +12220,7 @@ (unspec [(match_operand:P 1 "" "") (match_operand:P 2 "gpc_reg_operand" "b")] UNSPEC_TOCREL) - (match_operand 3 "const_int_operand" "n"))))] + (match_operand 3 "add_cint_operand" "n"))))] "TARGET_XCOFF && TARGET_CMODEL != CMODEL_SMALL" "addis %0,%1+%3@u(%2)")