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