From patchwork Wed May 3 07:54:06 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Sandiford X-Patchwork-Id: 98470 Delivered-To: patch@linaro.org Received: by 10.140.89.200 with SMTP id v66csp177471qgd; Wed, 3 May 2017 00:54:31 -0700 (PDT) X-Received: by 10.98.68.8 with SMTP id r8mr3365236pfa.168.1493798071826; Wed, 03 May 2017 00:54:31 -0700 (PDT) Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id a81si1902048pfk.196.2017.05.03.00.54.31 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 03 May 2017 00:54:31 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-return-452659-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; spf=pass (google.com: domain of gcc-patches-return-452659-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-452659-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=o31FEqCAz0wB6or/ZdjMjViIvyFwhWTukRqBzzC3xm6XSFeKOxoTd JJeFonWMvXNzx0LwTgnibxce3r+aORTsNkKhHiHn7S93iSp4PL5ivNWXnrLPhOWj PtqGe2U9Vn/fQ6gGABMFaFqCQg4YLY7YtN68pCMP8DQXGirXfmBqcY= 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=F4ITGn6quNkGlj+dv6f2LBtG/M8=; b=GepMW8NlAEfXid8z3xUj RVjHIAPqrWT3PiVq7yjteWG5LaxrRgcgC/Xde90PlcGQiDPyx1JmZLOmZ7WPt0br yaK0qkLoSOhD8UXRbOYFLOQbV9FlWyvAAfqmU2KirVay6V9dBSX16iiCXFadvR3Y /0aQ5tgqSgXpggbxY2QyCA4= Received: (qmail 80338 invoked by alias); 3 May 2017 07:54:14 -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 80303 invoked by uid 89); 3 May 2017 07:54:12 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-10.7 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_NONE, RCVD_IN_SORBS_SPAM, SPF_PASS autolearn=ham version=3.3.2 spammy=divided, dist, drs, principle X-HELO: mail-wr0-f173.google.com Received: from mail-wr0-f173.google.com (HELO mail-wr0-f173.google.com) (209.85.128.173) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 03 May 2017 07:54:11 +0000 Received: by mail-wr0-f173.google.com with SMTP id w50so99640487wrc.0 for ; Wed, 03 May 2017 00:54:13 -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=tzoCy+PzBIVekK3/Edjji5vfISUYy2MHk8hkIkD5FME=; b=dLxil0EjNbEudI2vlPP+vSCx64SPtTxAwOwPKcZPMufCjax7odMjinswItxyoqLZ5e OPaOe7SgH1Rsj4yv9ezucka0vK7uCpih3aU+bENHTLNZDYbtM6ahfgO/ylyD/NKDgJBG lvYf0cSWVbZDGLaFR4VKcpI7NUSfLwVRX6Wu3aRJ82uPu+nUXOSXvn+RIkSZPoXSSPKC Etpbt5RS5XjZVGysF0jIjS9pcBqCan69FZ4o9i+oMlW1S8kGiVX9TKTMXb5uZOqcCKmd YNNXCX8n0BhnMN2CYv11IcXT7VGsUQLL87kuoo7RC3t4tqo9gfySGVUIYY87m88HGA2r 4MmQ== X-Gm-Message-State: AN3rC/6Z1Hk1Mht26e5UeDjFxCm5ztHaTzDJBwT3WzJCeADSrIfmwDPb VFTqRa+vRItPvk7J0P1dqg== X-Received: by 10.223.131.130 with SMTP id 2mr22311342wre.104.1493798051012; Wed, 03 May 2017 00:54:11 -0700 (PDT) Received: from localhost (94.197.120.23.threembb.co.uk. [94.197.120.23]) by smtp.gmail.com with ESMTPSA id m185sm3174592wma.7.2017.05.03.00.54.09 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 03 May 2017 00:54:10 -0700 (PDT) From: Richard Sandiford To: gcc-patches@gcc.gnu.org Mail-Followup-To: gcc-patches@gcc.gnu.org, richard.sandiford@linaro.org Subject: Alternative check for vector refs with same alignment Date: Wed, 03 May 2017 08:54:06 +0100 Message-ID: <87zieus7dt.fsf@linaro.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1 (gnu/linux) MIME-Version: 1.0 vect_find_same_alignment_drs uses the ddr dependence distance to tell whether two references have the same alignment. Although that's safe with the current code, there's no particular reason why a dependence distance of 0 should mean that the accesses start on the same byte. E.g. a reference to a full complex value could in principle depend on a reference to the imaginary component. A later patch adds support for this kind of dependence. On the other side, checking modulo vf is pessimistic when the step divided by the element size is a factor of 2. This patch instead looks for cases in which the drs have the same base, offset and step, and for which the difference in their constant initial values is a multiple of the alignment. Tested on aarch64-linux-gnu and x86_64-linux-gnu. OK to install? Thanks, Richard gcc/ 2017-05-03 Richard Sandiford * tree-vect-data-refs.c (vect_find_same_alignment_drs): Remove loop_vinfo argument and use of dependence distance vectors. Check instead whether the two references differ only in their initial value and assume that they have the same alignment if the difference is a multiple of the vector alignment. (vect_analyze_data_refs_alignment): Update call accordingly. gcc/testsuite/ * gcc.dg/vect/vect-103.c: Update wording of dump message. Index: gcc/tree-vect-data-refs.c =================================================================== --- gcc/tree-vect-data-refs.c 2017-04-18 19:52:35.060164268 +0100 +++ gcc/tree-vect-data-refs.c 2017-05-03 08:48:30.536704993 +0100 @@ -2042,20 +2042,12 @@ vect_enhance_data_refs_alignment (loop_v vectorization factor. */ static void -vect_find_same_alignment_drs (struct data_dependence_relation *ddr, - loop_vec_info loop_vinfo) +vect_find_same_alignment_drs (struct data_dependence_relation *ddr) { - unsigned int i; - struct loop *loop = LOOP_VINFO_LOOP (loop_vinfo); - int vectorization_factor = LOOP_VINFO_VECT_FACTOR (loop_vinfo); struct data_reference *dra = DDR_A (ddr); struct data_reference *drb = DDR_B (ddr); stmt_vec_info stmtinfo_a = vinfo_for_stmt (DR_STMT (dra)); stmt_vec_info stmtinfo_b = vinfo_for_stmt (DR_STMT (drb)); - int dra_size = GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (DR_REF (dra)))); - int drb_size = GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (DR_REF (drb)))); - lambda_vector dist_v; - unsigned int loop_depth; if (DDR_ARE_DEPENDENT (ddr) == chrec_known) return; @@ -2063,48 +2055,37 @@ vect_find_same_alignment_drs (struct dat if (dra == drb) return; - if (DDR_ARE_DEPENDENT (ddr) == chrec_dont_know) - return; - - /* Loop-based vectorization and known data dependence. */ - if (DDR_NUM_DIST_VECTS (ddr) == 0) - return; - - /* Data-dependence analysis reports a distance vector of zero - for data-references that overlap only in the first iteration - but have different sign step (see PR45764). - So as a sanity check require equal DR_STEP. */ - if (!operand_equal_p (DR_STEP (dra), DR_STEP (drb), 0)) + if (!operand_equal_p (DR_BASE_OBJECT (dra), DR_BASE_OBJECT (drb), + OEP_ADDRESS_OF) + || !operand_equal_p (DR_OFFSET (dra), DR_OFFSET (drb), 0) + || !operand_equal_p (DR_STEP (dra), DR_STEP (drb), 0)) return; - loop_depth = index_in_loop_nest (loop->num, DDR_LOOP_NEST (ddr)); - FOR_EACH_VEC_ELT (DDR_DIST_VECTS (ddr), i, dist_v) + /* Two references with distance zero have the same alignment. */ + offset_int diff = (wi::to_offset (DR_INIT (dra)) + - wi::to_offset (DR_INIT (drb))); + if (diff != 0) { - int dist = dist_v[loop_depth]; + /* Get the wider of the two alignments. */ + unsigned int align_a = TYPE_ALIGN_UNIT (STMT_VINFO_VECTYPE (stmtinfo_a)); + unsigned int align_b = TYPE_ALIGN_UNIT (STMT_VINFO_VECTYPE (stmtinfo_b)); + unsigned int max_align = MAX (align_a, align_b); + + /* Require the gap to be a multiple of the larger vector alignment. */ + if (!wi::multiple_of_p (diff, max_align, SIGNED)) + return; + } - if (dump_enabled_p ()) - dump_printf_loc (MSG_NOTE, vect_location, - "dependence distance = %d.\n", dist); - - /* Same loop iteration. */ - if (dist == 0 - || (dist % vectorization_factor == 0 && dra_size == drb_size)) - { - /* Two references with distance zero have the same alignment. */ - STMT_VINFO_SAME_ALIGN_REFS (stmtinfo_a).safe_push (drb); - STMT_VINFO_SAME_ALIGN_REFS (stmtinfo_b).safe_push (dra); - if (dump_enabled_p ()) - { - dump_printf_loc (MSG_NOTE, vect_location, - "accesses have the same alignment.\n"); - dump_printf (MSG_NOTE, - "dependence distance modulo vf == 0 between "); - dump_generic_expr (MSG_NOTE, TDF_SLIM, DR_REF (dra)); - dump_printf (MSG_NOTE, " and "); - dump_generic_expr (MSG_NOTE, TDF_SLIM, DR_REF (drb)); - dump_printf (MSG_NOTE, "\n"); - } - } + STMT_VINFO_SAME_ALIGN_REFS (stmtinfo_a).safe_push (drb); + STMT_VINFO_SAME_ALIGN_REFS (stmtinfo_b).safe_push (dra); + if (dump_enabled_p ()) + { + dump_printf_loc (MSG_NOTE, vect_location, + "accesses have the same alignment: "); + dump_generic_expr (MSG_NOTE, TDF_SLIM, DR_REF (dra)); + dump_printf (MSG_NOTE, " and "); + dump_generic_expr (MSG_NOTE, TDF_SLIM, DR_REF (drb)); + dump_printf (MSG_NOTE, "\n"); } } @@ -2128,7 +2109,7 @@ vect_analyze_data_refs_alignment (loop_v unsigned int i; FOR_EACH_VEC_ELT (ddrs, i, ddr) - vect_find_same_alignment_drs (ddr, vinfo); + vect_find_same_alignment_drs (ddr); vec datarefs = vinfo->datarefs; struct data_reference *dr; Index: gcc/testsuite/gcc.dg/vect/vect-103.c =================================================================== --- gcc/testsuite/gcc.dg/vect/vect-103.c 2015-06-02 23:53:38.000000000 +0100 +++ gcc/testsuite/gcc.dg/vect/vect-103.c 2017-05-03 08:48:30.536704993 +0100 @@ -55,5 +55,5 @@ int main (void) } /* { dg-final { scan-tree-dump-times "vectorized 1 loops" 1 "vect" } } */ -/* { dg-final { scan-tree-dump-times "dependence distance modulo vf == 0" 1 "vect" } } */ +/* { dg-final { scan-tree-dump-times "accesses have the same alignment" 1 "vect" } } */