From patchwork Mon Jul 3 07:35:30 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Sandiford X-Patchwork-Id: 106882 Delivered-To: patch@linaro.org Received: by 10.140.101.44 with SMTP id t41csp5466995qge; Mon, 3 Jul 2017 00:36:57 -0700 (PDT) X-Received: by 10.84.137.1 with SMTP id 1mr9412231plm.128.1499067417515; Mon, 03 Jul 2017 00:36:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1499067417; cv=none; d=google.com; s=arc-20160816; b=fgBui0NuSR9h6xPdJcpBTTgDQ9soiRlNbmEMZr2LFviiyhlbuD4V1fUD+9CRQ7681W jxwRLmP4C0iHV335vOMpBpGT0YtfauXtv5Pt2mo+v9BmmyPRab4+PHIG6j5h96noWbNe prYfwwsx6hrWyE3GLnjyeZDwUTcZDSBZJlctCc0Ovtpn4vlY5dVA8BxyFCyyUqgIk6FL BPGpbk+lvu+GZC5GtZiTSU+RzHDZvaLLImn/1KuNUt70uUFDTJ72zISbPSSMHUXVjwsA 3gBXuA1WZpiKaBd+ww+kEAdJCJsNdfgF6C4FjbReMnHWidVDJbZaZo5BcQqjaQ6GGPKE yG+g== 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=lH8iTNOMk+gQMoYzUSNkGZjH+PRSumufdRzme9C3PbQ=; b=Xdytc351p+WbcdSVVI+YdqCr9eVe4/v9KDTIzeeqhON9hZLvYRKjZN1+J47CYA0Hn9 hxybl0oFf50PjSCap/PSkcKqA8qi9QEgKMQRst5GDhre1pImF/diSfbz2oA59mXnV5x2 M1Pv8RZmxDNc/+3wocOt9LCighwu7qDGJf241jFHZj5Fx0QCD6wgxaRrsXQwtRE4/lUV hR+IVWCtogbt5Ty23B0Gy9u/TdC5ummMlFXIs3BRz2baLRZoPVkVOI89igJpE8qlikHa iuZ8M8vcbP1W1tVTQtHFaHtX5hiKVu+07Db6omfGXDPjFDyuD3RUzF1W+bH852PcyXVJ Da4A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.b=PQGmdJUX; spf=pass (google.com: domain of gcc-patches-return-457410-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-457410-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 s78si11482070pfj.114.2017.07.03.00.36.57 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 03 Jul 2017 00:36:57 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-return-457410-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.b=PQGmdJUX; spf=pass (google.com: domain of gcc-patches-return-457410-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-457410-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=B8uyajUDuq7EksPhUNDvfbltSYgJpDuxPnRw4uN+zi66TWgvAuRL3 95WuorMVwOGNHsMGlFPluwprj3abiskVYOustPXT8MDOlXDBXc0dzOlu/6uR6OGp Y9ZKmTB439g7/WsMkx2AzjGV0qA84IXK3fmb1PewcZ5JuUCwIeqfvw= 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=9FgWBeiSaKsvgyb7yhi2V1Kkuzw=; b=PQGmdJUX5+fUONMZhfWC xkVYkcaMfPPB0LZb3OKUKR5zc+/ShLazbPhVk4TwEQwyBQVYYvFdZvNA9r9ic/+0 CbpjNxoAitYfyYumzA8r8HIl2gP8dsr8jHAmz5o73bWQMF5C4guf7PCOCuvNjrA3 uI4he8zCRV9bDCcd1f7WoRA= Received: (qmail 36829 invoked by alias); 3 Jul 2017 07:36:30 -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 33150 invoked by uid 89); 3 Jul 2017 07:35:36 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-11.0 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-f180.google.com Received: from mail-wr0-f180.google.com (HELO mail-wr0-f180.google.com) (209.85.128.180) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 03 Jul 2017 07:35:34 +0000 Received: by mail-wr0-f180.google.com with SMTP id k67so228962453wrc.2 for ; Mon, 03 Jul 2017 00:35:34 -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=lH8iTNOMk+gQMoYzUSNkGZjH+PRSumufdRzme9C3PbQ=; b=GEmp0HWwDM58C5tEo//thERwmH44w4obtLocYHca3XEbwiI8YsE/B756E5ArxK70MG 8yKuLpsrj/CEihMJRicW1QJnBgP3hOp6qTaRBJDtQMDx3horzB9weyNFnQB3Eh4w2Y14 Nf6HXtDp062mw18VvKscoLa1gRZ7lEDcVJAZpVwiix2uqiQcTUIwYILZ2jJrxxeaw5Bo JYRwzSV6bTE78Laix7oJLnPmOW8zNSL6n19Agdd2KL8uG6rp9Qr28jEzCBDMl3w08w9Q STZSf9/0wSLs+ODzAPNaUPQbFNEEQHYcNTj1DBu5N3KhuHQ9bdF5aWj8CDqrTlvfd9o5 p5jw== X-Gm-Message-State: AKS2vOwYCsWhhN742MSRAF7CNXnRAFUc7OFb3ViIunqkCRpAXlkB9aLd RkWJJNgXvfNxl9B7vBzjnQ== X-Received: by 10.223.139.70 with SMTP id v6mr35898833wra.97.1499067332471; Mon, 03 Jul 2017 00:35:32 -0700 (PDT) Received: from localhost (92.40.248.165.threembb.co.uk. [92.40.248.165]) by smtp.gmail.com with ESMTPSA id 46sm21818991wrz.8.2017.07.03.00.35.31 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 03 Jul 2017 00:35:31 -0700 (PDT) From: Richard Sandiford To: gcc-patches@gcc.gnu.org Mail-Followup-To: gcc-patches@gcc.gnu.org, richard.sandiford@linaro.org Subject: [4/7] Add DR_STEP_ALIGNMENT Date: Mon, 03 Jul 2017 08:35:30 +0100 Message-ID: <87shiex9a5.fsf@linaro.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.2 (gnu/linux) MIME-Version: 1.0 A later patch adds base alignment information to innermost_loop_behavior. After that, the only remaining piece of alignment information that wasn't immediately obvious was the step alignment. Adding that allows a minor simplification to vect_compute_data_ref_alignment, and also potentially improves the handling of variable strides for outer loop vectorisation. A later patch will also use it to give the alignment of the DR as a whole. Tested on aarch64-linux-gnu and x86_64-linux-gnu. OK to install? Richard 2017-07-03 Richard Sandiford gcc/ * tree-data-ref.h (innermost_loop_behavior): Add a step_alignment field. (DR_STEP_ALIGNMENT): New macro. * tree-vectorizer.h (STMT_VINFO_DR_STEP_ALIGNMENT): Likewise. * tree-data-ref.c (dr_analyze_innermost): Initalize step_alignment. (create_data_ref): Print it. * tree-vect-stmts.c (vectorizable_load): Use the step alignment to tell whether the step preserves vector (mis)alignment. * tree-vect-data-refs.c (vect_compute_data_ref_alignment): Likewise. Move the check for an integer step and generalise to all INTEGER_CST. (vect_analyze_data_refs): Set DR_STEP_ALIGNMENT when setting DR_STEP. Print the outer step alignment. Index: gcc/tree-data-ref.h =================================================================== --- gcc/tree-data-ref.h 2017-07-03 07:51:31.005161213 +0100 +++ gcc/tree-data-ref.h 2017-07-03 07:52:14.194782203 +0100 @@ -56,6 +56,9 @@ struct innermost_loop_behavior high value if the offset is zero. This is a byte rather than a bit quantity. */ unsigned int offset_alignment; + + /* Likewise for STEP. */ + unsigned int step_alignment; }; /* Describes the evolutions of indices of the memory reference. The indices @@ -145,6 +148,7 @@ #define DR_INIT(DR) (DR)- #define DR_STEP(DR) (DR)->innermost.step #define DR_PTR_INFO(DR) (DR)->alias.ptr_info #define DR_OFFSET_ALIGNMENT(DR) (DR)->innermost.offset_alignment +#define DR_STEP_ALIGNMENT(DR) (DR)->innermost.step_alignment #define DR_INNERMOST(DR) (DR)->innermost typedef struct data_reference *data_reference_p; Index: gcc/tree-vectorizer.h =================================================================== --- gcc/tree-vectorizer.h 2017-07-03 07:51:31.006161241 +0100 +++ gcc/tree-vectorizer.h 2017-07-03 07:52:14.196782157 +0100 @@ -709,6 +709,8 @@ #define STMT_VINFO_DR_OFFSET(S) #define STMT_VINFO_DR_STEP(S) (S)->dr_wrt_vec_loop.step #define STMT_VINFO_DR_OFFSET_ALIGNMENT(S) \ (S)->dr_wrt_vec_loop.offset_alignment +#define STMT_VINFO_DR_STEP_ALIGNMENT(S) \ + (S)->dr_wrt_vec_loop.step_alignment #define STMT_VINFO_IN_PATTERN_P(S) (S)->in_pattern_p #define STMT_VINFO_RELATED_STMT(S) (S)->related_stmt Index: gcc/tree-data-ref.c =================================================================== --- gcc/tree-data-ref.c 2017-07-03 07:51:31.004161185 +0100 +++ gcc/tree-data-ref.c 2017-07-03 07:52:14.193782226 +0100 @@ -870,6 +870,7 @@ dr_analyze_innermost (struct data_refere drb->init = init; drb->step = step; drb->offset_alignment = highest_pow2_factor (offset_iv.base); + drb->step_alignment = highest_pow2_factor (step); if (dump_file && (dump_flags & TDF_DETAILS)) fprintf (dump_file, "success.\n"); @@ -1085,6 +1086,7 @@ create_data_ref (loop_p nest, loop_p loo print_generic_expr (dump_file, DR_STEP (dr), TDF_SLIM); fprintf (dump_file, "\n\toffset alignment: %d", DR_OFFSET_ALIGNMENT (dr)); + fprintf (dump_file, "\n\tstep alignment: %d", DR_STEP_ALIGNMENT (dr)); fprintf (dump_file, "\n\tbase_object: "); print_generic_expr (dump_file, DR_BASE_OBJECT (dr), TDF_SLIM); fprintf (dump_file, "\n"); Index: gcc/tree-vect-stmts.c =================================================================== --- gcc/tree-vect-stmts.c 2017-07-03 07:51:05.480852682 +0100 +++ gcc/tree-vect-stmts.c 2017-07-03 07:52:14.195782180 +0100 @@ -7294,8 +7294,7 @@ vectorizable_load (gimple *stmt, gimple_ nested within an outer-loop that is being vectorized. */ if (nested_in_vect_loop - && (TREE_INT_CST_LOW (DR_STEP (dr)) - % GET_MODE_SIZE (TYPE_MODE (vectype)) != 0)) + && (DR_STEP_ALIGNMENT (dr) % GET_MODE_SIZE (TYPE_MODE (vectype))) != 0) { gcc_assert (alignment_support_scheme != dr_explicit_realign_optimized); compute_in_loop = true; Index: gcc/tree-vect-data-refs.c =================================================================== --- gcc/tree-vect-data-refs.c 2017-07-03 07:51:31.006161241 +0100 +++ gcc/tree-vect-data-refs.c 2017-07-03 07:52:14.194782203 +0100 @@ -698,10 +698,9 @@ vect_compute_data_ref_alignment (struct divides by the vector size. */ else if (nested_in_vect_loop_p (loop, stmt)) { - tree step = DR_STEP (dr); step_preserves_misalignment_p - = (tree_fits_shwi_p (step) - && tree_to_shwi (step) % GET_MODE_SIZE (TYPE_MODE (vectype)) == 0); + = (DR_STEP_ALIGNMENT (dr) + % GET_MODE_SIZE (TYPE_MODE (vectype))) == 0; if (dump_enabled_p ()) { @@ -720,12 +719,10 @@ vect_compute_data_ref_alignment (struct the dataref evenly divides by the vector size. */ else { - tree step = DR_STEP (dr); unsigned vf = LOOP_VINFO_VECT_FACTOR (loop_vinfo); step_preserves_misalignment_p - = (tree_fits_shwi_p (step) - && ((tree_to_shwi (step) * vf) - % GET_MODE_SIZE (TYPE_MODE (vectype)) == 0)); + = ((DR_STEP_ALIGNMENT (dr) * vf) + % GET_MODE_SIZE (TYPE_MODE (vectype))) == 0; if (!step_preserves_misalignment_p && dump_enabled_p ()) dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location, @@ -773,7 +770,10 @@ vect_compute_data_ref_alignment (struct alignment = TYPE_ALIGN_UNIT (vectype); if (drb->offset_alignment < alignment - || !step_preserves_misalignment_p) + || !step_preserves_misalignment_p + /* We need to know whether the step wrt the vectorized loop is + negative when computing the starting misalignment below. */ + || TREE_CODE (drb->step) != INTEGER_CST) { if (dump_enabled_p ()) { @@ -3414,6 +3414,8 @@ vect_analyze_data_refs (vec_info *vinfo, DR_STEP (newdr) = step; DR_OFFSET_ALIGNMENT (newdr) = BIGGEST_ALIGNMENT; + DR_STEP_ALIGNMENT (newdr) + = highest_pow2_factor (step); dr = newdr; simd_lane_access = true; } @@ -3665,6 +3667,8 @@ vect_analyze_data_refs (vec_info *vinfo, STMT_VINFO_DR_STEP (stmt_info)); dump_printf (MSG_NOTE, "\n\touter offset alignment: %d\n", STMT_VINFO_DR_OFFSET_ALIGNMENT (stmt_info)); + dump_printf (MSG_NOTE, "\n\touter step alignment: %d\n", + STMT_VINFO_DR_STEP_ALIGNMENT (stmt_info)); } }