From patchwork Mon Oct 23 17:22:01 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Sandiford X-Patchwork-Id: 116796 Delivered-To: patch@linaro.org Received: by 10.140.22.164 with SMTP id 33csp4887397qgn; Mon, 23 Oct 2017 10:22:20 -0700 (PDT) X-Received: by 10.98.249.5 with SMTP id o5mr8980644pfh.54.1508779340846; Mon, 23 Oct 2017 10:22:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1508779340; cv=none; d=google.com; s=arc-20160816; b=dGP022J64PQGCRbVZBN5MdLyMLfc+j7qzv1+usTW7yJ8RsnUTgM4B00IffUTyszpft IY0ke5ykpWLL9wlUKbbIN1F6CdtuswWf7PalZ4NS1QyJTy6xxROOD5e9j0SjCwL5ZLBl WZoS1uXZuZ0wEphYk+I5t/vJ3drvssUXaHxxEXKzHqwJqRKVb5oaT3m93fU4i02ztFm1 Vz4NPkc7AvHWXctMwGMeCB4OrVqUggMJcYHf4ghChZGerU8+uqVThEajXFlWMRr/h/l9 MPUdwNfJnpEM/aEld1RyvIFKLsoOxwg9Yk57N06/alnhpaylg+RzkbNYdoc1GhuTRyvd TfgA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:user-agent:message-id:in-reply-to:date:references :subject:mail-followup-to:to:from:delivered-to:sender:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence :mailing-list:dkim-signature:domainkey-signature :arc-authentication-results; bh=N1D+egM4wyg7m6+vVrTywZgHPLr4jloFtornxkq7HhM=; b=pg68HWNbBHTbrkFA1lBmpnYDLGW1udq7fkfAdvYLUW0xHW18Jc85pTAOoRPt1T4TGT C5yIJVvCQdyrSG0GXk+x7oHR//wiwBI9taMl+vC9xSoxZar9wz4iOG0tEcWS+w/O/E1c sc0fm7E1sR+6Zu3CyvFqAEH/qDlxlX3mNtxZX+CTRbEooegEB6HfvUQ7R3yPuFX5bNGJ UMSFK1rSyHf03h/g7oGJbIiEdjGlN7+t27Euxeyvy2N8L1DASUCCqu1ut49vwSFZsDMh RuPwQIX4OZI26guE0Lb2zR3R8+g2CFZqoJNc4AJNAHbINt6S37fJbZK3bM0FfYddjqNF MxVA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=C5vAsJr1; spf=pass (google.com: domain of gcc-patches-return-464828-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-464828-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 v1si5176301pgq.533.2017.10.23.10.22.20 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 23 Oct 2017 10:22:20 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-return-464828-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=C5vAsJr1; spf=pass (google.com: domain of gcc-patches-return-464828-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-464828-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:from :to:subject:references:date:in-reply-to:message-id:mime-version :content-type; q=dns; s=default; b=XHiUzpv469o0fbBVEIcmxKYYQU1lq Jj23ElY7iyqvNlG/YcltzpV8GQo+q7btrxFPMpbZ/G4UmPA51btipeaI3edKbbka R6MVatqD13Tt9yHVARd7XwXtbjBuVoBP6sP/4P8wNzaxrDRt/6vzqbToKjuHXwne mVp0r53z4b2qkc= 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:from :to:subject:references:date:in-reply-to:message-id:mime-version :content-type; s=default; bh=pIRnGIopdS/9xWcSaE2RPNg03mg=; b=C5v AsJr1MO30JCtKX5KciI0KO/8opjxkqax0FFJKQchHn44kaYLiyBby3c0GhWxGw5F iopvPsO0ufRmJivnNOyPZGJNVXFTddpmhEYbkM9CFPRyf3hazW8kmLTzF1iswhSw BXD+tz82XkwSGzA3PWxbUB+IEpQ382TBMo/8NwSY= Received: (qmail 28909 invoked by alias); 23 Oct 2017 17:22:07 -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 28279 invoked by uid 89); 23 Oct 2017 17:22:07 -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, RCVD_IN_SORBS_SPAM, SPF_PASS autolearn=ham version=3.3.2 spammy= X-HELO: mail-wm0-f52.google.com Received: from mail-wm0-f52.google.com (HELO mail-wm0-f52.google.com) (74.125.82.52) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 23 Oct 2017 17:22:05 +0000 Received: by mail-wm0-f52.google.com with SMTP id p75so10945986wmg.3 for ; Mon, 23 Oct 2017 10:22:04 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:mail-followup-to:subject:references:date :in-reply-to:message-id:user-agent:mime-version; bh=N1D+egM4wyg7m6+vVrTywZgHPLr4jloFtornxkq7HhM=; b=Fx0vSCA/pUm2mc9dv2IvfIDm1iFOsTZ0SipOZOvV7A5xT0srbx9QfP2Nnxc1ydpDt5 Dx5U4rgW/zGsyS4NFgHQQBgM91TmFDTLyEl6IrSJQbS4k5EcFMkqwOU5qD6HdSOZdnmn UHRKOqS/94hBXo7cszP/Covef41H0GN5ss8w2Ddnx3CZFK7kE+QgKt9qqRsIBIrzCR2h 76D81X03n/JUwLDyR4nsAflS8Um0wybhDX9TzsETiX3mqk6naU1J9y0iKTGojSFvBxJH 2UWNhoMY665RR/UXck5wEmlaezNbGxvrfsumkdgrs2ZElb+U/h72pvgfFB7SYsjdmlpp DURw== X-Gm-Message-State: AMCzsaW9cr/1y6ETdqqk2StwAS+jKw66x3BMXlGPR9X+bNq9CVHLh0VC lS2EuDZ7V7BC41Mquo0UGk203/7YLTQ= X-Google-Smtp-Source: ABhQp+RaPbe3G9vNAbZaRAVAElhLoL7veUp4CfxX86kQM0B3l6rytP7/I+HBqKftkOWIxCLENHBQ9g== X-Received: by 10.28.146.18 with SMTP id u18mr6027296wmd.28.1508779322769; Mon, 23 Oct 2017 10:22:02 -0700 (PDT) Received: from localhost ([2.26.27.199]) by smtp.gmail.com with ESMTPSA id g16sm9618317wrd.72.2017.10.23.10.22.01 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 23 Oct 2017 10:22:01 -0700 (PDT) From: Richard Sandiford To: gcc-patches@gcc.gnu.org Mail-Followup-To: gcc-patches@gcc.gnu.org, richard.sandiford@linaro.org Subject: [052/nnn] poly_int: bit_field_size/offset References: <871sltvm7r.fsf@linaro.org> Date: Mon, 23 Oct 2017 18:22:01 +0100 In-Reply-To: <871sltvm7r.fsf@linaro.org> (Richard Sandiford's message of "Mon, 23 Oct 2017 17:54:32 +0100") Message-ID: <87mv4hlqyu.fsf@linaro.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.2 (gnu/linux) MIME-Version: 1.0 verify_expr ensured that the size and offset in gimple BIT_FIELD_REFs satisfied tree_fits_uhwi_p. This patch extends that so that they can be poly_uint64s, and adds helper routines for accessing them when the verify_expr requirements apply. 2017-10-23 Richard Sandiford Alan Hayward David Sherwood gcc/ * tree.h (bit_field_size, bit_field_offset): New functions. * hsa-gen.c (gen_hsa_addr): Use them. * tree-ssa-forwprop.c (simplify_bitfield_ref): Likewise. (simplify_vector_constructor): Likewise. * tree-ssa-sccvn.c (copy_reference_ops_from_ref): Likewise. * tree-cfg.c (verify_expr): Require the sizes and offsets of a BIT_FIELD_REF to be poly_uint64s rather than uhwis. * fold-const.c (fold_ternary_loc): Protect tree_to_uhwi with tree_fits_uhwi_p. Index: gcc/tree.h =================================================================== --- gcc/tree.h 2017-10-23 17:18:47.668056833 +0100 +++ gcc/tree.h 2017-10-23 17:20:50.884679814 +0100 @@ -4764,6 +4764,24 @@ poly_int_tree_p (const_tree t) return (TREE_CODE (t) == INTEGER_CST || POLY_INT_CST_P (t)); } +/* Return the bit size of BIT_FIELD_REF T, in cases where it is known + to be a poly_uint64. (This is always true at the gimple level.) */ + +inline poly_uint64 +bit_field_size (const_tree t) +{ + return tree_to_poly_uint64 (TREE_OPERAND (t, 1)); +} + +/* Return the starting bit offset of BIT_FIELD_REF T, in cases where it is + known to be a poly_uint64. (This is always true at the gimple level.) */ + +inline poly_uint64 +bit_field_offset (const_tree t) +{ + return tree_to_poly_uint64 (TREE_OPERAND (t, 2)); +} + extern tree strip_float_extensions (tree); extern int really_constant_p (const_tree); extern bool ptrdiff_tree_p (const_tree, poly_int64_pod *); Index: gcc/hsa-gen.c =================================================================== --- gcc/hsa-gen.c 2017-10-23 17:18:47.664057184 +0100 +++ gcc/hsa-gen.c 2017-10-23 17:20:50.882679875 +0100 @@ -1959,8 +1959,8 @@ gen_hsa_addr (tree ref, hsa_bb *hbb, HOS goto out; } else if (TREE_CODE (ref) == BIT_FIELD_REF - && ((tree_to_uhwi (TREE_OPERAND (ref, 1)) % BITS_PER_UNIT) != 0 - || (tree_to_uhwi (TREE_OPERAND (ref, 2)) % BITS_PER_UNIT) != 0)) + && (!multiple_p (bit_field_size (ref), BITS_PER_UNIT) + || !multiple_p (bit_field_offset (ref), BITS_PER_UNIT))) { HSA_SORRY_ATV (EXPR_LOCATION (origref), "support for HSA does not implement " Index: gcc/tree-ssa-forwprop.c =================================================================== --- gcc/tree-ssa-forwprop.c 2017-10-23 17:17:01.434034223 +0100 +++ gcc/tree-ssa-forwprop.c 2017-10-23 17:20:50.883679845 +0100 @@ -1727,7 +1727,7 @@ simplify_bitfield_ref (gimple_stmt_itera gimple *def_stmt; tree op, op0, op1, op2; tree elem_type; - unsigned idx, n, size; + unsigned idx, size; enum tree_code code; op = gimple_assign_rhs1 (stmt); @@ -1762,12 +1762,11 @@ simplify_bitfield_ref (gimple_stmt_itera return false; size = TREE_INT_CST_LOW (TYPE_SIZE (elem_type)); - n = TREE_INT_CST_LOW (op1) / size; - if (n != 1) + if (may_ne (bit_field_size (op), size)) return false; - idx = TREE_INT_CST_LOW (op2) / size; - if (code == VEC_PERM_EXPR) + if (code == VEC_PERM_EXPR + && constant_multiple_p (bit_field_offset (op), size, &idx)) { tree p, m, tem; unsigned nelts; @@ -2020,9 +2019,10 @@ simplify_vector_constructor (gimple_stmt return false; orig = ref; } - if (TREE_INT_CST_LOW (TREE_OPERAND (op1, 1)) != elem_size) + unsigned int elt; + if (may_ne (bit_field_size (op1), elem_size) + || !constant_multiple_p (bit_field_offset (op1), elem_size, &elt)) return false; - unsigned int elt = TREE_INT_CST_LOW (TREE_OPERAND (op1, 2)) / elem_size; if (elt != i) maybe_ident = false; sel.quick_push (elt); Index: gcc/tree-ssa-sccvn.c =================================================================== --- gcc/tree-ssa-sccvn.c 2017-10-23 17:17:01.435034088 +0100 +++ gcc/tree-ssa-sccvn.c 2017-10-23 17:20:50.884679814 +0100 @@ -766,12 +766,8 @@ copy_reference_ops_from_ref (tree ref, v /* Record bits, position and storage order. */ temp.op0 = TREE_OPERAND (ref, 1); temp.op1 = TREE_OPERAND (ref, 2); - if (tree_fits_shwi_p (TREE_OPERAND (ref, 2))) - { - HOST_WIDE_INT off = tree_to_shwi (TREE_OPERAND (ref, 2)); - if (off % BITS_PER_UNIT == 0) - temp.off = off / BITS_PER_UNIT; - } + if (!multiple_p (bit_field_offset (ref), BITS_PER_UNIT, &temp.off)) + temp.off = -1; temp.reverse = REF_REVERSE_STORAGE_ORDER (ref); break; case COMPONENT_REF: Index: gcc/tree-cfg.c =================================================================== --- gcc/tree-cfg.c 2017-10-23 17:11:40.247950952 +0100 +++ gcc/tree-cfg.c 2017-10-23 17:20:50.883679845 +0100 @@ -3054,8 +3054,9 @@ #define CHECK_OP(N, MSG) \ tree t0 = TREE_OPERAND (t, 0); tree t1 = TREE_OPERAND (t, 1); tree t2 = TREE_OPERAND (t, 2); - if (!tree_fits_uhwi_p (t1) - || !tree_fits_uhwi_p (t2) + poly_uint64 size, bitpos; + if (!poly_int_tree_p (t1, &size) + || !poly_int_tree_p (t2, &bitpos) || !types_compatible_p (bitsizetype, TREE_TYPE (t1)) || !types_compatible_p (bitsizetype, TREE_TYPE (t2))) { @@ -3063,8 +3064,7 @@ #define CHECK_OP(N, MSG) \ return t; } if (INTEGRAL_TYPE_P (TREE_TYPE (t)) - && (TYPE_PRECISION (TREE_TYPE (t)) - != tree_to_uhwi (t1))) + && may_ne (TYPE_PRECISION (TREE_TYPE (t)), size)) { error ("integral result type precision does not match " "field size of BIT_FIELD_REF"); @@ -3072,16 +3072,16 @@ #define CHECK_OP(N, MSG) \ } else if (!INTEGRAL_TYPE_P (TREE_TYPE (t)) && TYPE_MODE (TREE_TYPE (t)) != BLKmode - && (GET_MODE_BITSIZE (TYPE_MODE (TREE_TYPE (t))) - != tree_to_uhwi (t1))) + && may_ne (GET_MODE_BITSIZE (TYPE_MODE (TREE_TYPE (t))), + size)) { error ("mode size of non-integral result does not " "match field size of BIT_FIELD_REF"); return t; } if (!AGGREGATE_TYPE_P (TREE_TYPE (t0)) - && (tree_to_uhwi (t1) + tree_to_uhwi (t2) - > tree_to_uhwi (TYPE_SIZE (TREE_TYPE (t0))))) + && may_gt (size + bitpos, + tree_to_poly_uint64 (TYPE_SIZE (TREE_TYPE (t0))))) { error ("position plus size exceeds size of referenced object in " "BIT_FIELD_REF"); Index: gcc/fold-const.c =================================================================== --- gcc/fold-const.c 2017-10-23 17:18:47.662057360 +0100 +++ gcc/fold-const.c 2017-10-23 17:20:50.881679906 +0100 @@ -11728,7 +11728,9 @@ fold_ternary_loc (location_t loc, enum t fold (nearly) all BIT_FIELD_REFs. */ if (CONSTANT_CLASS_P (arg0) && can_native_interpret_type_p (type) - && BITS_PER_UNIT == 8) + && BITS_PER_UNIT == 8 + && tree_fits_uhwi_p (op1) + && tree_fits_uhwi_p (op2)) { unsigned HOST_WIDE_INT bitpos = tree_to_uhwi (op2); unsigned HOST_WIDE_INT bitsize = tree_to_uhwi (op1);