From patchwork Wed Mar 8 10:53:12 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Haley X-Patchwork-Id: 736522 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 3vdVkM4MvJz9sCX for ; Wed, 8 Mar 2017 21:53:30 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="eWt12q/D"; 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:to :from:subject:message-id:date:mime-version:content-type :content-transfer-encoding; q=dns; s=default; b=XluxVicJRS3W6tbC CWv98jn9+fRzP3zsaIQUB/+vFzWLiyL9W8lss9j6oVUUjUJ0GbpV8paA/+2ehSS6 97T6VH1x1x9dFsiYlRC+1hnLiKnmYtMS0mRFasVYSMeeUIl73AomHlYwh28/VV66 wV/m41ardd7ZX6V4CSSXXaKjOY0= 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:to :from:subject:message-id:date:mime-version:content-type :content-transfer-encoding; s=default; bh=2eAKF6NFXlAayvwNdKHFI7 96CJc=; b=eWt12q/DNtlsypcWPhQmVGmsR8ivgCY9FwikrRhLhLEd+Y92lgTYGv gYCUfyb5QkKu3K+smyyPerS102S0yrDToEit+qb6Q+z2wcZre8ftg7eSIurYFlBk uZ5fNFVBw0Tjzw7dQA0wEQlCd+2lYgzseinwcyao0qIO8JyFUFCXE= Received: (qmail 128172 invoked by alias); 8 Mar 2017 10:53:20 -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 125211 invoked by uid 89); 8 Mar 2017 10:53:19 -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, RP_MATCHES_RCVD, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=H*Ad:U*aph, U*aph, beg, haley X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 08 Mar 2017 10:53:17 +0000 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5AFD5C03BD78 for ; Wed, 8 Mar 2017 10:53:18 +0000 (UTC) Received: from zebedee.pink ([10.33.36.50]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v28ArDNx005107; Wed, 8 Mar 2017 05:53:14 -0500 To: GCC Patches From: Andrew Haley Subject: [PATCH] Loop splitting breaks with loops of pointer type Message-ID: Date: Wed, 8 Mar 2017 10:53:12 +0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.7.0 MIME-Version: 1.0 X-IsSubscribed: yes Loop splitting is fine when the control variable is of integer type, but when it is a pointer type the upper bound of the new loop is calculated incorrectly. The calculation should be guard_init + (end-beg), but instead we do guard_init - (end-beg). Fixed thusly. Bootstrapped, regtested. OK? Andrew. 2017-03-08 Andrew Haley PR tree-optimization/79894 * tree-ssa-loop-split.c (compute_new_first_bound): When calculating the new upper bound, (END-BEG) should be added, not subtracted. Index: gcc/tree-ssa-loop-split.c =================================================================== --- gcc/tree-ssa-loop-split.c (revision 245948) +++ gcc/tree-ssa-loop-split.c (working copy) @@ -436,7 +436,6 @@ if (POINTER_TYPE_P (TREE_TYPE (guard_init))) { enddiff = gimple_convert (stmts, sizetype, enddiff); - enddiff = gimple_build (stmts, NEGATE_EXPR, sizetype, enddiff); newbound = gimple_build (stmts, POINTER_PLUS_EXPR, TREE_TYPE (guard_init), guard_init, enddiff); 2017-03-08 Andrew Haley PR tree-optimization/79894 * gcc.dg/tree-ssa/pr79943.c: New test. Index: gcc/testsuite/gcc.dg/tree-ssa/pr79943.c =================================================================== --- gcc/testsuite/gcc.dg/tree-ssa/pr79943.c (revision 0) +++ gcc/testsuite/gcc.dg/tree-ssa/pr79943.c (revision 0) @@ -0,0 +1,40 @@ +/* { dg-do run } */ +/* { dg-options "-O2 -fsplit-loops -fdump-tree-lsplit-details" } */ +/* { dg-require-effective-target int32plus } */ + +#ifdef __cplusplus +extern "C" void abort (void); +#else +extern void abort (void); +#endif + +typedef struct { + int n; +} region_t; + +void set (region_t *region) __attribute__((noinline)); +void doit (region_t *beg, region_t *end, region_t *limit) + __attribute__((noinline)); + +region_t regions[10]; + +void +set (region_t *region) { + region->n = 1; +} + +void +doit (region_t *beg, region_t *end, region_t *limit) { + for (region_t *cur = beg; cur < end; cur++) { + if (cur < limit) { + set(cur); + } + } +} + +int +main (void) { + doit(®ions[0], ®ions[2], ®ions[10]); + if (regions[1].n != 1) + abort(); +}