From patchwork Tue Nov 1 11:54:26 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kyrill Tkachov X-Patchwork-Id: 80331 Delivered-To: patch@linaro.org Received: by 10.140.97.247 with SMTP id m110csp586743qge; Tue, 1 Nov 2016 04:55:08 -0700 (PDT) X-Received: by 10.99.63.135 with SMTP id m129mr9037185pga.16.1478001308371; Tue, 01 Nov 2016 04:55:08 -0700 (PDT) Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id 145si30044120pgc.315.2016.11.01.04.55.08 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 01 Nov 2016 04:55:08 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-return-440028-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-440028-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-440028-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=j7+qOhjT92MgtEW4IytBpIRME6u8VXU4N3GJXAt/M2w1kE STcCCkgJuY3ABAjnf2ECu+h5On0odSBkdslk1N1Ezf7fStCrkqicpAVqfisSliL+ kl+L7+cbZbpdO8TuSxrNQ85sKKpz3h+E4PSYC47igS4feyDrKabhbox3egEaw= 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=Ecs+ktl7hWI+KHvqQc0OhYNG6U0=; b=XgT5cdK6rOMswd3e4Mzi EBikJY1flmxOz5weBU8o5VWfCgPoeFu8Q4PSzHr2jjGBJ/xgGLOpP3azFEJuq7jv vorePB1lwURnTeXfwwUGRGiLSOu7z3AAVACV4bGhuS1z7SeQORXhGddoO4HQSKdw 17H9Wu7Av41XM1dKE4M9098= Received: (qmail 110525 invoked by alias); 1 Nov 2016 11:54:41 -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 110494 invoked by uid 89); 1 Nov 2016 11:54:40 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-3.4 required=5.0 tests=BAYES_00, KAM_LAZY_DOMAIN_SECURITY, RP_MATCHES_RCVD autolearn=ham version=3.3.2 spammy=trips, filling, Hx-languages-length:2155, enhancement 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, 01 Nov 2016 11:54:30 +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 48A0E16; Tue, 1 Nov 2016 04:54:28 -0700 (PDT) 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 ED1593F318 for ; Tue, 1 Nov 2016 04:54:27 -0700 (PDT) Message-ID: <58188272.3040104@foss.arm.com> Date: Tue, 01 Nov 2016 11:54:26 +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] PR tree-optimization/78162: Reject negative offsets in store merging early Hi all, Store merging ICEs on this invalid testcase because it trips up on the negative bitposition to store to. It doesn't really expect to handle negative offsets and I believe they won't occur very often in valid code anyway. Filling out structs/bitfields/class members involves positive offsets. I can look into removing all the assumptions about positive offsets if folks want me to (should involve removing some 'unsigned' modifiers from HOST_WIDE_INTs and double-checking some range checks), but for now this patch just fixes the ICE by rejecting negative offsets early on. Bootstrapped and tested on aarch64-none-linux-gnu and x86_64. Ok for trunk? Thanks, Kyrill 2016-11-01 Kyrylo Tkachov PR tree-optimization/78162 * gimple-ssa-store-merging.c (execute): Mark stores with bitpos < 0 as invalid. 2016-11-01 Kyrylo Tkachov PR tree-optimization/78162 * gcc.c-torture/compile/pr78162.c: New test. diff --git a/gcc/gimple-ssa-store-merging.c b/gcc/gimple-ssa-store-merging.c index f82cad35afbc10eea76957d38100acdce137d271..4dbf03f61ab5ed4e33481d53cc3c2dee1a457f8f 100644 --- a/gcc/gimple-ssa-store-merging.c +++ b/gcc/gimple-ssa-store-merging.c @@ -1371,7 +1371,7 @@ pass_store_merging::execute (function *fun) &unsignedp, &reversep, &volatilep); /* As a future enhancement we could handle stores with the same base and offset. */ - bool invalid = offset || reversep + bool invalid = offset || reversep || bitpos < 0 || ((bitsize > MAX_BITSIZE_MODE_ANY_INT) && (TREE_CODE (rhs) != INTEGER_CST)) || !rhs_valid_for_store_merging_p (rhs) diff --git a/gcc/testsuite/gcc.c-torture/compile/pr78162.c b/gcc/testsuite/gcc.c-torture/compile/pr78162.c new file mode 100644 index 0000000000000000000000000000000000000000..743d4e678b5b8c9a7ee6fb45254f86212523d59c --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/compile/pr78162.c @@ -0,0 +1,10 @@ +/* PR tree-optimization/78162. + Handle negative offsets in store merging gracefully. */ + +int a, b[1][2]; + +void fn1() +{ + for (a = 0; a < 2; a++) + b[-1][a] = 0; +}