From patchwork Thu Oct 2 08:23:30 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilya Enkovich X-Patchwork-Id: 395850 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 9ED9414010F for ; Thu, 2 Oct 2014 18:23: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=s0tv1Onyq85ZHQ5xZ p4bVu9d7OJ7FHsALTzVYQ4fvZM41o/fdYfbzKtnm94asrLbEsFm5P3sFEDfj/C2L oeZoMsqkVufbmyFwxomGZ0afzdMg/PMLv9ohdyFbrZklcmNOIF9MZNnzdHZ71L/U sIC4PVYJqRUwqXBmIms/FCFmuY= 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=Apd4CHdHXhTpbhG2SDeX/4P dY3g=; b=gILc8DEH4HofHDDFoOcWe8fVvvWKv+4smhuERcIklftE2uzAPBSyCvU AuPaAfJlHPP9nt75GGRBCOHZIbLsdKXEJZzfWpMGgvvtGtbO07C3H9NQyF1EFqiJ laIWyl5JhnCXq0LimnUH3q7+5aOxsT+1HQ/OllUbAD2LbAT81pgw= Received: (qmail 6498 invoked by alias); 2 Oct 2014 08:23: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 6463 invoked by uid 89); 2 Oct 2014 08:23:41 -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-pa0-f44.google.com Received: from mail-pa0-f44.google.com (HELO mail-pa0-f44.google.com) (209.85.220.44) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Thu, 02 Oct 2014 08:23:39 +0000 Received: by mail-pa0-f44.google.com with SMTP id et14so1848539pad.17 for ; Thu, 02 Oct 2014 01:23:37 -0700 (PDT) X-Received: by 10.68.179.66 with SMTP id de2mr85074067pbc.31.1412238217092; Thu, 02 Oct 2014 01:23:37 -0700 (PDT) Received: from msticlxl57.ims.intel.com (fmdmzpr03-ext.fm.intel.com. [192.55.54.38]) by mx.google.com with ESMTPSA id f2sm2824539pdo.29.2014.10.02.01.23.35 for (version=TLSv1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 02 Oct 2014 01:23:36 -0700 (PDT) Date: Thu, 2 Oct 2014 12:23:30 +0400 From: Ilya Enkovich To: Uros Bizjak Cc: "gcc-patches@gcc.gnu.org" Subject: Re: [PATCH, i386, Pointer Bounds Checker 30/x] Size relocation Message-ID: <20141002082330.GB28697@msticlxl57.ims.intel.com> References: <20140917183534.GD3628@msticlxl57.ims.intel.com> <20140918140033.GB50194@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 01 Oct 19:57, Uros Bizjak wrote: > On Wed, Oct 1, 2014 at 7:02 PM, Ilya Enkovich wrote: > > 2014-10-01 19:17 GMT+04:00 Uros Bizjak : > >> On Wed, Oct 1, 2014 at 4:10 PM, Ilya Enkovich wrote: > >> > >>>> +;; 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); > >>>> +}) > >>>> + > >>> > >>> This predicate causes bootstrap error: > >>> predicates.md:362:38: error: unused parameter 'op' [-Werror=unused-parameter] > >> > >> Huh? How is this predicate different from e.g. > >> > >> (define_predicate "compare_operator" > >> (match_code "compare")) > >> > >> ? > >> > >> Can you please show generated code from gcc/insn-preds.c? > >> > >> Uros. > > > > It is different because it has a code block which is used to generate > > additional function. Here is what generated for the predicate: > > > > static inline int > > x86_64_immediate_size_operand_1 (rtx op, enum machine_mode mode > > ATTRIBUTE_UNUSED) > > { > > 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); > > } > > > > int > > x86_64_immediate_size_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED) > > { > > return ((GET_CODE (op) == SYMBOL_REF) && ( > > (x86_64_immediate_size_operand_1 (op, mode)))) && ( > > (mode == VOIDmode || GET_MODE (op) == mode)); > > } > > Well, > > --cut here-- > (define_predicate "x86_64_immediate_size_operand" > (and (match_code "symbol_ref") > (ior (not (match_test "TARGET_64BIT")) > (and (match_test ("ix86_cmodel == CM_SMALL")) > (match_test ("ix86_cmodel == CM_KERNEL")))))) > --cut here-- > > Uros. Thanks for a workaround. Below is a modified version passing bootstrap. Ilya --- 2014-10-01 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 65990b1..1901023 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 @@ -18789,6 +18790,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 fea7754..1875339 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,14 @@ return false; }) +;; Return true if size of VALUE can be stored in a sign +;; extended immediate field. +(define_predicate "x86_64_immediate_size_operand" + (and (match_code "symbol_ref") + (ior (not (match_test "TARGET_64BIT")) + (ior (match_test ("ix86_cmodel == CM_SMALL")) + (match_test ("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")