From patchwork Mon Oct 23 11:29:39 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Sandiford X-Patchwork-Id: 116708 Delivered-To: patch@linaro.org Received: by 10.140.22.164 with SMTP id 33csp4533533qgn; Mon, 23 Oct 2017 04:29:58 -0700 (PDT) X-Received: by 10.98.67.154 with SMTP id l26mr12913773pfi.212.1508758198409; Mon, 23 Oct 2017 04:29:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1508758198; cv=none; d=google.com; s=arc-20160816; b=tO0GYTXQ+R2zmPtsoMP+Dgu0Y7br2aOM4WibclRR4AxVW25TTDirnBGuEX6mN/Fb8V CdoNb8oOQ1Pou9wmLdddQaBAr4cPy3wiENjrmoqHVBgTUXQLQ6ZLWpHuyYQAEBhzLkB8 88Kms3yzf5+k95Oyym2a8/kVEDazzRf7HPFaJzucpQkI0if5OKZ//lN5rEcKQo4xu+7S jpNdUHtSYQX5fQbl90kXMOgMDbKf8pvbzXddHR/7Bd9NYZqN7PxDUINzXGusUlDOpfQt SJIsvlMqwWd6wkd+4PFgAPHAr5s63Xsmaef2OoJMDZ0rrZ5q5uYD5icLBvjn9gD6l462 sM9A== 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=EghnQmdkufP679kSDf+xP1xBgibeHnh5zhEAq8W8DUM=; b=ADYi574N8yiqPCuHIvNV+QRbKP9enCLb+aMA+h8QHIaLiEiU2lY85pLegHjTZoqk+k U/bxrnMG0M7UUhvLoW2PLKI6t61A0EnKLDE+uwOHTm62z2kyTBY6clYCOumjAE+rKQ2Z rH6v/925JYx52JlEdo14+anjeDCguSL/dv3Zw7+vOe7ZHBeVF42ViLO9pgZtbOun05WH dvWUJZhyH3TADVRM86nJeaN33H1tC6fN1TIr8XkElfiObnuoUpcGMeEcmPEGkUfj5f0Y dJMIj2gRoOtnWNbTZhGbsFfTr9HVDsMmtVR/TQmOju7VkE/qZBovoF8wa8YSbstltqAk 721A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=cWB/8+qB; spf=pass (google.com: domain of gcc-patches-return-464748-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-464748-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 e7si5184727pfc.465.2017.10.23.04.29.58 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 23 Oct 2017 04:29:58 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-return-464748-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=cWB/8+qB; spf=pass (google.com: domain of gcc-patches-return-464748-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-464748-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=eN6bEjP1ywt8BEqzKf9iNacfUUpFX 4COYT4Z0N20qnloZBXdSF815AOV/53JvXYYRVnIUy8bfkTpzu0MIXkSb4vNGajG6 EsdOOvGBm+AbRHRglO+lwLfJWzQ+ZdG0/Oe9ADVNnPvQv2nLBoxso6Fiq6dX3XWX AfouD3roE4EQbE= 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=pOrP7SHLhv3qIYruHuPvIQVTk2E=; b=cWB /8+qByEtypX+qEllWOPM/LqwWDkuonrytIsFNePCTlARSPpyj81BYuUF8yV5F/67 +KwoO9is2ZnHWu/IhlYdb0aoOIn9nv+dlBlLTzbLwnW3He5QLKytAdbwqJLOgSSj kgyXaGHemgLVvw4TuPAkv1g4TvoprRmOiPyr5b8E= Received: (qmail 94942 invoked by alias); 23 Oct 2017 11:29:46 -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 94925 invoked by uid 89); 23 Oct 2017 11:29:44 -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=15113 X-HELO: mail-wr0-f196.google.com Received: from mail-wr0-f196.google.com (HELO mail-wr0-f196.google.com) (209.85.128.196) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 23 Oct 2017 11:29:43 +0000 Received: by mail-wr0-f196.google.com with SMTP id k62so16981100wrc.9 for ; Mon, 23 Oct 2017 04:29:42 -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=EghnQmdkufP679kSDf+xP1xBgibeHnh5zhEAq8W8DUM=; b=Afi8HPzYROxd1yX53DoCGTl3nVYR0G/AdcmhLOIT3dKf1QOAAFhTFzI/VxKEDO0Pu/ Kdd7pOUZAT+1xyrjMb66oQWlL8WNv7IvY9r5XQIJEp6NZAPS4DeyRrdZRbw79KTBDNvG AT/eVEAdnBmryJecgC5rc7svKA+t1/fJLhbbCD/CdTravWsIzmTqPMOTjcaPOw5PkyCJ cMfuBcDEwZ1RMlgR3gd+35ozOj5R8qPnhsiRzVirdLNt1pJdyMQtEVkpuo586O3IgB9c yqCXMYcjbGaDIUbdNoKc2HAMBX6VaVbPo7CwSk/9EDz+S+CzJFD3vD5aE1mx6nWQaWl2 XJpw== X-Gm-Message-State: AMCzsaUuIbYbckH2GsOcK7hOC7O0/YIDioYjqc/xJmfUI/vkEjVFCxso Fxg6OWyBVsFmvbB7lKr7W3Tk88Z06PU= X-Google-Smtp-Source: ABhQp+QzhVlHwjPeQ69AAF2DluWbubOAoogVzTyncsaH6bygKHJPiY1IUOuPt5YGF90rjibp4G+2Tg== X-Received: by 10.223.134.212 with SMTP id 20mr10242999wry.81.1508758181017; Mon, 23 Oct 2017 04:29:41 -0700 (PDT) Received: from localhost ([2.26.27.199]) by smtp.gmail.com with ESMTPSA id l7sm4318593wrg.69.2017.10.23.04.29.39 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 23 Oct 2017 04:29:39 -0700 (PDT) From: Richard Sandiford To: gcc-patches@gcc.gnu.org Mail-Followup-To: gcc-patches@gcc.gnu.org, richard.sandiford@linaro.org Subject: [20/nn] Make tree-ssa-dse.c:normalize_ref return a bool References: <87wp3mxgir.fsf@linaro.org> Date: Mon, 23 Oct 2017 12:29:39 +0100 In-Reply-To: <87wp3mxgir.fsf@linaro.org> (Richard Sandiford's message of "Mon, 23 Oct 2017 12:14:36 +0100") Message-ID: <87inf6umos.fsf@linaro.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.2 (gnu/linux) MIME-Version: 1.0 This patch moves the check for an overlapping byte to normalize_ref from its callers, so that it's easier to convert to poly_ints later. It's not really worth it on its own. 2017-10-23 Richard Sandiford gcc/ * tree-ssa-dse.c (normalize_ref): Check whether the ranges overlap and return false if not. (clear_bytes_written_by, live_bytes_read): Update accordingly. Index: gcc/tree-ssa-dse.c =================================================================== --- gcc/tree-ssa-dse.c 2017-10-23 11:41:23.587123840 +0100 +++ gcc/tree-ssa-dse.c 2017-10-23 11:47:41.546155781 +0100 @@ -137,13 +137,11 @@ valid_ao_ref_for_dse (ao_ref *ref) && (ref->size != -1)); } -/* Normalize COPY (an ao_ref) relative to REF. Essentially when we are - done COPY will only refer bytes found within REF. +/* Try to normalize COPY (an ao_ref) relative to REF. Essentially when we are + done COPY will only refer bytes found within REF. Return true if COPY + is known to intersect at least one byte of REF. */ - We have already verified that COPY intersects at least one - byte with REF. */ - -static void +static bool normalize_ref (ao_ref *copy, ao_ref *ref) { /* If COPY starts before REF, then reset the beginning of @@ -151,13 +149,22 @@ normalize_ref (ao_ref *copy, ao_ref *ref number of bytes removed from COPY. */ if (copy->offset < ref->offset) { - copy->size -= (ref->offset - copy->offset); + HOST_WIDE_INT diff = ref->offset - copy->offset; + if (copy->size <= diff) + return false; + copy->size -= diff; copy->offset = ref->offset; } + HOST_WIDE_INT diff = copy->offset - ref->offset; + if (ref->size <= diff) + return false; + /* If COPY extends beyond REF, chop off its size appropriately. */ - if (copy->offset + copy->size > ref->offset + ref->size) - copy->size -= (copy->offset + copy->size - (ref->offset + ref->size)); + HOST_WIDE_INT limit = ref->size - diff; + if (copy->size > limit) + copy->size = limit; + return true; } /* Clear any bytes written by STMT from the bitmap LIVE_BYTES. The base @@ -179,14 +186,10 @@ clear_bytes_written_by (sbitmap live_byt if (valid_ao_ref_for_dse (&write) && operand_equal_p (write.base, ref->base, OEP_ADDRESS_OF) && write.size == write.max_size - && ((write.offset < ref->offset - && write.offset + write.size > ref->offset) - || (write.offset >= ref->offset - && write.offset < ref->offset + ref->size))) - { - normalize_ref (&write, ref); - bitmap_clear_range (live_bytes, - (write.offset - ref->offset) / BITS_PER_UNIT, + && normalize_ref (&write, ref)) + { + HOST_WIDE_INT start = write.offset - ref->offset; + bitmap_clear_range (live_bytes, start / BITS_PER_UNIT, write.size / BITS_PER_UNIT); } } @@ -480,21 +483,20 @@ live_bytes_read (ao_ref use_ref, ao_ref { /* We have already verified that USE_REF and REF hit the same object. Now verify that there's actually an overlap between USE_REF and REF. */ - if (ranges_overlap_p (use_ref.offset, use_ref.size, ref->offset, ref->size)) + if (normalize_ref (&use_ref, ref)) { - normalize_ref (&use_ref, ref); + HOST_WIDE_INT start = use_ref.offset - ref->offset; + HOST_WIDE_INT size = use_ref.size; /* If USE_REF covers all of REF, then it will hit one or more live bytes. This avoids useless iteration over the bitmap below. */ - if (use_ref.offset <= ref->offset - && use_ref.offset + use_ref.size >= ref->offset + ref->size) + if (start == 0 && size == ref->size) return true; /* Now check if any of the remaining bits in use_ref are set in LIVE. */ - unsigned int start = (use_ref.offset - ref->offset) / BITS_PER_UNIT; - unsigned int end = ((use_ref.offset + use_ref.size) / BITS_PER_UNIT) - 1; - return bitmap_bit_in_range_p (live, start, end); + return bitmap_bit_in_range_p (live, start / BITS_PER_UNIT, + (start + size - 1) / BITS_PER_UNIT); } return true; }