From patchwork Fri Oct 13 15:04:40 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bin Cheng X-Patchwork-Id: 825513 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-464147-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="KgvCzMmk"; 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 3yD9xP394Gz9s7C for ; Sat, 14 Oct 2017 02:04:57 +1100 (AEDT) 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:cc:subject:date:message-id:content-type:mime-version; q=dns; s=default; b=osWt5VxlFlrG05TUiCA0FHcWBYRh8wzVez+PK84jh5x69zxZ1L oP75tQXqQkeJuRuUOp/nsl02SIgWKUaslqu4I5NzJDZSRtboxeiZAat6NmOROV/Q k0tYNvVsZm59rJy1K2qMYYhZ8kIKLKXmBm9ehPOgb6S+ko3GM1Yq9EFwU= 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:cc:subject:date:message-id:content-type:mime-version; s= default; bh=OJiIxTieQyNPUuPIriLbr6JtOO8=; b=KgvCzMmk698cj0C9eR0l bU/3gPnE4yMUIOZdyozJkkyQvGfC8K35LDYIZU51aUuwk4OVNqvWZZXC/1l5itO8 P/g6TPHjyHMqXl3D+SZdoiggRcYXpt5IUD0OTJjTlyuvRmxSTSTeLxJ+kzH7b1Ya nTTskyU0aFNQAOHsdxkk1NE= Received: (qmail 65857 invoked by alias); 13 Oct 2017 15:04:48 -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 65841 invoked by uid 89); 13 Oct 2017 15:04:47 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-25.8 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS, SPF_PASS autolearn=ham version=3.3.2 spammy= X-HELO: EUR03-VE1-obe.outbound.protection.outlook.com Received: from mail-eopbgr50075.outbound.protection.outlook.com (HELO EUR03-VE1-obe.outbound.protection.outlook.com) (40.107.5.75) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 13 Oct 2017 15:04:43 +0000 Received: from DB5PR0801MB2742.eurprd08.prod.outlook.com (10.166.176.26) by DB5PR0801MB2742.eurprd08.prod.outlook.com (10.166.176.26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.77.7; Fri, 13 Oct 2017 15:04:40 +0000 Received: from DB5PR0801MB2742.eurprd08.prod.outlook.com ([10.166.176.26]) by DB5PR0801MB2742.eurprd08.prod.outlook.com ([10.166.176.26]) with mapi id 15.20.0077.021; Fri, 13 Oct 2017 15:04:40 +0000 From: Bin Cheng To: "gcc-patches@gcc.gnu.org" CC: nd Subject: [PATCH GCC]Try harder to find base object by expanding base address Date: Fri, 13 Oct 2017 15:04:40 +0000 Message-ID: authentication-results: spf=none (sender IP is ) smtp.mailfrom=Bin.Cheng@arm.com; x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1; DB5PR0801MB2742; 6:xLm2UPGHCyse++CYPIXLb7SQDvTnTgDFs7SG+qYRnCc+AQVcmWHIbr7VlPsrhJioaEpZd3ry+75rHxrZQfgX0OSUXN92BLvdiIyA37PsfNWcg7Uv/Fu1KcFmVoHWPYb99Wxv2GhSKiGGo395hCYS98jGb+N9mA0Usa+XiXvWJ/7lYm9XnQBWZiKpzPvjKtp2k4TY1TW3FDfF3DlHwwvlX9B9Jt7VvC3/EPMsgGw3YqNpsVG470VK1hFgWPa67pZ5M5DzJWPx4UntUiE/sTk08c4eSwJqGWTdAdbKD5nn/r87xyR5NyQdK20A3fsDf1MHjY1E0cYU8kni+N0e8DzM9g==; 5:ZSZ7n8QPSg68wI7/SNjlW1L6YQp7SD28pwHvxiVq7ph2UYWWO92v44VEECRmxvYsRcxfauZH2xzdwRpCZxKaDa3E5jRQZSaqUNd2ExwYNPc/9ZsB1ZlyCD/8sENIN6VEwlX08UImXMX7AA3Zw+EWQA==; 24:3Cn6Z4p6yOlrGLYmqUDoyTYESVhCgCreEDd1aV+IofsB8W3ty94CgwJpznDcfWn9upSVmCo9RRjMdUFHe0ezrRIJC+QTd5LwAB3tMhy7hfU=; 7:Z3pPwj4h0dZhjbeYV0/qlF5CGv6Lg8NyavBH14u4SdDg1AZwl9dx4Q3maME944btLDBaJJQBpxovILXbzQ5SOJzMwHn3ZbB1doCwc/ELPHbIRKEG0et+n9rRX6QafARQfbW8ZcLPaL4qbti9ZSY9zChOX2b9C13Rt6vBxDeYBOY4wd+XA7HgcUnegmZZ20CBImwkXKnYnRBEbTvx/ZgXy37fvbwXiGfKEmIq9IGNRlA= x-ms-exchange-antispam-srfa-diagnostics: SSOS; x-ms-office365-filtering-correlation-id: 3e927cd8-bd09-4ecc-59bc-08d5124bba7d x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001)(2017030254152)(48565401081)(2017052603199)(49563074)(201703131423075)(201703031133081)(201702281549075); SRVR:DB5PR0801MB2742; x-ms-traffictypediagnostic: DB5PR0801MB2742: nodisclaimer: True x-exchange-antispam-report-test: UriScan:(180628864354917); x-microsoft-antispam-prvs: x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(100000700101)(100105000095)(100000701101)(100105300095)(100000702101)(100105100095)(102415395)(6040450)(2401047)(8121501046)(5005006)(10201501046)(93006095)(93001095)(3002001)(100000703101)(100105400095)(6055026)(6041248)(20161123562025)(20161123560025)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123558100)(20161123555025)(20161123564025)(6072148)(201708071742011)(100000704101)(100105200095)(100000705101)(100105500095); SRVR:DB5PR0801MB2742; BCL:0; PCL:0; RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095); SRVR:DB5PR0801MB2742; x-forefront-prvs: 04599F3534 x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(6009001)(376002)(346002)(39860400002)(199003)(189002)(377424004)(97736004)(7696004)(6116002)(4326008)(5640700003)(102836003)(53936002)(81166006)(81156014)(3846002)(316002)(2501003)(9686003)(8936002)(4001150100001)(6916009)(99286003)(8676002)(5660300001)(2351001)(189998001)(55016002)(14454004)(105586002)(77096006)(6436002)(3660700001)(101416001)(66066001)(33656002)(6506006)(478600001)(72206003)(2906002)(74316002)(25786009)(3280700002)(68736007)(86362001)(106356001)(7736002)(305945005)(50986999)(2900100001)(54356999)(99936001)(64163002)(34023003)(37363001)(148693002); DIR:OUT; SFP:1101; SCL:1; SRVR:DB5PR0801MB2742; H:DB5PR0801MB2742.eurprd08.prod.outlook.com; FPR:; SPF:None; PTR:InfoNoRecords; A:1; MX:1; LANG:en; received-spf: None (protection.outlook.com: arm.com does not designate permitted sender hosts) spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-originalarrivaltime: 13 Oct 2017 15:04:40.2479 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB5PR0801MB2742 X-IsSubscribed: yes Hi, I ran into this when investigating PR82369 which we failed to find base object. This simple patch tries harder to find base object by expanding base address in alloc_iv. In general, we don't want to do aggressive expansion, but this case is fine because finding base object means reduction happened during the expansion. And it's good to have base object for address type iv_uses. Bootstrap and test on x86_64 and AArch64. Is it OK? Thanks, bin 2017-10-12 Bin Cheng * tree-scalar-evolution.c (alloc_iv): New parameter controlling base expansion for finding base object. (find_interesting_uses_address): Adjust call to alloc_iv. gcc/testsuite 2017-10-12 Bin Cheng * gcc.dg/tree-ssa/ivopt_6.c: New test. diff --git a/gcc/testsuite/gcc.dg/tree-ssa/ivopt_6.c b/gcc/testsuite/gcc.dg/tree-ssa/ivopt_6.c new file mode 100644 index 0000000..de94b88 --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/ivopt_6.c @@ -0,0 +1,23 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-tree-ivopts-details" } */ + +typedef unsigned long int uintptr_t; +typedef long unsigned int size_t; +typedef long int ptrdiff_t; + +void foo (unsigned char *restrict dst, unsigned char *restrict src, size_t bytes) +{ + uintptr_t end_dst = (uintptr_t) (dst + bytes); + uintptr_t srcu = (uintptr_t) src, dstu = (uintptr_t) dst; + ptrdiff_t src_dst_offset = srcu - 2 * dstu; + + do { + unsigned char v0 = *(unsigned char *) (dstu * 2 + src_dst_offset); + unsigned char v1 = *(unsigned char *) ((dstu * 2 + src_dst_offset) + 1); + unsigned char res = v1 + v0; + + *((unsigned char*) dstu) = res; + dstu += 16; + } while (dstu < end_dst); +} +/* { dg-final { scan-tree-dump-times "Type:\tADDRESS" 3 "ivopts" } } */ diff --git a/gcc/tree-ssa-loop-ivopts.c b/gcc/tree-ssa-loop-ivopts.c index bbea619..4ccdf32 100644 --- a/gcc/tree-ssa-loop-ivopts.c +++ b/gcc/tree-ssa-loop-ivopts.c @@ -1160,11 +1160,12 @@ contain_complex_addr_expr (tree expr) } /* Allocates an induction variable with given initial value BASE and step STEP - for loop LOOP. NO_OVERFLOW implies the iv doesn't overflow. */ + for loop LOOP. NO_OVERFLOW implies the iv doesn't overflow. If EXPAND_P + is true, this function expands base address to find base object. */ static struct iv * alloc_iv (struct ivopts_data *data, tree base, tree step, - bool no_overflow = false) + bool no_overflow = false, bool expand_p = false) { tree expr = base; struct iv *iv = (struct iv*) obstack_alloc (&data->iv_obstack, @@ -1185,8 +1186,22 @@ alloc_iv (struct ivopts_data *data, tree base, tree step, base = fold_convert (TREE_TYPE (base), aff_combination_to_tree (&comb)); } + tree base_object = determine_base_object (base); + /* Try harder to find base object by expanding base. */ + if (expand_p && base_object == NULL_TREE) + { + aff_tree comb; + expr = unshare_expr (base); + tree_to_aff_combination_expand (base, TREE_TYPE (base), &comb, + &data->name_expansion_cache); + base = fold_convert (TREE_TYPE (base), aff_combination_to_tree (&comb)); + base_object = determine_base_object (base); + /* Fall back to unexpanded base if no base object is found. */ + if (!base_object) + base = expr; + } iv->base = base; - iv->base_object = determine_base_object (base); + iv->base_object = base_object; iv->step = step; iv->biv_p = false; iv->nonlin_use = NULL; @@ -2365,7 +2380,7 @@ find_interesting_uses_address (struct ivopts_data *data, gimple *stmt, } } - civ = alloc_iv (data, base, step); + civ = alloc_iv (data, base, step, false, true); /* Fail if base object of this memory reference is unknown. */ if (civ->base_object == NULL_TREE) goto fail;