From patchwork Mon Oct 23 17:13:18 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Sandiford X-Patchwork-Id: 116777 Delivered-To: patch@linaro.org Received: by 10.140.22.164 with SMTP id 33csp4879305qgn; Mon, 23 Oct 2017 10:13:38 -0700 (PDT) X-Received: by 10.159.218.135 with SMTP id w7mr10989404plp.229.1508778818816; Mon, 23 Oct 2017 10:13:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1508778818; cv=none; d=google.com; s=arc-20160816; b=T4/fi+hP/0rgC12rMjdjvMYTwVbYO3pup1ROyIK95zUmzOeynnO+x0jFwR+kLcn/NA VROLfkKLOBmNyyB8zJhH1p28F2RrZpjSrGhumJmdXBmGG55wRgM/BUpeYsz6gZdeotZ7 jCncBFb8OxYfb+zQECfIPmHeyPVRLmqEMmW7/yMC63RwCS8ngfJRl9SCRhJTAfwr1sck cTyq1axsKRSgByJONeyIMOhVUzxKBrrduo9XJLBV7mmvp6HlTC+QuOLrAIObCdAdh/Hb 96ltaD5Giy51DRC/8MJbBW4GEcdjNzi5oDBng3BDEliJbjbIiunxF2hQjbgFO3ylkaDq 8Cgw== 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=5vMrjFwy6LwMaUC1B1KPHSb4Xr58kKRTjmtOactM8eo=; b=G5FDxzGjMyPNejY2zsIxRzTJAc8PMR8II0podNjxrd1D+HCYXRVGowLjY/SSNhDmQi PMbg7w6H+oTbYqwb1DW+j3d/vQknPrhbJ0L7rGD6bcdhSmegI0C3Qi59zp1QGSVBD59I g1Jor1dswjnSS2V6mnQ1BhKayejsyupcYv1PMcsd+Ahy1DjWqqe0GxJF1p/ay+Izi9ho FdkmvmCkDPFVNUmEAeTOOC6qNnm+BniAFv0NHiL0vWYYQmznTUbHMuSn8S8NoU+nt2HG vZfPn7scb57vYaTmt/ooWzn5Qc3Rmd7v1W63GIqW3sweDrc7PVJSX7ofDzzLABnBz9fy 4s6g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=GDfY//TE; spf=pass (google.com: domain of gcc-patches-return-464809-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-464809-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 69si4242151plc.414.2017.10.23.10.13.38 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 23 Oct 2017 10:13:38 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-return-464809-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=GDfY//TE; spf=pass (google.com: domain of gcc-patches-return-464809-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-464809-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=B7EUogUMgw3uytKVRFknJ6iKBImJ3 hJEgIGg+OdlwJPlkJZ+jkdFyOkzVB+EvcXxAvvwz1QEaGKyfsRvKRK+36EwZw2F8 UXdYoddHbk7quPwj6gXYct0doVgGMhpmuG9m92P6LZpnyaId6MB6uE9EKweRXuZ5 P7/49p2eB+BCH0= 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=zQUrhWWAvMtwGkGWytVbr0NtbvM=; b=GDf Y//TEvCPiWXzCvHlGiUWOG03FV/+7LlC8w0Ys3Yw9Fq01ZVqSAI7RD4Ce+4Rt36M eZY+vrOrBPsx1zC7EMKck7M5x+cCKyhrb4mfTe+DfXW/tqAGrDHpXwdMvcWH7yE9 nd3uRPvZeIKycjJnrpXWdE36jrjf527R4KKYOjMk= Received: (qmail 23368 invoked by alias); 23 Oct 2017 17:13:23 -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 23358 invoked by uid 89); 23 Oct 2017 17:13:23 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-11.7 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy= X-HELO: mail-wr0-f170.google.com Received: from mail-wr0-f170.google.com (HELO mail-wr0-f170.google.com) (209.85.128.170) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 23 Oct 2017 17:13:22 +0000 Received: by mail-wr0-f170.google.com with SMTP id 15so4305394wrb.5 for ; Mon, 23 Oct 2017 10:13:21 -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=5vMrjFwy6LwMaUC1B1KPHSb4Xr58kKRTjmtOactM8eo=; b=PhihTDisY2zqh2fgqiyc/64Otk/X0u22xj9GAHuUAVkZeK5Vagmwx9liDDHgLHvu9M IxLzl5U19ZM7q6CgpjK2+56qEoCxFC5qEj6ADodJqrlZso/1+wP+q0sPLdL3HujUyKSx arblt2JST4AaTBcyk37PXF4e5RShcELojAbFTKsUKv3FhgTpxoGGZiIuH4gbWqT9HHNA DrELkBOHiRqKrK5sa/UzJU85AOBQYUzZlv9ByiKU0M9o1UaX/GVm/xfJtTqRSlhVvbGV nnkRBDqjkzVD17k7s+zy0V4eGqgYJ/H+2+jcqVQrw9Y0Ee6M8JhXt3KXsVGQoivYCfCm UIWA== X-Gm-Message-State: AMCzsaUZ3GJ/U9TTykYlPL72gZ5w/WD5vwKKaI9Bs/VVyZbPMo6TRXOD MdZ7lyV4fcswZzigWhB7EpHtUTMtfGE= X-Google-Smtp-Source: ABhQp+Rv/aJSWJRqsxGOyax8LGArgBMLFYfuWsgmCKqGJ0GsOORqw2t+QSD1BirZl+kAl3s82QrE8A== X-Received: by 10.223.195.110 with SMTP id e43mr11449892wrg.219.1508778799941; Mon, 23 Oct 2017 10:13:19 -0700 (PDT) Received: from localhost ([2.26.27.199]) by smtp.gmail.com with ESMTPSA id v5sm5702022wrf.29.2017.10.23.10.13.19 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 23 Oct 2017 10:13:19 -0700 (PDT) From: Richard Sandiford To: gcc-patches@gcc.gnu.org Mail-Followup-To: gcc-patches@gcc.gnu.org, richard.sandiford@linaro.org Subject: [033/nnn] poly_int: pointer_may_wrap_p References: <871sltvm7r.fsf@linaro.org> Date: Mon, 23 Oct 2017 18:13:18 +0100 In-Reply-To: <871sltvm7r.fsf@linaro.org> (Richard Sandiford's message of "Mon, 23 Oct 2017 17:54:32 +0100") Message-ID: <87wp3loki9.fsf@linaro.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.2 (gnu/linux) MIME-Version: 1.0 This patch changes the bitpos argument to pointer_may_wrap_p from HOST_WIDE_INT to poly_int64. A later patch makes the callers track polynomial offsets. 2017-10-23 Richard Sandiford Alan Hayward David Sherwood gcc/ * fold-const.c (pointer_may_wrap_p): Take the offset as a HOST_WIDE_INT rather than a poly_int64. Index: gcc/fold-const.c =================================================================== --- gcc/fold-const.c 2017-10-23 17:17:01.429034898 +0100 +++ gcc/fold-const.c 2017-10-23 17:17:05.755450644 +0100 @@ -8421,48 +8421,50 @@ maybe_canonicalize_comparison (location_ expressions like &p->x which can not wrap. */ static bool -pointer_may_wrap_p (tree base, tree offset, HOST_WIDE_INT bitpos) +pointer_may_wrap_p (tree base, tree offset, poly_int64 bitpos) { if (!POINTER_TYPE_P (TREE_TYPE (base))) return true; - if (bitpos < 0) + if (may_lt (bitpos, 0)) return true; - wide_int wi_offset; + poly_wide_int wi_offset; int precision = TYPE_PRECISION (TREE_TYPE (base)); if (offset == NULL_TREE) wi_offset = wi::zero (precision); - else if (TREE_CODE (offset) != INTEGER_CST || TREE_OVERFLOW (offset)) + else if (!poly_int_tree_p (offset) || TREE_OVERFLOW (offset)) return true; else - wi_offset = wi::to_wide (offset); + wi_offset = wi::to_poly_wide (offset); bool overflow; - wide_int units = wi::shwi (bitpos / BITS_PER_UNIT, precision); - wide_int total = wi::add (wi_offset, units, UNSIGNED, &overflow); + poly_wide_int units = wi::shwi (bits_to_bytes_round_down (bitpos), + precision); + poly_wide_int total = wi::add (wi_offset, units, UNSIGNED, &overflow); if (overflow) return true; - if (!wi::fits_uhwi_p (total)) + poly_uint64 total_hwi, size; + if (!total.to_uhwi (&total_hwi) + || !poly_int_tree_p (TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (base))), + &size) + || known_zero (size)) return true; - HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (TREE_TYPE (base))); - if (size <= 0) - return true; + if (must_le (total_hwi, size)) + return false; /* We can do slightly better for SIZE if we have an ADDR_EXPR of an array. */ - if (TREE_CODE (base) == ADDR_EXPR) - { - HOST_WIDE_INT base_size; - - base_size = int_size_in_bytes (TREE_TYPE (TREE_OPERAND (base, 0))); - if (base_size > 0 && size < base_size) - size = base_size; - } + if (TREE_CODE (base) == ADDR_EXPR + && poly_int_tree_p (TYPE_SIZE_UNIT (TREE_TYPE (TREE_OPERAND (base, 0))), + &size) + && maybe_nonzero (size) + && must_le (total_hwi, size)) + return false; - return total.to_uhwi () > (unsigned HOST_WIDE_INT) size; + return true; } /* Return a positive integer when the symbol DECL is known to have