From patchwork Wed May 23 06:41:04 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Sandiford X-Patchwork-Id: 136633 Delivered-To: patch@linaro.org Received: by 2002:a2e:9706:0:0:0:0:0 with SMTP id r6-v6csp512386lji; Tue, 22 May 2018 23:41:39 -0700 (PDT) X-Google-Smtp-Source: AB8JxZpzZKvBqK5JTy0eSzxjbAF7IpNLjhfz/QH0YkqTQMwxECQCoto2WlrJ89HlysNn1/PHfmsm X-Received: by 2002:a63:34c1:: with SMTP id b184-v6mr1291503pga.396.1527057699852; Tue, 22 May 2018 23:41:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527057699; cv=none; d=google.com; s=arc-20160816; b=bhqvUjVLEyNio0urX7fVrKrjw0HQG1dxZv/jRX0/hI7c8Xf8sShoKuPooA3NvgPmgj /AB5+LEDtTr9kA4C2/jmsUaD4bq69swQyakp9FvBS3bi1OF5VuugR43TfJOyyjoTTwYM NZ479+adhfVP91wEMz2kSOKjtCUmeuxMKJvGnNznlQq/cDaD6zMmf/VXZpFSnIAkgdf6 tEg6qtRQ72N4cOa3IM6XOVWyqPklfuEvWrkm+tkQxOhFLOW/U9ZUDoawUJeJr2cjk05l YXzIRmXo5TsEB2zUQfc2fMrWftwGBstqE+eYEpXxfTPbATSasyHi/V1oVcNB1vFDj/WE B/BA== 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=MZWQlw+XoCtVy9uiMULqEXj30hoJTbhlB/JobcVphCo=; b=h0H0BY8F5PaejASTrcc4K3ag6R3c7nYkmvUvSqQjxrZvb68I33tMo2WbgJ74DjCpQ/ nOWxWYarB1YfzwuUa5Gpq3/vDWJrjoGHVU0ciLrT0i5GpYTSFzPc28U8IwQpNjFtqPqH UArSdjldSWPq5hWW7wL+fcb+nAJWo0rBswrbZSoeymHxfh+CApT73EDJlgx6o5CKLj1V QvZqfzz1gV0KNn1gziOes397h9Fw/YGJQpVvgXenzIchdu+EI4CMI4zG4yycpNOQfC+y xiAEA7qu6EalbqqKAY0AmROK08RyyrZ0DKOSxTo1iOyWeDEkRHJK0s8S8auszIeBzOCp kdkg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=rIbMpgTa; spf=pass (google.com: domain of gcc-patches-return-478224-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-478224-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 p1-v6si17726104pld.218.2018.05.22.23.41.39 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 22 May 2018 23:41:39 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-return-478224-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=rIbMpgTa; spf=pass (google.com: domain of gcc-patches-return-478224-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-478224-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=GyBvR/I4ZRSotdFX8G8lhJ2CJ+EzMh10+gXfbW4yp0MnvX7/RLq3c 4RnF1KfbNiuActjk+BosDEQnwpsa9jXA2rHuRTYzvXhPg0PMoezogr30HWda1HkN VIizIPDDNRT44biyX5bmiqp1UY95aCUIjijRmRIYADEfSWYkbGys8s= 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=lHvCZpuMvkHbS9YmsJowxkgqON0=; b=rIbMpgTa/KzT939fBNY+ 6bdm6Scr1cLXj8R7mOkJw0iulZlMM8SXR83NbUoCpAQxpsQ551z8OTPCEC6vRKEP DwK06UfnUGd7PARt3qwJPRCmBLVliJ/SmbDUm7+Jp0tDhxnb5yuMlXCje0F5Zjx5 nSPisG71eNgNkmqPXt28G7Y= Received: (qmail 115450 invoked by alias); 23 May 2018 06:41:26 -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 106333 invoked by uid 89); 23 May 2018 06:41:15 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-11.2 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=Hx-spam-relays-external:74.125.82.68, H*RU:74.125.82.68, STOP X-HELO: mail-wm0-f68.google.com Received: from mail-wm0-f68.google.com (HELO mail-wm0-f68.google.com) (74.125.82.68) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 23 May 2018 06:41:08 +0000 Received: by mail-wm0-f68.google.com with SMTP id a8-v6so5751835wmg.5 for ; Tue, 22 May 2018 23:41:08 -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=MZWQlw+XoCtVy9uiMULqEXj30hoJTbhlB/JobcVphCo=; b=kL7usHXYjxrAIo3dSiUGtN+kisTNKZ3qcOcQ/uvmy2TUqko9KqNHodkQM+OKB4LXgB bysv7Xyxf38LiA1Ye2k+RLZwsq82q8ANcBpZfSAg15kQiWJEWkXkJWlfMbWS/E2hfyyR rmsSjO/trBA0v3lMrIRTt5RztRUTAUKyz+6QYMNm281NR8yfR18Um0chSlkbHw2I8vZE GlIKZ5n7hIc4htHeCKkIrdC0FcyYMvplsjEKEMvP8+3i9M5RZfDXyDDsSzjn4fFCV6ML GlErMRQl03AWWEJjqLSrTbucoXiBNrvn7hf7lDRp/TbfryMl5sSji65ycMsJw2Us+Hy9 IKCw== X-Gm-Message-State: ALKqPwfhZABTtkopKzEyNI10FDhW9Dm9ON7Z15dillYM3onmv4tnb7xK kEHlpFMi/o7y4/xiNkRAQme69M9tAjk= X-Received: by 2002:a1c:5f82:: with SMTP id t124-v6mr3215165wmb.124.1527057666115; Tue, 22 May 2018 23:41:06 -0700 (PDT) Received: from localhost (201.69.7.51.dyn.plus.net. [51.7.69.201]) by smtp.gmail.com with ESMTPSA id p38-v6sm2436862wrc.11.2018.05.22.23.41.04 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 22 May 2018 23:41:05 -0700 (PDT) From: Richard Sandiford To: gcc-patches@gcc.gnu.org Mail-Followup-To: gcc-patches@gcc.gnu.org, richard.sandiford@linaro.org Subject: Fix SLP def type when computing masks (PR85853) Date: Wed, 23 May 2018 07:41:04 +0100 Message-ID: <87muwqlvr3.fsf@linaro.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.3 (gnu/linux) MIME-Version: 1.0 In this PR, SLP failed to include a comparison node in the SLP tree and so marked the node as external. It then went on to call vect_is_simple_use on the comparison with its STMT_VINFO_DEF_TYPE still claiming that it was an internal definition. We already avoid that for vect_analyze_stmt by temporarily copying the node's definition type to each STMT_VINFO_DEF_TYPE. This patch extends that to the vector type calculation. The easiest thing seemed to be to split the analysis of the root node out into a subroutine, so that it's possible to return false early without awkward control flow. Tested on aarch64-linux-gnu (with and without SLP), aarch64_be-elf and x86_64-linux-gnu. OK to install? Richard 2018-05-23 Richard Sandiford gcc/ PR tree-optimization/85853 * tree-vect-slp.c (vect_slp_analyze_node_operations): Split out handling of the root of the node to... (vect_slp_analyze_node_operations_1): ...this new function, and run the whole thing with the child nodes' def types set according to their SLP node's def type. gcc/testsuite/ PR tree-optimization/85853 * gfortran.dg/vect/pr85853.f90: New test. Index: gcc/tree-vect-slp.c =================================================================== --- gcc/tree-vect-slp.c 2018-05-17 11:50:31.609158213 +0100 +++ gcc/tree-vect-slp.c 2018-05-23 07:37:12.480578116 +0100 @@ -2476,49 +2476,16 @@ _bb_vec_info::~_bb_vec_info () bb->aux = NULL; } - -/* Analyze statements contained in SLP tree NODE after recursively analyzing - the subtree. NODE_INSTANCE contains NODE and VINFO contains INSTANCE. - - Return true if the operations are supported. */ +/* Subroutine of vect_slp_analyze_node_operations. Handle the root of NODE, + given then that child nodes have already been processed, and that + their def types currently match their SLP node's def type. */ static bool -vect_slp_analyze_node_operations (vec_info *vinfo, slp_tree node, - slp_instance node_instance, - scalar_stmts_to_slp_tree_map_t *visited, - scalar_stmts_to_slp_tree_map_t *lvisited, - stmt_vector_for_cost *cost_vec) +vect_slp_analyze_node_operations_1 (vec_info *vinfo, slp_tree node, + slp_instance node_instance, + stmt_vector_for_cost *cost_vec) { - bool dummy; - int i, j; - gimple *stmt; - slp_tree child; - - if (SLP_TREE_DEF_TYPE (node) != vect_internal_def) - return true; - - /* If we already analyzed the exact same set of scalar stmts we're done. - We share the generated vector stmts for those. */ - slp_tree *leader; - if ((leader = visited->get (SLP_TREE_SCALAR_STMTS (node))) - || (leader = lvisited->get (SLP_TREE_SCALAR_STMTS (node)))) - { - SLP_TREE_NUMBER_OF_VEC_STMTS (node) - = SLP_TREE_NUMBER_OF_VEC_STMTS (*leader); - return true; - } - - /* The SLP graph is acyclic so not caching whether we failed or succeeded - doesn't result in any issue since we throw away the lvisited set - when we fail. */ - lvisited->put (SLP_TREE_SCALAR_STMTS (node).copy (), node); - - FOR_EACH_VEC_ELT (SLP_TREE_CHILDREN (node), i, child) - if (!vect_slp_analyze_node_operations (vinfo, child, node_instance, - visited, lvisited, cost_vec)) - return false; - - stmt = SLP_TREE_SCALAR_STMTS (node)[0]; + gimple *stmt = SLP_TREE_SCALAR_STMTS (node)[0]; stmt_vec_info stmt_info = vinfo_for_stmt (stmt); gcc_assert (stmt_info); gcc_assert (STMT_SLP_TYPE (stmt_info) != loop_vect); @@ -2545,6 +2512,7 @@ vect_slp_analyze_node_operations (vec_in } gimple *sstmt; + unsigned int i; FOR_EACH_VEC_ELT (SLP_TREE_SCALAR_STMTS (node), i, sstmt) STMT_VINFO_VECTYPE (vinfo_for_stmt (sstmt)) = vectype; } @@ -2572,12 +2540,56 @@ vect_slp_analyze_node_operations (vec_in = vect_get_num_vectors (vf * group_size, vectype); } + bool dummy; + return vect_analyze_stmt (stmt, &dummy, node, node_instance, cost_vec); +} + +/* Analyze statements contained in SLP tree NODE after recursively analyzing + the subtree. NODE_INSTANCE contains NODE and VINFO contains INSTANCE. + + Return true if the operations are supported. */ + +static bool +vect_slp_analyze_node_operations (vec_info *vinfo, slp_tree node, + slp_instance node_instance, + scalar_stmts_to_slp_tree_map_t *visited, + scalar_stmts_to_slp_tree_map_t *lvisited, + stmt_vector_for_cost *cost_vec) +{ + int i, j; + slp_tree child; + + if (SLP_TREE_DEF_TYPE (node) != vect_internal_def) + return true; + + /* If we already analyzed the exact same set of scalar stmts we're done. + We share the generated vector stmts for those. */ + slp_tree *leader; + if ((leader = visited->get (SLP_TREE_SCALAR_STMTS (node))) + || (leader = lvisited->get (SLP_TREE_SCALAR_STMTS (node)))) + { + SLP_TREE_NUMBER_OF_VEC_STMTS (node) + = SLP_TREE_NUMBER_OF_VEC_STMTS (*leader); + return true; + } + + /* The SLP graph is acyclic so not caching whether we failed or succeeded + doesn't result in any issue since we throw away the lvisited set + when we fail. */ + lvisited->put (SLP_TREE_SCALAR_STMTS (node).copy (), node); + + FOR_EACH_VEC_ELT (SLP_TREE_CHILDREN (node), i, child) + if (!vect_slp_analyze_node_operations (vinfo, child, node_instance, + visited, lvisited, cost_vec)) + return false; + /* Push SLP node def-type to stmt operands. */ FOR_EACH_VEC_ELT (SLP_TREE_CHILDREN (node), j, child) if (SLP_TREE_DEF_TYPE (child) != vect_internal_def) STMT_VINFO_DEF_TYPE (vinfo_for_stmt (SLP_TREE_SCALAR_STMTS (child)[0])) = SLP_TREE_DEF_TYPE (child); - bool res = vect_analyze_stmt (stmt, &dummy, node, node_instance, cost_vec); + bool res = vect_slp_analyze_node_operations_1 (vinfo, node, node_instance, + cost_vec); /* Restore def-types. */ FOR_EACH_VEC_ELT (SLP_TREE_CHILDREN (node), j, child) if (SLP_TREE_DEF_TYPE (child) != vect_internal_def) Index: gcc/testsuite/gfortran.dg/vect/pr85853.f90 =================================================================== --- /dev/null 2018-04-20 16:19:46.369131350 +0100 +++ gcc/testsuite/gfortran.dg/vect/pr85853.f90 2018-05-23 07:37:12.477578485 +0100 @@ -0,0 +1,26 @@ +! Taken from execute/where_2.f90, but with special flags. +! { dg-do run } +! { dg-additional-options "-O3 -fno-tree-loop-vectorize" } + +! Program to test the WHERE constructs +program where_2 + integer temp(10), reduce(10) + + temp = 10 + reduce(1:3) = -1 + reduce(4:6) = 0 + reduce(7:8) = 5 + reduce(9:10) = 10 + + WHERE (reduce < 0) + temp = 100 + ELSE WHERE (reduce .EQ. 0) + temp = 200 + temp + ELSE WHERE + WHERE (reduce > 6) temp = temp + sum(reduce) + temp = 300 + temp + END WHERE + + if (any (temp .ne. (/100, 100, 100, 210, 210, 210, 310, 310, 337, 337/))) & + STOP 1 +end program