From patchwork Mon Sep 2 07:03:50 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Bin Cheng X-Patchwork-Id: 271686 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 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "www.sourceware.org", Issuer "StartCom Class 1 Primary Intermediate Server CA" (not verified)) by ozlabs.org (Postfix) with ESMTPS id 8D9322C009E for ; Mon, 2 Sep 2013 17:04:12 +1000 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:subject:date:message-id:mime-version:content-type; q=dns; s= default; b=ihjVTsqHME7ZsG/G1Tcy0szTTTZySjEfxU4Xolhs2uIgDP1ECjaKz cnKIvBc8BOCQzSzW5lH3sM+zysjibS3imi3TSckq3TIKerCuAESsYGJOdAVS9Gh1 SROUsBcXkBOUuyZL1fkz2LHAyXc8k43iqWTV/slyvTgT0yAwRt8HHY= 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:from :to:subject:date:message-id:mime-version:content-type; s= default; bh=MAu6V0rNoziOgARy5dxlPbAMK14=; b=OLDgprNIV7GFlLcG/zdZ 4gPgf9JW7eQ5xiVJ3XgjIACTN9ZtX+rmmZbrWRw4ZvcIJ2HG1kWryjN4aAt95rG0 Wg8xvOXbuyWDkwbfUAdudz0aZuNmvySNTrZBJFzl5w62yOz1KmvCKlA2GY4667Iy aixfapPRGapw9DybYQAbUBI= Received: (qmail 7116 invoked by alias); 2 Sep 2013 07:04:05 -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 7104 invoked by uid 89); 2 Sep 2013 07:04:05 -0000 Received: from service87.mimecast.com (HELO service87.mimecast.com) (91.220.42.44) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 02 Sep 2013 07:04:05 +0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-3.5 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_LOW, RCVD_IN_HOSTKARMA_NO, RP_MATCHES_RCVD, SPF_PASS autolearn=ham version=3.3.2 X-HELO: service87.mimecast.com Received: from cam-owa2.Emea.Arm.com (fw-tnat.cambridge.arm.com [217.140.96.21]) by service87.mimecast.com; Mon, 02 Sep 2013 08:04:00 +0100 Received: from SHAWIN162 ([10.1.255.212]) by cam-owa2.Emea.Arm.com with Microsoft SMTPSVC(6.0.3790.3959); Mon, 2 Sep 2013 08:03:58 +0100 From: "bin.cheng" To: Subject: [PATCH GCC]Find auto-increment use both before and after candidate's increment in IVOPT Date: Mon, 2 Sep 2013 15:03:50 +0800 Message-ID: <004301cea7aa$949ae0a0$bdd0a1e0$@arm.com> MIME-Version: 1.0 X-MC-Unique: 113090208040006401 X-IsSubscribed: yes Hi, For now set_autoinc_for_original_candidates only searches auto-inc uses before candidate's increment, causing pre-increment opportunities missed for original candidates. This is a straightforward fix by searching after candidate's increment too. The patch also includes a test case to illustrate the problem. Without the patch, assembly of the test is: foo: @ args = 0, pretend = 0, frame = 0 @ frame_needed = 0, uses_anonymous_args = 0 @ link register save eliminated. movw r3, #:lower16:__ctype_ptr__ ldrb r2, [r0] @ zero_extendqisi2 movt r3, #:upper16:__ctype_ptr__ ldr r1, [r3] adds r3, r1, r2 ldrb r3, [r3, #1] @ zero_extendqisi2 lsls r3, r3, #29 bmi .L2 adds r3, r0, #1 .L3: mov r0, r3 adds r3, r3, #1 ldrb r2, [r0] @ zero_extendqisi2 add r2, r2, r1 ldrb r2, [r2, #1] @ zero_extendqisi2 lsls r2, r2, #29 bpl .L3 .L2: bx lr .size foo, .-foo Which can be optimized into below: foo: @ args = 0, pretend = 0, frame = 0 @ frame_needed = 0, uses_anonymous_args = 0 @ link register save eliminated. movw r3, #:lower16:__ctype_ptr__ ldrb r1, [r0] @ zero_extendqisi2 movt r3, #:upper16:__ctype_ptr__ ldr r2, [r3] adds r3, r2, r1 ldrb r3, [r3, #1] @ zero_extendqisi2 lsls r1, r3, #29 bmi .L2 .L3: ldrb r3, [r0, #1]! @ zero_extendqisi2 add r3, r3, r2 ldrb r3, [r3, #1] @ zero_extendqisi2 lsls r3, r3, #29 bpl .L3 .L2: bx lr .size foo, .-foo Bootstrapped and tested on arm a15, is it OK? Thanks. bin 2013-09-02 Bin Cheng * tree-ssa-loop-ivopts.c (set_autoinc_for_original_candidates): Find auto-increment use both before and after candidate. gcc/testsuite/ChangeLog 2013-09-02  Bin Cheng   * gcc.target/arm/ivopts-orig_biv-inc.c: New test. Index: gcc/testsuite/gcc.target/arm/ivopts-orig_biv-inc.c =================================================================== --- gcc/testsuite/gcc.target/arm/ivopts-orig_biv-inc.c (revision 0) +++ gcc/testsuite/gcc.target/arm/ivopts-orig_biv-inc.c (revision 0) @@ -0,0 +1,19 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-tree-ivopts-details" } */ +/* { dg-skip-if "" { arm_thumb1 } } */ + +extern char *__ctype_ptr__; + +unsigned char * foo(unsigned char *ReadPtr) +{ + + unsigned char c; + + while (!(((__ctype_ptr__+sizeof(""[*ReadPtr]))[(int)(*ReadPtr)])&04) == (!(0))) + ReadPtr++; + + return ReadPtr; +} + +/* { dg-final { scan-tree-dump-times "original biv" 2 "ivopts"} } */ +/* { dg-final { cleanup-tree-dump "ivopts" } } */ Index: gcc/tree-ssa-loop-ivopts.c =================================================================== --- gcc/tree-ssa-loop-ivopts.c (revision 200774) +++ gcc/tree-ssa-loop-ivopts.c (working copy) @@ -4876,22 +4876,36 @@ set_autoinc_for_original_candidates (struct ivopts for (i = 0; i < n_iv_cands (data); i++) { struct iv_cand *cand = iv_cand (data, i); - struct iv_use *closest = NULL; + struct iv_use *closest_before = NULL; + struct iv_use *closest_after = NULL; if (cand->pos != IP_ORIGINAL) continue; + for (j = 0; j < n_iv_uses (data); j++) { struct iv_use *use = iv_use (data, j); unsigned uid = gimple_uid (use->stmt); - if (gimple_bb (use->stmt) != gimple_bb (cand->incremented_at) - || uid > gimple_uid (cand->incremented_at)) + + if (gimple_bb (use->stmt) != gimple_bb (cand->incremented_at)) continue; - if (closest == NULL || uid > gimple_uid (closest->stmt)) - closest = use; + + if (uid < gimple_uid (cand->incremented_at) + && (closest_before == NULL + || uid > gimple_uid (closest_before->stmt))) + closest_before = use; + + if (uid > gimple_uid (cand->incremented_at) + && (closest_after == NULL + || uid < gimple_uid (closest_after->stmt))) + closest_after = use; } - if (closest == NULL || !autoinc_possible_for_pair (data, closest, cand)) - continue; - cand->ainc_use = closest; + + if (closest_before != NULL + && autoinc_possible_for_pair (data, closest_before, cand)) + cand->ainc_use = closest_before; + else if (closest_after != NULL + && autoinc_possible_for_pair (data, closest_after, cand)) + cand->ainc_use = closest_after; } }