From patchwork Thu Apr 26 12:22:24 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 905046 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-476849-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=suse.de Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="fse5rGak"; dkim-atps=neutral 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 40Wx652pTzz9rxx for ; Thu, 26 Apr 2018 22:22:37 +1000 (AEST) 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:subject:message-id:mime-version:content-type; q=dns; s= default; b=dv+wC/1JsQqf6pqqmzMSz3ed0sbUBB3kztYB6eXpEYkMP0kVa3b58 Bow8xJqdQF5bg1MZOEIQYYxNoCIrsIJMsoFEUKNDnAXdfZZQe5fi2MsG9rL8UfWE EvokMXWiNaK5s66p6NCRxDwK2ndhCcXp5/19DNIk/sWdzWcTwVh1l8= 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:subject:message-id:mime-version:content-type; s= default; bh=/2dgJfIRzUVnbP1ILqOwSu0GhJ0=; b=fse5rGakaQFOerGfKUoG G4z88nKYoblQfu9rumEOxbqqg7GtQ7OT896tl+suMiG0ZrcSv30A61/Tvcqeo4Ec rUZEcx3nbwxL1n8Je7uiG+/FmvPeg4UyrRGS7yMZ18wzWRet1Hb4gMX/bf9hWlhb 7/m6inxcimLl7il4fF9SHnc= Received: (qmail 123171 invoked by alias); 26 Apr 2018 12:22:29 -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 123149 invoked by uid 89); 26 Apr 2018 12:22:28 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-11.1 required=5.0 tests=BAYES_00, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, SPF_PASS autolearn=ham version=3.3.2 spammy=rightfully 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; Thu, 26 Apr 2018 12:22:26 +0000 Received: from relay2.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id ADC8CAC6A for ; Thu, 26 Apr 2018 12:22:24 +0000 (UTC) Date: Thu, 26 Apr 2018 14:22:24 +0200 (CEST) From: Richard Biener To: gcc-patches@gcc.gnu.org Subject: [PATCH] Prevent excessive loop-header copying with multiple exits Message-ID: User-Agent: Alpine 2.20 (LSU 67 2015-01-07) MIME-Version: 1.0 The following makes loop-header copying stop after the first exit test it copied. The reports rightfully complain about too much peeling. If some cases pop up which show we should peel up to a specific test we need to improve this heuristic which simply errs on the easy side. Bootstrap & regtest running on x86_64-unknown-linux-gnu. Richard. 2018-04-26 Richard Biener PR tree-optimization/28364 PR tree-optimization/85275 * tree-ssa-loop-ch.c (ch_base::copy_headers): Stop after copying first exit test. * gcc.dg/tree-ssa/copy-headers-5.c: New testcase. Index: gcc/tree-ssa-loop-ch.c =================================================================== --- gcc/tree-ssa-loop-ch.c (revision 259669) +++ gcc/tree-ssa-loop-ch.c (working copy) @@ -328,6 +340,11 @@ ch_base::copy_headers (function *fun) bbs[n_bbs++] = header; gcc_assert (bbs_size > n_bbs); header = exit->dest; + /* Make sure to stop copying after we copied the first exit test. + Without further heuristics we do not want to rotate the loop + any further. */ + if (loop_exits_from_bb_p (loop, exit->src)) + break; } if (!exit) Index: gcc/testsuite/gcc.dg/tree-ssa/copy-headers-5.c =================================================================== --- gcc/testsuite/gcc.dg/tree-ssa/copy-headers-5.c (nonexistent) +++ gcc/testsuite/gcc.dg/tree-ssa/copy-headers-5.c (working copy) @@ -0,0 +1,16 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-tree-ch2-details" } */ + +int is_sorted(int *a, int n) +{ + for (int i = 0; i < n - 1; i++) + if (a[i] > a[i + 1]) + return 0; + return 1; +} + +/* Verify we apply loop header copying but only copy the IV test and + not the alternate exit test. */ + +/* { dg-final { scan-tree-dump "is now do-while loop" "ch2" } } */ +/* { dg-final { scan-tree-dump-times " if " 3 "ch2" } } */