From patchwork Mon May 23 21:03:43 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: 97061 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 69C9EB6FB0 for ; Tue, 24 May 2011 07:06:08 +1000 (EST) Received: (qmail 13833 invoked by alias); 23 May 2011 21:06:06 -0000 Received: (qmail 13824 invoked by uid 22791); 23 May 2011 21:06:05 -0000 X-SWARE-Spam-Status: No, hits=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE, SPF_FAIL X-Spam-Check-By: sourceware.org Received: from smtp-vbr1.xs4all.nl (HELO smtp-vbr1.xs4all.nl) (194.109.24.21) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Mon, 23 May 2011 21:05:51 +0000 Received: from [192.168.1.68] (teejay.xs4all.nl [213.84.119.160]) (authenticated bits=0) by smtp-vbr1.xs4all.nl (8.13.8/8.13.8) with ESMTP id p4NL5lau071818 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Mon, 23 May 2011 23:05:48 +0200 (CEST) (envelope-from vries@codesourcery.com) Message-ID: <4DDACBAF.7090700@codesourcery.com> Date: Mon, 23 May 2011 23:03:43 +0200 From: Tom de Vries User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.17) Gecko/20110424 Lightning/1.0b2 Thunderbird/3.1.10 MIME-Version: 1.0 To: Zdenek Dvorak CC: gcc-patches@gcc.gnu.org Subject: [PATCH, PR49121] [4.7 Regression] FAIL: gcc.dg/tree-ssa/ivopt_infer_2.c scan-tree-dump-times ivopts "Replacing" 0 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, This test case gcc.dg/tree-ssa/ivopt_infer_2.c started failing due to http://gcc.gnu.org/ml/gcc-cvs/2011-05/msg00837.html. test case: ... #ifndef TYPE #define TYPE char* #endif extern int a[]; /* Can not infer loop iteration from array -- exit test can not be replaced. */ void foo (int i_width, TYPE dst, TYPE src1, TYPE src2) { TYPE dstn= dst + i_width; TYPE dst0 = dst; unsigned long long i = 0; for( ; dst <= dstn; ) { dst0[i] = ( src1[i] + src2[i] + 1 +a[i]) >> 1; dst++; i += 16; } } ... test case representation at ivopts: ... foo (int i_width, char * dst, char * src1, char * src2) { long long unsigned int i; char * dstn; char D.2707; int D.2706; int D.2705; int D.2704; int D.2703; int D.2702; int D.2701; char D.2700; char * D.2699; int D.2698; char D.2697; char * D.2696; char * D.2695; long unsigned int D.2694; : D.2694_4 = (long unsigned int) i_width_3(D); dstn_6 = dst_5(D) + D.2694_4; if (dst_5(D) <= dstn_6) goto ; else goto ; : : # dst_32 = PHI # i_33 = PHI D.2695_9 = dst_5(D) + i_33; D.2696_11 = src1_10(D) + i_33; D.2697_12 = *D.2696_11; D.2698_13 = (int) D.2697_12; D.2699_15 = src2_14(D) + i_33; D.2700_16 = *D.2699_15; D.2701_17 = (int) D.2700_16; D.2702_18 = D.2698_13 + D.2701_17; D.2703_19 = D.2702_18 + 1; D.2704_20 = a[i_33]; D.2705_21 = D.2703_19 + D.2704_20; D.2706_22 = D.2705_21 >> 1; D.2707_23 = (char) D.2706_22; *D.2695_9 = D.2707_23; dst_24 = dst_32 + 1; i_25 = i_33 + 16; if (dstn_6 >= dst_24) goto ; else goto ; : goto ; : : return; } ... the patch causes estimated_loop_iterations (loop, true, &max_niter) in may_eliminate_iv to return a different value: without patch: 0x10000000000000000 with patch: 0x01000000000000000 The analysis in the patch concludes that the pointer arithmetic statement D.2695_9 = dst_5(D) + i_33 can only be executed 0x01000000000000000 times, based on the fact that i is incremented with 16 each iteration. Note that the statement corresponds to the pointer arithmetic in 'dst0[i]'. Since the proposed new char pointer iterator can represent 0x10000000000000000 distinct values, may_eliminate_iv returns true, and the exit test is replaced: ... Replacing exit test: if (dstn_6 >= dst_24) ... This causes the check: ... /* { dg-final { scan-tree-dump-times "Replacing" 0 "ivopts"} } */ ... to fail. The analysis is correct, and the test case needs to be adapted. I adapted the testcase such that it still replaces the exit test if 'a' is declared as 'char a[400]', but not if it is declared as 'extern char a[]'. ok for trunk? Thanks, - Tom 2011-05-23 Tom de Vries PR tree-optimization/49121 * gcc.dg/tree-ssa/ivopt_infer_2.c: Adapt test. Index: gcc/testsuite/gcc.dg/tree-ssa/ivopt_infer_2.c =================================================================== --- gcc/testsuite/gcc.dg/tree-ssa/ivopt_infer_2.c (revision 173703) +++ gcc/testsuite/gcc.dg/tree-ssa/ivopt_infer_2.c (working copy) @@ -5,20 +5,20 @@ #define TYPE char* #endif -extern int a[]; +extern char a[]; /* Can not infer loop iteration from array -- exit test can not be replaced. */ -void foo (int i_width, TYPE dst, TYPE src1, TYPE src2) +void foo (unsigned int i_width, TYPE dst) { - TYPE dstn= dst + i_width; - TYPE dst0 = dst; - unsigned long long i = 0; - for( ; dst <= dstn; ) - { - dst0[i] = ( src1[i] + src2[i] + 1 +a[i]) >> 1; - dst++; - i += 16; - } + unsigned long long i = 0; + unsigned long long j = 0; + for ( ; j < i_width; ) + { + *dst = a[i]; + dst++; + i += 2; + j += 1; + } } /* { dg-final { scan-tree-dump-times "Replacing" 0 "ivopts"} } */