From patchwork Mon Feb 28 09:41:13 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom de Vries X-Patchwork-Id: 84757 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]) by ozlabs.org (Postfix) with SMTP id 1817BB7112 for ; Mon, 28 Feb 2011 20:44:04 +1100 (EST) Received: (qmail 4736 invoked by alias); 28 Feb 2011 09:44:01 -0000 Received: (qmail 4715 invoked by uid 22791); 28 Feb 2011 09:43:58 -0000 X-SWARE-Spam-Status: No, hits=-0.8 required=5.0 tests=AWL, BAYES_00, TW_IV, TW_TM, TW_XF, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mail.codesourcery.com (HELO mail.codesourcery.com) (38.113.113.100) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Mon, 28 Feb 2011 09:43:52 +0000 Received: (qmail 15487 invoked from network); 28 Feb 2011 09:43:47 -0000 Received: from unknown (HELO ?192.168.1.66?) (vries@127.0.0.2) by mail.codesourcery.com with ESMTPA; 28 Feb 2011 09:43:47 -0000 Message-ID: <4D6B6DB9.7050302@codesourcery.com> Date: Mon, 28 Feb 2011 10:41:13 +0100 From: Tom de Vries User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.13) Gecko/20101208 Lightning/1.0b2 Thunderbird/3.1.7 MIME-Version: 1.0 To: rakdver@kam.mff.cuni.cz CC: gcc-patches@gcc.gnu.org, Bernd Schmidt , Maxim Kuvyrkov Subject: ivopts improvement 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 Hi Zdenek, could you please review the following patch set? The goal is to remove the 'i' iterator from the following example, by replacing 'i < n' with 'p < base + n'. void f (char *base, unsigned long int i, unsigned long int n) { char *p = base + i; do { *p = '\0'; p++; i++; } while (i < n); } The difficulty is that this replacement is only valid under the guarantee that base + n does not overflow. I was not able to deduce from the C standard that merely the fact that it's a pointer type guarantees this, so I added analysis to prove no overflow based on the memory access '*p' and the relation between the 2 iterators. patch set description: - iterator.6.1-ml.patch: maximum bounds fix. - iterator.6.2-ml.patch: infrastructure change, no change in functionality. calculate the new comparison operator at the same time as the new bound, and store it next to the new bound in the cost pair. - iterator.6.3-ml.patch: infrastructure change. carved out new function. - iterator.6.4-ml.patch: patch to rewrite an exit test with a '<' using a different iterator. reg-tested on x86-64, and a 4.5 version of the patch set reg-tested on MIPS, ARM and PPC. Thanks, - Tom Index: gcc/testsuite/gcc.dg/tree-ssa/ivopts-lt.c =================================================================== --- gcc/testsuite/gcc.dg/tree-ssa/ivopts-lt.c (revision 0) +++ gcc/testsuite/gcc.dg/tree-ssa/ivopts-lt.c (revision 0) @@ -0,0 +1,20 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-tree-ivopts -fno-tree-vectorize -fno-tree-loop-ivcanon" } */ + +void +f (char *p, unsigned long int i, unsigned long int n) +{ + p += i; + do + { + *p = '\0'; + p += 1; + i++; + } + while (i < n); +} + +/* { dg-final { scan-tree-dump-times "PHI" 1 "ivopts"} } */ +/* { dg-final { scan-tree-dump-times "PHI