From patchwork Mon Dec 12 15:29:24 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Matz X-Patchwork-Id: 705059 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3tcmwt5L0Qz9t6g for ; Tue, 13 Dec 2016 02:29:50 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="BpMgyS2E"; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:cc:subject:in-reply-to:message-id:references :mime-version:content-type; q=dns; s=default; b=U4jilghvlO4N2ivE l/Zjag+2COMRjXzq6buVFLT00tCkr5JP9ps071BDfMhTAnuSKOOvT6UR8+To4dz4 dOkhFTA3/v/zXQn3P0FvBIBa8wB3q3JyDRuFDVHRkat1U7pn4cZO7/IqJFePqYpE F8GW/jdzrqbO7RW5uRByGKWK4YI= 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:date :from:to:cc:subject:in-reply-to:message-id:references :mime-version:content-type; s=default; bh=8wYSPdYlYOnwtaMcJAsPss 7WDYc=; b=BpMgyS2Eskae1mrO/dIeyf6UcppuvMTclwbA8jW3MjT21A74UFfL/L 8AAN2fWB8KfDjZ8Li12d57/sHH3wL25OJ6NMIkWqmEDZd5N9jKJrKOiwvbyX7Rv+ cGWvK66zNS8yNl1JM7zA/gX9RROgOt6KD0l7uqfrYdWeH9sT1wc3U= Received: (qmail 9304 invoked by alias); 12 Dec 2016 15:29:39 -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 9258 invoked by uid 89); 12 Dec 2016 15:29:38 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-5.0 required=5.0 tests=BAYES_00, RP_MATCHES_RCVD, SPF_PASS autolearn=ham version=3.3.2 spammy=ciao, Hx-languages-length:3246 X-HELO: mx2.suse.de Received: from mx2.suse.de (HELO mx2.suse.de) (195.135.220.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 12 Dec 2016 15:29:28 +0000 Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id D7FB6AAC7; Mon, 12 Dec 2016 15:29:24 +0000 (UTC) Date: Mon, 12 Dec 2016 16:29:24 +0100 (CET) From: Michael Matz To: Richard Biener cc: gcc-patches@gcc.gnu.org Subject: Re: Fix PR78725 (v2) In-Reply-To: <8DE64A60-43DC-4CC2-AF9B-6318A9EF5109@gmail.com> Message-ID: References: <8DE64A60-43DC-4CC2-AF9B-6318A9EF5109@gmail.com> User-Agent: Alpine 2.20 (LSU 67 2015-01-07) MIME-Version: 1.0 X-IsSubscribed: yes Hi, On Fri, 9 Dec 2016, Richard Biener wrote: > On December 9, 2016 4:29:04 PM GMT+01:00, Michael Matz wrote: > >Hi, > > > >if the induction variable on which we want to partition the loop > >iterations for loop splitting might overflow we would either need > >runtime > >tests checking if an overflow in fact does happen, or we can simply not > > > >split loops on such ones. I chose the latter. > > > >Fixes the testcase, and regstrapped without regressions on x86-64-linux > > > >(all languages+Ada). Okay for trunk? > > OK Actually there came another report in the same bug, which has a different but related cause. In the testcase the potential split-point is if (outer >= inner) where the final value of 'inner' is known constant in the _outer_ loop. But of course we have to consider the actual place of the use: the comparison statement which is inside the inner loop, not merely in the outer loop. Fixed with the amended patch. Regstrapping on x86-64-linux in progress (all langs+ada), but I know that it fixes both testcases and doesn't regress in gcc.dg. Okay for trunk if regstrapping succeeds? Ciao, Michael. PR tree-optimization/78725 * tree-ssa-loop-split.c (split_at_bb_p): Check for overflow and at correct use point. testsuite/ PR tree-optimization/78725 * gcc.dg/pr78725.c: New test. * gcc.dg/pr78725-2.c: New test. diff --git a/gcc/testsuite/gcc.dg/pr78725-2.c b/gcc/testsuite/gcc.dg/pr78725-2.c new file mode 100644 index 0000000..9de489e --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr78725-2.c @@ -0,0 +1,19 @@ +/* { dg-do run } */ +/* { dg-options "-O3 -fsplit-loops" } */ + +int a, b, c; + +int main () +{ + int d; + for (; c < 1; c++) + for (d = 0; d < 3; d++) + for (b = 0; b < 1; b++) + if (c >= d) + a = 1; + + if (a != 1) + __builtin_abort (); + + return 0; +} diff --git a/gcc/testsuite/gcc.dg/pr78725.c b/gcc/testsuite/gcc.dg/pr78725.c new file mode 100644 index 0000000..ed95790 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr78725.c @@ -0,0 +1,19 @@ +/* { dg-do run } */ +/* { dg-options "-O3 -fsplit-loops" } */ + +int fn1 (int b, int c) +{ + return c < 0 || c > 31 ? 0 : b >> c; +} + +unsigned char d = 255; +int e, f; + +int main () +{ + for (; f < 2; f++) + e = fn1 (1, d++); + if (e != 1) + __builtin_abort (); + return 0; +} diff --git a/gcc/tree-ssa-loop-split.c b/gcc/tree-ssa-loop-split.c index dac68e6..84c0627 100644 --- a/gcc/tree-ssa-loop-split.c +++ b/gcc/tree-ssa-loop-split.c @@ -102,10 +102,11 @@ split_at_bb_p (struct loop *loop, basic_block bb, tree *border, affine_iv *iv) tree op0 = gimple_cond_lhs (stmt); tree op1 = gimple_cond_rhs (stmt); + struct loop *useloop = loop_containing_stmt (stmt); - if (!simple_iv (loop, loop, op0, iv, false)) + if (!simple_iv (loop, useloop, op0, iv, false)) return NULL_TREE; - if (!simple_iv (loop, loop, op1, &iv2, false)) + if (!simple_iv (loop, useloop, op1, &iv2, false)) return NULL_TREE; /* Make it so that the first argument of the condition is @@ -122,6 +123,8 @@ split_at_bb_p (struct loop *loop, basic_block bb, tree *border, affine_iv *iv) return NULL_TREE; if (!integer_zerop (iv2.step)) return NULL_TREE; + if (!iv->no_overflow) + return NULL_TREE; if (dump_file && (dump_flags & TDF_DETAILS)) {