From patchwork Thu Sep 18 14:00:33 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilya Enkovich X-Patchwork-Id: 390832 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.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 7FC341401AF for ; Fri, 19 Sep 2014 00:00:53 +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:cc:subject:message-id:references:mime-version :content-type:in-reply-to; q=dns; s=default; b=XtV6H17Tn+iJ7M+fm osXFkuIRiIP3Imj3yL9MSDfAai93mNYLIEvjGlGGzMm4wT96pQC4YS+nhUMHGhAD euOvmyqLg13OkhWC5zYNcAAotTkMce0eVLXYGOXqN3tmmF8WW1XWkePtxmpzN7bO zlcx4HMyiz+ad5RiPIKa/sND/c= 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:cc:subject:message-id:references:mime-version :content-type:in-reply-to; s=default; bh=zgXcb4FH3GJk8Q+i1DHnYme 6jAE=; b=sCDdmZ7idHET/L3qj533ixjzCiaGK0gMiOvpYKfe/lW7WZ9t1B7yqvc zR45w3YX9kL1gA6Fm8L1vzMP4h2fQQFobA9y1yRye6DbTxk+y3J3lTfjIEnrpcYQ MGWw+iEOSSTeYyoQ/d8LhuLNXO0cz4qAa+TCb/23u34k1ASgGx1c= Received: (qmail 29638 invoked by alias); 18 Sep 2014 14:00:46 -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 29621 invoked by uid 89); 18 Sep 2014 14:00:45 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.7 required=5.0 tests=AWL, BAYES_00, FREEMAIL_FROM, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 X-HELO: mail-pd0-f170.google.com Received: from mail-pd0-f170.google.com (HELO mail-pd0-f170.google.com) (209.85.192.170) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Thu, 18 Sep 2014 14:00:44 +0000 Received: by mail-pd0-f170.google.com with SMTP id fp1so1463958pdb.15 for ; Thu, 18 Sep 2014 07:00:42 -0700 (PDT) X-Received: by 10.68.69.33 with SMTP id b1mr5646851pbu.59.1411048840707; Thu, 18 Sep 2014 07:00:40 -0700 (PDT) Received: from msticlxl57.ims.intel.com (fmdmzpr03-ext.fm.intel.com. [192.55.54.38]) by mx.google.com with ESMTPSA id e11sm19893043pdm.47.2014.09.18.07.00.38 for (version=TLSv1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 18 Sep 2014 07:00:40 -0700 (PDT) Date: Thu, 18 Sep 2014 18:00:33 +0400 From: Ilya Enkovich To: Uros Bizjak Cc: "gcc-patches@gcc.gnu.org" , "Enkovich, Ilya" Subject: Re: [PATCH, i386, Pointer Bounds Checker 30/x] Size relocation Message-ID: <20140918140033.GB50194@msticlxl57.ims.intel.com> References: <20140917183534.GD3628@msticlxl57.ims.intel.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) X-IsSubscribed: yes On 17 Sep 20:51, Uros Bizjak wrote: > On Wed, Sep 17, 2014 at 8:35 PM, Ilya Enkovich wrote: > > On 16 Sep 12:22, Uros Bizjak wrote: > >> On Tue, Sep 16, 2014 at 11:37 AM, Ilya Enkovich wrote: > >> > 2014-09-16 13:08 GMT+04:00 Uros Bizjak : > >> >> > >> >> Can x86_64_immediate_operand predicate be used here? > >> > > >> > I think it cannot be used because of TLS symbols not counting as immediate. > >> > >> OK, please introduce a new predicate, similar to > >> x86_64_immediate_operand, perhaps x86_64_immediate_size_operand, so we > >> can add some comments there. This will also help to macroize the insn, > >> x86_64_immediate_operand has !TARGET_64BIT shortcut for this case. > >> > >> Uros. > > > > I don't see how new predicate would help to macroize insn. Single template may look as following patch. > > You put early return for !TARGET_64BITS. Please see > x86_64_immediate_operand predicate. > > So, > > /* Here comes comment. */ > (define_predicate "x86_64_immediate_size_operand" > (match_code "symbol_ref") > { > if (!TARGET_64BIT) > return true; > > /* Comment here explaining these conditions. */ > return (ix86_cmodel == CM_SMALL || ix86_cmodel == CM_KERNEL); > } > > And then in the pattern itself: > > if (x86_64_immediate_size_operand (operands[1], VOIDmode) > return "mov{l}\t{%1@SIZE, %k0|%k0, %1@SIZE}"; > else > return "movabs{q}\t{%1@SIZE, %0|%0, %1@SIZE}"; > > Uros. Here is a version with check in a form you suggest. Thanks, Ilya --- 2014-09-18 Ilya Enkovich * config/i386/i386.md (UNSPEC_SIZEOF): New. (move_size_reloc_): New. * config/i386/predicates.md (symbol_operand): New. (x86_64_immediate_size_operand): New. diff --git a/gcc/config/i386/i386.md b/gcc/config/i386/i386.md index 2c367b2..db22b06 100644 --- a/gcc/config/i386/i386.md +++ b/gcc/config/i386/i386.md @@ -79,6 +79,7 @@ UNSPEC_PLTOFF UNSPEC_MACHOPIC_OFFSET UNSPEC_PCREL + UNSPEC_SIZEOF ;; Prologue support UNSPEC_STACK_ALLOC @@ -18554,6 +18555,21 @@ "bndstx\t{%2, %3|%3, %2}" [(set_attr "type" "mpxst")]) +(define_insn "move_size_reloc_" + [(set (match_operand:SWI48 0 "register_operand" "=r") + (unspec:SWI48 + [(match_operand:SWI48 1 "symbol_operand")] + UNSPEC_SIZEOF))] + "TARGET_MPX" +{ + if (x86_64_immediate_size_operand (operands[1], VOIDmode)) + return "mov{l}\t{%1@SIZE, %k0|%k0, %1@SIZE}"; + else + return "movabs{q}\t{%1@SIZE, %0|%0, %1@SIZE}"; +} + [(set_attr "type" "imov") + (set_attr "mode" "")]) + (include "mmx.md") (include "sse.md") (include "sync.md") diff --git a/gcc/config/i386/predicates.md b/gcc/config/i386/predicates.md index cd542b7..da01c9a 100644 --- a/gcc/config/i386/predicates.md +++ b/gcc/config/i386/predicates.md @@ -124,6 +124,10 @@ (match_test "TARGET_64BIT") (match_test "REGNO (op) > BX_REG"))) +;; Return true if VALUE is symbol reference +(define_predicate "symbol_operand" + (match_code "symbol_ref")) + ;; Return true if VALUE can be stored in a sign extended immediate field. (define_predicate "x86_64_immediate_operand" (match_code "const_int,symbol_ref,label_ref,const") @@ -336,6 +340,19 @@ return false; }) +;; Return true if size of VALUE can be stored in a sign +;; extended immediate field. +(define_predicate "x86_64_immediate_size_operand" + (match_code "symbol_ref") +{ + if (!TARGET_64BIT) + return true; + + /* For 64 bit target we may assume size of object fits + immediate only when code model guarantees that. */ + return (ix86_cmodel == CM_SMALL || ix86_cmodel == CM_KERNEL); +}) + ;; Return true if OP is general operand representable on x86_64. (define_predicate "x86_64_general_operand" (if_then_else (match_test "TARGET_64BIT")