From patchwork Tue Nov 8 12:03:22 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kyrill Tkachov X-Patchwork-Id: 81293 Delivered-To: patch@linaro.org Received: by 10.140.97.165 with SMTP id m34csp1506694qge; Tue, 8 Nov 2016 04:04:00 -0800 (PST) X-Received: by 10.36.76.22 with SMTP id a22mr8647978itb.44.1478606640857; Tue, 08 Nov 2016 04:04:00 -0800 (PST) Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id v5si30518292pag.30.2016.11.08.04.04.00 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 08 Nov 2016 04:04:00 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-return-440732-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; spf=pass (google.com: domain of gcc-patches-return-440732-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-440732-patch=linaro.org@gcc.gnu.org DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :message-id:date:from:mime-version:to:subject:content-type; q= dns; s=default; b=Ic+eTDh42+AYLZ03PhbXs0OhR45IHqsDq/CsOVOUG0EWtM au89yq5dH6FhfFjVdKdEHFGe4hpF2PK1xTPYx9Ggai2+sPSWt9fngyoWd8knFgpT DXV4kHEG5WJb7iLFDrFGKgdjuVAXOzbBnSPOhusN1XviHbzwB1XNn2Bb4pnMY= 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 :message-id:date:from:mime-version:to:subject:content-type; s= default; bh=9T0Ewap+DhYqhmkOZ6lixYLJFRg=; b=icBSyJD4aO0ByrfsiYlA y5WcBMvjfqvsfN/J8cSQKtMlocyP01QN94bVPUbfWJLV1w52v9QlyeYKNIt/akND 8GJqGqmsfI6poEKxneWxFBijYZeXoTzZTjuQASg2mHJo1hjTngGjcWwlwcHtaC8f 8+D5WVSMU1EsWHL2LUFHSDQ= Received: (qmail 49600 invoked by alias); 8 Nov 2016 12:03:35 -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 49516 invoked by uid 89); 8 Nov 2016 12:03:35 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-3.8 required=5.0 tests=BAYES_00, KAM_LAZY_DOMAIN_SECURITY, RP_MATCHES_RCVD autolearn=ham version=3.3.2 spammy=20161108 X-HELO: foss.arm.com Received: from foss.arm.com (HELO foss.arm.com) (217.140.101.70) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 08 Nov 2016 12:03:25 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id BF71228; Tue, 8 Nov 2016 04:03:23 -0800 (PST) Received: from [10.2.207.77] (e100706-lin.cambridge.arm.com [10.2.207.77]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 71BC63F25D for ; Tue, 8 Nov 2016 04:03:23 -0800 (PST) Message-ID: <5821BF0A.1020609@foss.arm.com> Date: Tue, 08 Nov 2016 12:03:22 +0000 From: Kyrill Tkachov User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.2.0 MIME-Version: 1.0 To: GCC Patches Subject: [PATCH][1/2] Fix off-by-one error in clear_bit_region in store merging (PR tree-optimization/78234 ?) Hi all, There is an off-by-one error in the clear_bit_region helper in store merging in the case where it deals with multi-byte quantities starting at a non-zero bit offset. The particular input is {0xff, 0xff, 0xff} and we want to clear all bits except the least and most significant i.e. we want: {0x01, 0x00, 0x80} so it's called as clear_bit_region (input, 1, 22); This ends up clearing one more bit due to this bug. The patch fixes that. The last argument to clear_bit_region is the number of bits left to clear and since in the previous call we cleared BITS_PER_UNIT - start bits we should subtract exactly that amount from len when calculating the bits left to clear. This was uncovered when writing initial unit tests for these functions which are included in the followup patch. Bootstrapped and tested on aarch64 and x86_64 (the affected function is only called for little-endian code). Ok for trunk? Thanks, Kyrill 2016-11-08 Kyrylo Tkachov PR tree-optimization/78234 * gimple-ssa-store-merging.c (clear_bit_region): Fix off-by-one error in start != 0 case. diff --git a/gcc/gimple-ssa-store-merging.c b/gcc/gimple-ssa-store-merging.c index 36bc833af910f85c4c8ed7581a247f5d3182053d..46f92ba2d2f4e85c4256be11be5c8b1d40c21499 100644 --- a/gcc/gimple-ssa-store-merging.c +++ b/gcc/gimple-ssa-store-merging.c @@ -337,7 +337,7 @@ clear_bit_region (unsigned char *ptr, unsigned int start, else if (start != 0) { clear_bit_region (ptr, start, BITS_PER_UNIT - start); - clear_bit_region (ptr + 1, 0, len - (BITS_PER_UNIT - start) + 1); + clear_bit_region (ptr + 1, 0, len - (BITS_PER_UNIT - start)); } /* Whole bytes need to be cleared. */ else if (start == 0 && len > BITS_PER_UNIT)