From patchwork Sat Mar 17 10:45:22 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Sandiford X-Patchwork-Id: 131972 Delivered-To: patch@linaro.org Received: by 10.46.84.17 with SMTP id i17csp516960ljb; Sat, 17 Mar 2018 03:46:13 -0700 (PDT) X-Google-Smtp-Source: AG47ELv/UZt0T+YCSy2qXbBvUYq5CIbKDomzpsRbfqkL8uTjOwlKgdv1PBkwrEfhAqTH8Mk2RZe3 X-Received: by 2002:a17:902:a70f:: with SMTP id w15-v6mr5274097plq.79.1521283573291; Sat, 17 Mar 2018 03:46:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521283573; cv=none; d=google.com; s=arc-20160816; b=dvzUoaNKZrqXK+HolyuEy2BWvXBzDeI+iXhA2XgnCWEKE1kU4C45RhyPUuiawR9Q3q OcgICjPVcQ/V34cK5n1HuZ/p7vaQnkpns7+Wqq3PW/zHipr6sbdF0GKkh1ERM7yfekrc GTpfHSWJI4OxmMl2i0cUTz5vtdROyuhpP7R/l4qjlI1usIoI7bsn488xCbpb7EsEN0Me Rjv6ImucjrLdYd8JWu0N/8jYtzMHguldfluXLUdh64f4fHRSxuamQeRHCdlCgMtyXlYn kfBV2lT4/ziH7KzmzM4/SMmMbMoSItOwf6wliDLhYIq4zf29rTTAeu61QlP20E1JzjTo JCYA== 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=iDCv6V7A8EHRgykLlUJfSJRis0VQpNkSGRv8pPjtD0M=; b=iACKIHubZwpuVQ0vW3rMoBU4TjYiVaMoEPnl9QsGocaZtLNz3kk1yDCLc8nnirwsmR Ww/B+0RzrTOzQtc/Kd9xGTL7Afx0YgPyd7U3R93acqXN7L2HnKQ/7yc+EWZr7dWNRZk4 kmZ/i48t+xsY5Vgqhzpl4O5/1VSG3NRTRC9in2joE4L5j/P+K9iUcuRrCc/0FU38TVqq okGUjEtOr/IlLDyXRo1SHhjl5pPCZ5Whi+tDZ0UWA9gjMogRlL6bypYKC0tRHuCi+LDs JMzT93hfPBkfTroS2Ly3w90i7TmCplfTLGv0wQ7IfWy80NjXLBD4EMeypFBrOl+lZhXK uZqQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=Cx9T0gvD; spf=pass (google.com: domain of gcc-patches-return-474900-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-474900-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 t12si6631408pgo.153.2018.03.17.03.46.12 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 17 Mar 2018 03:46:13 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-return-474900-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=Cx9T0gvD; spf=pass (google.com: domain of gcc-patches-return-474900-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-474900-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=BzLmBr9LtFK9mtYSRLd+WGSaYHMTE2teJKW7Kay0CtkLYd788LTuN RTtG/r650r+OTEbImoDFZs5PKRrukYT7Nuct9UfpFgUgrqTrV537AzUrdc49tFcF kXYePoRx3iwgjva3P+7TiFbknD2BP9/5HvGYGDADK6ofpVjziU7MGk= 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=nv5ZJ+CjNDlufRaOVNa6p0wTMFQ=; b=Cx9T0gvDPnjf7tArNhd8 O8bPituJuSKGXjcsogFh8GwqX9ocALOEOr9Azul5q+zWNY7oqvkMp9Q0NglVjKI0 18Gdsv1JcFtUTd/Er2KLFi3039iaNlzeCc+6WrumMS27boPbHv6PERZM0ghf8Oe7 xnfjrORslRS/XldElwAiWMs= Received: (qmail 96451 invoked by alias); 17 Mar 2018 10:46:01 -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 96358 invoked by uid 89); 17 Mar 2018 10:45:49 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-11.1 required=5.0 tests=BAYES_00, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_NONE, SPF_PASS, TIME_LIMIT_EXCEEDED autolearn=unavailable version=3.3.2 spammy=achievable, Hx-languages-length:5987 X-HELO: mail-wr0-f170.google.com Received: from mail-wr0-f170.google.com (HELO mail-wr0-f170.google.com) (209.85.128.170) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sat, 17 Mar 2018 10:45:32 +0000 Received: by mail-wr0-f170.google.com with SMTP id l8so13956892wrg.5 for ; Sat, 17 Mar 2018 03:45:26 -0700 (PDT) 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=iDCv6V7A8EHRgykLlUJfSJRis0VQpNkSGRv8pPjtD0M=; b=Szyt2cxd+eKbfPW8vLvUG22inpnHogU+2aNWMZrVxA/X7kQcR/GuvCR60AYY29cEV5 aTrEpSbdQva54cdt4IlfB6HgCc6ZT35rCVbjlVkmGmOiaqiofpchAG7FJHQxLTUEosBC 6689Lf5wDQ1wvceV74q1y42SSMwkouOpqfm6hwltyAuZCRfNkUUqd8yzvwqts9oZE3W8 KFc5MCHOKHCnfLV4rWL/AsDhz8C0VuelIpqWLbpU0GrqE2+bg9aGpbpbzmuwrP9lBi3X TL9YvVsrGcqk5dMWrtZV/7cvCCo6D4APy750RWbne2i3s7QzIfgACapF13smWq+MPzNU 5/cQ== X-Gm-Message-State: AElRT7GC0PhwmnsWaw/dfymdKy966Cp2FJe2lzqjDLva/8E8dnirGmEM 3xwovNligRh8FqBE61R1aksBRSZ/doQ= X-Received: by 10.223.201.142 with SMTP id f14mr4349988wrh.40.1521283524112; Sat, 17 Mar 2018 03:45:24 -0700 (PDT) Received: from localhost (79.58.7.51.dyn.plus.net. [51.7.58.79]) by smtp.gmail.com with ESMTPSA id p78sm11209751wmg.47.2018.03.17.03.45.22 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sat, 17 Mar 2018 03:45:23 -0700 (PDT) From: Richard Sandiford To: gcc-patches@gcc.gnu.org Mail-Followup-To: gcc-patches@gcc.gnu.org, richard.sandiford@linaro.org Subject: Use SCEV information when aligning for vectorisation (PR 84005) Date: Sat, 17 Mar 2018 10:45:22 +0000 Message-ID: <871sgj0ym5.fsf@linaro.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.3 (gnu/linux) MIME-Version: 1.0 This PR is another regression caused by the removal of the simple_iv check in dr_analyze_innermost for BB analysis. Without splitting out the step, we weren't able to find an underlying object whose alignment could be increased. As with PR81635, I think the simple_iv was only handling one special case of something that ought to be more general. The more general thing here is that if the address can be analysed as a scalar evolution, and if all updates preserve alignment N, it's possible to align the address to N by increasing the alignment of the base object to N. That applies also to outer loops, and to both loop and BB analysis. I wasn't sure where the new functions ought to live, but tree-data-ref.c seemed OK since (a) that already does scev analysis on addresses and (b) you'd want to use dr_analyze_innermost first if you were analysing a reference. Tested on aarch64-linux-gnu and x86_64-linux-gnu. OK to install? Richard 2018-03-17 Richard Sandiford gcc/ PR tree-optimization/84005 * tree-data-ref.h (get_base_for_alignment): Declare. * tree-data-ref.c (get_base_for_alignment_1): New function. (get_base_for_alignment): Likewise. * tree-vect-data-refs.c (vect_compute_data_ref_alignment): Use get_base_for_alignment to find a suitable base object, instead of always using drb->base_address. gcc/testsuite/ PR tree-optimization/84005 * gcc.dg/vect/bb-slp-1.c: Make sure there is no message about failing to force the alignment. Index: gcc/tree-data-ref.h =================================================================== --- gcc/tree-data-ref.h 2018-01-13 18:02:00.948360274 +0000 +++ gcc/tree-data-ref.h 2018-03-17 10:43:42.544669549 +0000 @@ -463,6 +463,7 @@ extern bool compute_all_dependences (vec extern tree find_data_references_in_bb (struct loop *, basic_block, vec *); extern unsigned int dr_alignment (innermost_loop_behavior *); +extern tree get_base_for_alignment (tree, unsigned int *); /* Return the alignment in bytes that DR is guaranteed to have at all times. */ Index: gcc/tree-data-ref.c =================================================================== --- gcc/tree-data-ref.c 2018-02-14 13:14:36.268006810 +0000 +++ gcc/tree-data-ref.c 2018-03-17 10:43:42.544669549 +0000 @@ -5200,6 +5200,75 @@ dr_alignment (innermost_loop_behavior *d return alignment; } +/* If BASE is a pointer-typed SSA name, try to find the object that it + is based on. Return this object X on success and store the alignment + in bytes of BASE - &X in *ALIGNMENT_OUT. */ + +static tree +get_base_for_alignment_1 (tree base, unsigned int *alignment_out) +{ + if (TREE_CODE (base) != SSA_NAME || !POINTER_TYPE_P (TREE_TYPE (base))) + return NULL_TREE; + + gimple *def = SSA_NAME_DEF_STMT (base); + base = analyze_scalar_evolution (loop_containing_stmt (def), base); + + /* Peel chrecs and record the minimum alignment preserved by + all steps. */ + unsigned int alignment = MAX_OFILE_ALIGNMENT / BITS_PER_UNIT; + while (TREE_CODE (base) == POLYNOMIAL_CHREC) + { + unsigned int step_alignment = highest_pow2_factor (CHREC_RIGHT (base)); + alignment = MIN (alignment, step_alignment); + base = CHREC_LEFT (base); + } + + /* Punt if the expression is too complicated to handle. */ + if (tree_contains_chrecs (base, NULL) || !POINTER_TYPE_P (TREE_TYPE (base))) + return NULL_TREE; + + /* Analyze the base to which the steps we peeled were applied. */ + poly_int64 bitsize, bitpos, bytepos; + machine_mode mode; + int unsignedp, reversep, volatilep; + tree offset; + base = get_inner_reference (build_fold_indirect_ref (base), + &bitsize, &bitpos, &offset, &mode, + &unsignedp, &reversep, &volatilep); + if (!base || !multiple_p (bitpos, BITS_PER_UNIT, &bytepos)) + return NULL_TREE; + + /* Restrict the alignment to that guaranteed by the offsets. */ + unsigned int bytepos_alignment = known_alignment (bytepos); + if (bytepos_alignment != 0) + alignment = MIN (alignment, bytepos_alignment); + if (offset) + { + unsigned int offset_alignment = highest_pow2_factor (offset); + alignment = MIN (alignment, offset_alignment); + } + + *alignment_out = alignment; + return base; +} + +/* Return the object whose alignment would need to be changed in order + to increase the alignment of ADDR. Store the maximum achievable + alignment in *MAX_ALIGNMENT. */ + +tree +get_base_for_alignment (tree addr, unsigned int *max_alignment) +{ + tree base = get_base_for_alignment_1 (addr, max_alignment); + if (base) + return base; + + if (TREE_CODE (addr) == ADDR_EXPR) + addr = TREE_OPERAND (addr, 0); + *max_alignment = MAX_OFILE_ALIGNMENT / BITS_PER_UNIT; + return addr; +} + /* Recursive helper function. */ static bool Index: gcc/tree-vect-data-refs.c =================================================================== --- gcc/tree-vect-data-refs.c 2018-03-02 09:45:40.478265383 +0000 +++ gcc/tree-vect-data-refs.c 2018-03-17 10:43:42.544669549 +0000 @@ -957,11 +957,11 @@ vect_compute_data_ref_alignment (struct if (base_alignment < vector_alignment) { - tree base = drb->base_address; - if (TREE_CODE (base) == ADDR_EXPR) - base = TREE_OPERAND (base, 0); - if (!vect_can_force_dr_alignment_p (base, - vector_alignment * BITS_PER_UNIT)) + unsigned int max_alignment; + tree base = get_base_for_alignment (drb->base_address, &max_alignment); + if (max_alignment < vector_alignment + || !vect_can_force_dr_alignment_p (base, + vector_alignment * BITS_PER_UNIT)) { if (dump_enabled_p ()) { Index: gcc/testsuite/gcc.dg/vect/bb-slp-1.c =================================================================== --- gcc/testsuite/gcc.dg/vect/bb-slp-1.c 2017-11-09 15:15:06.846650880 +0000 +++ gcc/testsuite/gcc.dg/vect/bb-slp-1.c 2018-03-17 10:43:42.541669742 +0000 @@ -54,5 +54,5 @@ int main (void) return 0; } +/* { dg-final { scan-tree-dump-not "can't force alignment" "slp1" } } */ /* { dg-final { scan-tree-dump-times "basic block vectorized" 1 "slp1" } } */ -