From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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-Archive: List-Post: List-Help: Sender: gcc-patches-owner@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 17:13:00 -0000 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 Content-Type: text/plain X-SW-Source: 2017-10/txt/msg01534.txt.bz2 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