From patchwork Wed Feb 14 09:44:10 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Sandiford X-Patchwork-Id: 128327 Delivered-To: patch@linaro.org Received: by 10.46.124.24 with SMTP id x24csp417168ljc; Wed, 14 Feb 2018 01:44:29 -0800 (PST) X-Google-Smtp-Source: AH8x2274tJICjj7qUh0A56F2X2T9mFJ0Fwil8aSgsFMzAsD3rpKTsDewDncm04hfjBGRDMiMbtE7 X-Received: by 2002:a17:902:62:: with SMTP id 89-v6mr3961926pla.178.1518601469499; Wed, 14 Feb 2018 01:44:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518601469; cv=none; d=google.com; s=arc-20160816; b=Dt5TApXk223F2B+Vw/VA8vlLGCv+GiKjcwZkpCzHli+8LIxG28Fnkssh9BhS29Wzs9 N8bJLLN2NuhGiXHNtWmr7iRADakrbxsBnqnDt98juVFJqCXjyzXJzYX7Y7l3ATGP39WA UMhZlyZO1sW7jXQ+JgyEF+0ZuKXyHVof4TcyNTLdPWQEJ0K+OVOtwJEjvHr4J/NFrKuS pN/pyX2/HA8+7Rd6/SjZ23n6/Vp6HuaMAaHEpnHVdbe/hzIPTF77H9o6am5qggf9d/FN xVVBxs9tcLYYGur5EJ0yWZDsD2HKUu95rt/TMoAfGDQKsJwobjIFev9nbjgwVbGvgJLz lGnA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:user-agent:message-id:date:subject:mail-followup-to:to :from:delivered-to:sender:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:mailing-list:dkim-signature :domainkey-signature:arc-authentication-results; bh=iGDbf+ZPYM447W4Fmjq//o3z3B+q8IZ3qkAMm90xeBs=; b=od3BdMuyTbu76G1hJYmpaUqBU2SVANlTxHmPLIIoDyy8BtcuQDCqnSl9Eqf5GCJS2v TYA3WWLgh+MwgxE4OviSCtN7Vv5CQdPNB1fvNBBsMtRjMT1+b0fbiSGxle8kfV1ziNVP oxIxD8jRdbx/6ndXKPsH5Z3zG/ZBRrJsNEtiRHDQkgtIILhsYUXNO27X9QAsxlR37o2E IHnhu8h1asKQ13pMs6tCK5ZUu70To0WqxV0aHuq4caXQtjy9nhHsxxyPg6pdiHNAVw4c izcYk5OoDZvSHshx6SWNpWHNiBM2WkloDssv6QGjG1dUQwYzumHGjQA6jAAWoMKICX8B kReg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=PChPuav7; spf=pass (google.com: domain of gcc-patches-return-473250-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-473250-patch=linaro.org@gcc.gnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id v4si4573457pgt.331.2018.02.14.01.44.29 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 14 Feb 2018 01:44:29 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-return-473250-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=PChPuav7; spf=pass (google.com: domain of gcc-patches-return-473250-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-473250-patch=linaro.org@gcc.gnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org 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=mB1S3T6vBAT6SUL11TkSv/4ACAfyF8uGiPXHbCoVr/F794B+ieJkB HSbf5Gp3yzAOSR4mVTNc/GmPVw/0sEH9afTAF7o26eH6UFezKSZUkShs+GaimlaU 53AVVtI+pF0GxW/q0WqiTZ2wcDo9VAfXdEj+nnwfB7+d9sJ7h6lLPY= 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=3npmovLzntCLO5HNFZ/LVCSovJU=; b=PChPuav758cP3seJdyvm aW4J6uwM05jCf4b/H4GgLMlUF5SZb9PljznNOzSJEm6eCxst3IhMD5TfRUhigD6l RcEeqbQ31i/CTG6TOEDeTmC15TuvN8R1RlelRUkXS47csOEgGfsdMxxjK6ZyzRfs 0j4WYBQU1kNZlSuC3d7bVtg= Received: (qmail 11351 invoked by alias); 14 Feb 2018 09:44:18 -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 11340 invoked by uid 89); 14 Feb 2018 09:44:16 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-11.1 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy= X-HELO: mail-wr0-f171.google.com Received: from mail-wr0-f171.google.com (HELO mail-wr0-f171.google.com) (209.85.128.171) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 14 Feb 2018 09:44:14 +0000 Received: by mail-wr0-f171.google.com with SMTP id 34so11196531wre.13 for ; Wed, 14 Feb 2018 01:44:14 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:mail-followup-to:subject:date:message-id :user-agent:mime-version; bh=iGDbf+ZPYM447W4Fmjq//o3z3B+q8IZ3qkAMm90xeBs=; b=nuBbuFIpJgFEv7A68Uvt80ULHwfQ2ALKMTxtnEGZOZgalXdJH6kj/kkd7ic0FQeHhW jPtY7VPJ/qdb9MqMIx/R2NY+KS8UUJMmWadoLA5tegCV975osCCbL7PFdWYPWFX8sgb7 IMat6XYvs6uIDcHC7geTC9xaYdptWW/GB3xe55AX3AW4CAH3ZwtSpjdQoBd6rGGaRG/2 CXiluZXiEmNFFgdQR9p1KaUa0enoipBlYWPqSCWzfmDAkDTis9vuPjiO60nMg/T+0iNe Xh8qll/4VfhJHzPVoq+yFFTEZGensoaQN7q6B1Fd3H8wHr9OgiCAeZ2ckvzV+wWWlQC3 614w== X-Gm-Message-State: APf1xPAQ18zkii0tvOVhau2441DHk5TmFl7tiA1NIKTrZ4U0wHBygjdE BVjOB+jDH+oqGzkM6P+8p/RKS6nzwo4= X-Received: by 10.223.193.65 with SMTP id w1mr4110366wre.88.1518601452512; Wed, 14 Feb 2018 01:44:12 -0800 (PST) Received: from localhost ([95.144.14.158]) by smtp.gmail.com with ESMTPSA id z73sm25399447wrb.50.2018.02.14.01.44.10 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 14 Feb 2018 01:44:11 -0800 (PST) From: Richard Sandiford To: gcc-patches@gcc.gnu.org Mail-Followup-To: gcc-patches@gcc.gnu.org, richard.sandiford@linaro.org Subject: Check array indices in object_address_invariant_in_loop_p (PR 84357) Date: Wed, 14 Feb 2018 09:44:10 +0000 Message-ID: <87eflnc3dh.fsf@linaro.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.3 (gnu/linux) MIME-Version: 1.0 object_address_invariant_in_loop_p ignored ARRAY_REF indices on the basis that: /* Index of the ARRAY_REF was zeroed in analyze_indices, thus we only need to check the stride and the lower bound of the reference. */ That was true back in 2007 when the code was added: static void dr_analyze_indices (struct data_reference *dr, struct loop *nest) { [...] while (handled_component_p (aref)) { if (TREE_CODE (aref) == ARRAY_REF) { op = TREE_OPERAND (aref, 1); access_fn = analyze_scalar_evolution (loop, op); access_fn = resolve_mixers (nest, access_fn); VEC_safe_push (tree, heap, access_fns, access_fn); TREE_OPERAND (aref, 1) = build_int_cst (TREE_TYPE (op), 0); } aref = TREE_OPERAND (aref, 0); } but the assignment was removed a few years ago. We were therefore treating "two->arr[i]" and "three->arr[i]" as loop invariant. Tested on aarch64-linux-gnu, x86_64-linux-gnu and powerpc64le-linux-gnu. OK to install? Richard 2018-02-14 Richard Sandiford gcc/ PR tree-optimization/84357 * tree-data-ref.c (object_address_invariant_in_loop_p): Check operand 1 of an ARRAY_REF too. gcc/testsuite/ PR tree-optimization/84357 * gcc.dg/vect/pr84357.c: New test. Index: gcc/tree-data-ref.c =================================================================== --- gcc/tree-data-ref.c 2018-02-08 15:16:21.784407397 +0000 +++ gcc/tree-data-ref.c 2018-02-14 09:42:14.801095011 +0000 @@ -2200,13 +2200,10 @@ object_address_invariant_in_loop_p (cons { if (TREE_CODE (obj) == ARRAY_REF) { - /* Index of the ARRAY_REF was zeroed in analyze_indices, thus we only - need to check the stride and the lower bound of the reference. */ - if (chrec_contains_symbols_defined_in_loop (TREE_OPERAND (obj, 2), - loop->num) - || chrec_contains_symbols_defined_in_loop (TREE_OPERAND (obj, 3), - loop->num)) - return false; + for (int i = 1; i < 4; ++i) + if (chrec_contains_symbols_defined_in_loop (TREE_OPERAND (obj, i), + loop->num)) + return false; } else if (TREE_CODE (obj) == COMPONENT_REF) { Index: gcc/testsuite/gcc.dg/vect/pr84357.c =================================================================== --- /dev/null 2018-02-10 09:05:46.714416790 +0000 +++ gcc/testsuite/gcc.dg/vect/pr84357.c 2018-02-14 09:42:14.800095067 +0000 @@ -0,0 +1,31 @@ +/* { dg-do compile } */ +/* { dg-additional-options "-Wall" } */ + +#define COUNT 32 + +typedef struct s1 { + unsigned char c; +} s1; + +typedef struct s2 +{ + char pad; + s1 arr[COUNT]; +} s2; + +typedef struct s3 { + s1 arr[COUNT]; +} s3; + +s2 * get_s2(); +s3 * gActiveS3; +void foo() +{ + s3 * three = gActiveS3; + s2 * two = get_s2(); + + for (int i = 0; i < COUNT; i++) + { + two->arr[i].c = three->arr[i].c; + } +}