From patchwork Mon Oct 23 17:05:48 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Sandiford X-Patchwork-Id: 116758 Delivered-To: patch@linaro.org Received: by 10.140.22.164 with SMTP id 33csp4871640qgn; Mon, 23 Oct 2017 10:06:08 -0700 (PDT) X-Received: by 10.98.204.157 with SMTP id j29mr13870572pfk.236.1508778367944; Mon, 23 Oct 2017 10:06:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1508778367; cv=none; d=google.com; s=arc-20160816; b=xsIlV7Nhhjdy9iAQ3coQFtgFhyccsExK2yzoIDTRkJD8v3Fd336DNk3Z3riIRPQkzd KNbENG2e+x5OhzCRj4r4RmumNWumEV+qNclbgAKWsMnvROjZEv73VREcCDKKVNVW+dLW gj9NPYbLeM9FO2JUFTqejBmI0iJlMZBeWEujtg3TtZJQRDlST5Qcdnmn+coDILrEr1KM mWIKlzAD5jqBY33mZO5Y40LbtS+GXXiPjBfqjCGaW37gQLyBp7qfn1bAZz4HJO4orJqF S/B9DRTNFxHhu1NDNx8bRuxYHVHvcfafUENy7YR7hZSsqFZJ5cQJNFcsCAI0a10xu/no dimg== 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=5p3ZoRIojjEJmUCCKKegI/4G42iKXPa89G92rn5Uveo=; b=ecpKcK9OJtMvgEFniVjPB405eQqBzuqDnkEGQeFtoiioHY1ZbrO/+3tQkxYyJt/SZi QcmRn6hTTzI2SFDKUDXiEOt4B+s8pNH+sINWGWMNx2+a2aLbzITY8KZ5XVqBzKkJouNs DnMyDZwvrWw1tNVMwOfuMOjiQah1iYqdI8WCo/HF+jrxuBvcHK//k8fuXysce+dCwrxh 1TV2RKd9Um42MUC7pRkBpAxwvopUVP63Z7ZZjRjmAy7o39mHhx98bwOFnp/g7/7baq42 MwhCVQOrUcOhvEvRtUBoIe4t67qK10N7T44wDXF4I9ZT+Di+4tHtdx9HcCda3U1Y/uoP Fp4A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=MxYlUmPq; spf=pass (google.com: domain of gcc-patches-return-464790-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-464790-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 i128si5653748pfg.17.2017.10.23.10.06.07 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 23 Oct 2017 10:06:07 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-return-464790-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=MxYlUmPq; spf=pass (google.com: domain of gcc-patches-return-464790-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-464790-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=l0J4NyWxreMqIybzFSFinjXcP0yuB N/Iw9B1lTnOeRlUYWeaAJY6u4GVmNnzV5u27GQ938XAreTLU4gLG7x9ZNQONLLGy F/VyZs8+9LJPuzPD9iSxjBNKE20Vfpblrd97K85DNNFFvdxbeAdMo4fZj7uPFf84 +SJySJXj5RyLF0= 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=07f1NSbQQEBXj4qhtTxKnMuk4R4=; b=MxY lUmPqVY8P0ahqetWAwyPvMAMHTo5ysr0LiJ+2/ZW7TVwhvOoY8Xk+ozOjiQ8O6Mn 07/9bEj5c7GX0PBYoUBmVz3gdzKgNo6pdjhcGHBFsiqgZrBYccETbUyiGF4gYCVM dORUyvPxzKDjcIDCH1NFSnN7Jei2wUoV1Xz+i0qU= Received: (qmail 116916 invoked by alias); 23 Oct 2017 17:05:54 -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 116907 invoked by uid 89); 23 Oct 2017 17:05:54 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-11.2 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, RCVD_IN_SORBS_SPAM, SPF_PASS autolearn=ham version=3.3.2 spammy=014 X-HELO: mail-wr0-f178.google.com Received: from mail-wr0-f178.google.com (HELO mail-wr0-f178.google.com) (209.85.128.178) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 23 Oct 2017 17:05:52 +0000 Received: by mail-wr0-f178.google.com with SMTP id j15so5971746wre.8 for ; Mon, 23 Oct 2017 10:05:52 -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=5p3ZoRIojjEJmUCCKKegI/4G42iKXPa89G92rn5Uveo=; b=AxZEN81rru/kWt7OBZfsx1scjZt+ET4ZbhSUJEuqe2QC4ELW0STN4F9vn2NCQCPCWg q3q/9/rxLW1yjZtRYltpcaM2QiPmh0JtdmrXe4hojWhOhBOgdpaEzgLZzrI1L/XoxZPK XCkGEQBhYzoimvRAfg0Fni60REbbg4l3Nms8hJvYdqbaMLbu2ZOqz7KxO5G5SgUFvLbd aP31JiH+EDIfocLKNPzC1/eXl8rBwtGX28CNlgcQlTcxgms4fLWgJm000qJ12QYbZ/7X i95/cCGcRUdxAHXMaCeadO41SKthrlOZxGswGCx+mgfJTIuzG+lNZGAljgs1InZJrubK dOuw== X-Gm-Message-State: AMCzsaXDQyOp/VibkhLeRJTHQ15TmB+SKzxq3LzTWyIpn14GRa98gTso iQqP3MEmDlWn/Yxey6BJP+Lho61k+YA= X-Google-Smtp-Source: ABhQp+T0vRT2CvKNW3jEsbKina8hgX4TxSdE8ksC2snZ3xWxvcd0AYAR4csJb0OJ0GUHTmYZ4AXCFw== X-Received: by 10.223.160.77 with SMTP id l13mr8188562wrl.43.1508778350097; Mon, 23 Oct 2017 10:05:50 -0700 (PDT) Received: from localhost ([2.26.27.199]) by smtp.gmail.com with ESMTPSA id 92sm5580580wrd.15.2017.10.23.10.05.48 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 23 Oct 2017 10:05:49 -0700 (PDT) From: Richard Sandiford To: gcc-patches@gcc.gnu.org Mail-Followup-To: gcc-patches@gcc.gnu.org, richard.sandiford@linaro.org Subject: [014/nnn] poly_int: indirect_refs_may_alias_p References: <871sltvm7r.fsf@linaro.org> Date: Mon, 23 Oct 2017 18:05:48 +0100 In-Reply-To: <871sltvm7r.fsf@linaro.org> (Richard Sandiford's message of "Mon, 23 Oct 2017 17:54:32 +0100") Message-ID: <877evlssk3.fsf@linaro.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.2 (gnu/linux) MIME-Version: 1.0 This patch makes indirect_refs_may_alias_p use ranges_may_overlap_p rather than ranges_overlap_p. Unlike the former, the latter can handle negative offsets, so the fix for PR44852 should no longer be necessary. It can also handle offset_int, so avoids unchecked truncations to HOST_WIDE_INT. 2017-10-23 Richard Sandiford Alan Hayward David Sherwood gcc/ * tree-ssa-alias.c (indirect_ref_may_alias_decl_p) (indirect_refs_may_alias_p): Use ranges_may_overlap_p instead of ranges_overlap_p. Index: gcc/tree-ssa-alias.c =================================================================== --- gcc/tree-ssa-alias.c 2017-10-23 17:01:49.579064221 +0100 +++ gcc/tree-ssa-alias.c 2017-10-23 17:01:51.044974644 +0100 @@ -1135,23 +1135,13 @@ indirect_ref_may_alias_decl_p (tree ref1 { tree ptr1; tree ptrtype1, dbase2; - HOST_WIDE_INT offset1p = offset1, offset2p = offset2; - HOST_WIDE_INT doffset1, doffset2; gcc_checking_assert ((TREE_CODE (base1) == MEM_REF || TREE_CODE (base1) == TARGET_MEM_REF) && DECL_P (base2)); ptr1 = TREE_OPERAND (base1, 0); - - /* The offset embedded in MEM_REFs can be negative. Bias them - so that the resulting offset adjustment is positive. */ - offset_int moff = mem_ref_offset (base1); - moff <<= LOG2_BITS_PER_UNIT; - if (wi::neg_p (moff)) - offset2p += (-moff).to_short_addr (); - else - offset1p += moff.to_short_addr (); + offset_int moff = mem_ref_offset (base1) << LOG2_BITS_PER_UNIT; /* If only one reference is based on a variable, they cannot alias if the pointer access is beyond the extent of the variable access. @@ -1160,7 +1150,7 @@ indirect_ref_may_alias_decl_p (tree ref1 ??? IVOPTs creates bases that do not honor this restriction, so do not apply this optimization for TARGET_MEM_REFs. */ if (TREE_CODE (base1) != TARGET_MEM_REF - && !ranges_overlap_p (MAX (0, offset1p), -1, offset2p, max_size2)) + && !ranges_may_overlap_p (offset1 + moff, -1, offset2, max_size2)) return false; /* They also cannot alias if the pointer may not point to the decl. */ if (!ptr_deref_may_alias_decl_p (ptr1, base2)) @@ -1213,18 +1203,11 @@ indirect_ref_may_alias_decl_p (tree ref1 dbase2 = ref2; while (handled_component_p (dbase2)) dbase2 = TREE_OPERAND (dbase2, 0); - doffset1 = offset1; - doffset2 = offset2; + HOST_WIDE_INT doffset1 = offset1; + offset_int doffset2 = offset2; if (TREE_CODE (dbase2) == MEM_REF || TREE_CODE (dbase2) == TARGET_MEM_REF) - { - offset_int moff = mem_ref_offset (dbase2); - moff <<= LOG2_BITS_PER_UNIT; - if (wi::neg_p (moff)) - doffset1 -= (-moff).to_short_addr (); - else - doffset2 -= moff.to_short_addr (); - } + doffset2 -= mem_ref_offset (dbase2) << LOG2_BITS_PER_UNIT; /* If either reference is view-converted, give up now. */ if (same_type_for_tbaa (TREE_TYPE (base1), TREE_TYPE (ptrtype1)) != 1 @@ -1241,7 +1224,7 @@ indirect_ref_may_alias_decl_p (tree ref1 if ((TREE_CODE (base1) != TARGET_MEM_REF || (!TMR_INDEX (base1) && !TMR_INDEX2 (base1))) && same_type_for_tbaa (TREE_TYPE (base1), TREE_TYPE (dbase2)) == 1) - return ranges_overlap_p (doffset1, max_size1, doffset2, max_size2); + return ranges_may_overlap_p (doffset1, max_size1, doffset2, max_size2); if (ref1 && ref2 && nonoverlapping_component_refs_p (ref1, ref2)) @@ -1313,22 +1296,10 @@ indirect_refs_may_alias_p (tree ref1 ATT && operand_equal_p (TMR_INDEX2 (base1), TMR_INDEX2 (base2), 0)))))) { - offset_int moff; - /* The offset embedded in MEM_REFs can be negative. Bias them - so that the resulting offset adjustment is positive. */ - moff = mem_ref_offset (base1); - moff <<= LOG2_BITS_PER_UNIT; - if (wi::neg_p (moff)) - offset2 += (-moff).to_short_addr (); - else - offset1 += moff.to_shwi (); - moff = mem_ref_offset (base2); - moff <<= LOG2_BITS_PER_UNIT; - if (wi::neg_p (moff)) - offset1 += (-moff).to_short_addr (); - else - offset2 += moff.to_short_addr (); - return ranges_overlap_p (offset1, max_size1, offset2, max_size2); + offset_int moff1 = mem_ref_offset (base1) << LOG2_BITS_PER_UNIT; + offset_int moff2 = mem_ref_offset (base2) << LOG2_BITS_PER_UNIT; + return ranges_may_overlap_p (offset1 + moff1, max_size1, + offset2 + moff2, max_size2); } if (!ptr_derefs_may_alias_p (ptr1, ptr2)) return false;