From patchwork Fri Jan 19 09:45:47 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Sandiford X-Patchwork-Id: 125136 Delivered-To: patch@linaro.org Received: by 10.46.66.141 with SMTP id h13csp212085ljf; Fri, 19 Jan 2018 01:46:07 -0800 (PST) X-Google-Smtp-Source: ACJfBour9zJEAN6oGbAsZXAsrVFqyHOW1MuG2IwNla/l1SmmrO6cfYRlCfMQhEGZ3fUv8TAoS01e X-Received: by 10.99.160.88 with SMTP id u24mr31521436pgn.122.1516355167340; Fri, 19 Jan 2018 01:46:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516355167; cv=none; d=google.com; s=arc-20160816; b=U5Xf0fsjFDgIioNgVo563O3zN0XYkF0PJfILbXh9ihr0KQHmj/Gmg91gPHaDOkdFGM 03mxkNJXchkwZ0A5All7cWAVvCZY/9gv9k/ulLSfi1x2yX94kAUbttb5wEOfUnvOg/so vDri2YTuL/Ci2Yx5NdHLfqeaKUkYXOYIPxpqZi4pldkaW6mmexlc1jpOX4WDOhCaLazP 4B0TRZEgcg8hRShV6loS/2BXfvu2BInhx99dvOFKgM3Ug0ALdNHh97Gp1M7Xf00h7uCn Gc7WA9QWF4DLWcMM3vkTdBBFUXzMRqGeA6WCyrbGWcGVvtMH/J78FDtTD8gNu9q/czFF 9IQQ== 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=noQN0y3O0tA7e5md5QFaqLod2+qSLMeJjfh4UC9bIws=; b=Rrtz/vbb8N+hNzRmlYY/OpTZoayjC713D+WPuyAehTepAFK4SScvrszuXTIH8O0YMf /OmmlO2002UoKFSuTU5sX1k1w+aYRy9wVjkKffCNlRWzoWia7jIMUhtqjUBVA1L9SIj9 YPqhhS29ubu6R6+n3Tsl5BoAnOwc/2MRqTWITOIm+eBVuDkWCSyh3P8dZGuOJDOmpGhB PTZCwTx3dR6xx5tJujpq8SZJK/nYNRuRVcRbyNGZ0XtZEcTEC9ncsmHeieVkSUSTISoe u/oZOw9apBZ4ZWeNVJB87QnfbNwBVegla5E4QQ2UhMz2u0ockOQQOLt2aR87oiWlpQIU ifuA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=qP0TmkN0; spf=pass (google.com: domain of gcc-patches-return-471642-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-471642-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 x10si8182713pgt.208.2018.01.19.01.46.06 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 19 Jan 2018 01:46:07 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-return-471642-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=qP0TmkN0; spf=pass (google.com: domain of gcc-patches-return-471642-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-471642-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=WyJjA4BuWRMndq70Ifot3e+pg+xaFuhKf4UZpy5zSMSm0VhcoHMHZ veN5Ahi3oRb3B5hAHL0dtuPFOvyOT6lzRhCQZhjR/RWuqJLWBVK0YKVl2iIIi4/q aOkkUjuuA/VX6OQCiJlL8cVDPcOtWtCThipDd0L8JqjHaqAPabATzM= 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=mk9yBLouDCiySdeC6SGPB1UaDYk=; b=qP0TmkN0rXosubyl9hny mym8fLK2HISFq3xJNkQUMzhtctYERA2CQR9ddRovofyf3SsE9elACdEamYK8Dcnr FgL5AUxpYBF9yySKMFKpEKDaeEFLH0l0wk4Sw2te+kO+zaUw1O/ijuKM6QKTy6OJ G1jh9ZTBdhqxL3xbeQzSLMo= Received: (qmail 60388 invoked by alias); 19 Jan 2018 09:45:55 -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 60377 invoked by uid 89); 19 Jan 2018 09:45:55 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-9.7 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_NONE, RCVD_IN_SORBS_WEB, SPF_PASS autolearn=ham version=3.3.2 spammy=enforced, H*r:threembb.co.uk X-HELO: mail-wm0-f50.google.com Received: from mail-wm0-f50.google.com (HELO mail-wm0-f50.google.com) (74.125.82.50) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 19 Jan 2018 09:45:53 +0000 Received: by mail-wm0-f50.google.com with SMTP id t74so2170135wme.3 for ; Fri, 19 Jan 2018 01:45:52 -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=noQN0y3O0tA7e5md5QFaqLod2+qSLMeJjfh4UC9bIws=; b=U0Pen1csFScIZMC7aL+o2M0eQjfteFlyoxmrNSbTlcqUq6HlspLQcK4SCYcK11EIbu 2t0Nk2VlvdWUkRDM3htDc8e4HRPvk2oWpOxRhOQq6saULP/dqzNd+jeMd3ZLiV1jjjop vrs5Me1h/yKKu0txi03keAKep4+0ym4uzimdsvy9IMIzGfoFxvImN1hrPOFyXnutsXsW bpAwyniNHvF6qzrxBwdJf0V60M4u+mu/Nasw2QYczxZEIKGMhWOWXr0an6p2Rhrenzbb /IZi+rEN/rHotafg0OOElnU+ijtoRxzO4FVgDr8ngFfDnF0tzjRKYxtKKCq/K39fbA4D sYLA== X-Gm-Message-State: AKwxytc7iby2sT0gBu8HvfzU2J7Ufr7fcmBqJuYHwn/sOvUCXuB6HJwz Kz7kqD7maozWSLGJa1XaI1v5UwD66CE= X-Received: by 10.28.237.20 with SMTP id l20mr6832076wmh.15.1516355150947; Fri, 19 Jan 2018 01:45:50 -0800 (PST) Received: from localhost (188.29.165.192.threembb.co.uk. [188.29.165.192]) by smtp.gmail.com with ESMTPSA id o16sm689087wmi.29.2018.01.19.01.45.49 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 19 Jan 2018 01:45:50 -0800 (PST) From: Richard Sandiford To: gcc-patches@gcc.gnu.org Mail-Followup-To: gcc-patches@gcc.gnu.org, richard.sandiford@linaro.org Subject: Avoid ICE for nested inductions (PR 83914) Date: Fri, 19 Jan 2018 09:45:47 +0000 Message-ID: <87po6641x0.fsf@linaro.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.3 (gnu/linux) MIME-Version: 1.0 This testcase ICEd because we converted the initial value of an induction to the vector element type even for nested inductions. This isn't necessary because the initial expression is vectorised normally, and it meant that init_expr was no longer the original statement operand by the time we called vect_get_vec_def_for_operand. Also, adding the conversion code here made the existing SLP conversion redundant. It looks like something went wrong when rebasing the peeling via masks work on top of the support for SLP reductions, sorry about that. Tested on aarch64-linux-gnu, x86_64-linux-gnu and powerpc64le-linux-gnu. OK to install? Richard 2018-01-19 Richard Sandiford gcc/ PR tree-optimization/83914 * tree-vect-loop.c (vectorizable_induction): Don't convert init_expr or apply the peeling adjustment for inductions that are nested within the vectorized loop. Remove redundant conversion code. gcc/testsuite/ PR tree-optimization/83914 * gcc.dg/vect/pr83914.c: New test. Index: gcc/tree-vect-loop.c =================================================================== --- gcc/tree-vect-loop.c 2018-01-16 15:13:24.938622242 +0000 +++ gcc/tree-vect-loop.c 2018-01-19 09:36:33.409191362 +0000 @@ -7678,28 +7678,33 @@ vectorizable_induction (gimple *phi, init_expr = PHI_ARG_DEF_FROM_EDGE (phi, loop_preheader_edge (iv_loop)); - /* Convert the initial value and step to the desired type. */ stmts = NULL; - init_expr = gimple_convert (&stmts, TREE_TYPE (vectype), init_expr); - step_expr = gimple_convert (&stmts, TREE_TYPE (vectype), step_expr); - - /* If we are using the loop mask to "peel" for alignment then we need - to adjust the start value here. */ - tree skip_niters = LOOP_VINFO_MASK_SKIP_NITERS (loop_vinfo); - if (skip_niters != NULL_TREE) + if (!nested_in_vect_loop) { - if (FLOAT_TYPE_P (vectype)) - skip_niters = gimple_build (&stmts, FLOAT_EXPR, TREE_TYPE (vectype), - skip_niters); - else - skip_niters = gimple_convert (&stmts, TREE_TYPE (vectype), - skip_niters); - tree skip_step = gimple_build (&stmts, MULT_EXPR, TREE_TYPE (vectype), - skip_niters, step_expr); - init_expr = gimple_build (&stmts, MINUS_EXPR, TREE_TYPE (vectype), - init_expr, skip_step); + /* Convert the initial value to the desired type. */ + tree new_type = TREE_TYPE (vectype); + init_expr = gimple_convert (&stmts, new_type, init_expr); + + /* If we are using the loop mask to "peel" for alignment then we need + to adjust the start value here. */ + tree skip_niters = LOOP_VINFO_MASK_SKIP_NITERS (loop_vinfo); + if (skip_niters != NULL_TREE) + { + if (FLOAT_TYPE_P (vectype)) + skip_niters = gimple_build (&stmts, FLOAT_EXPR, new_type, + skip_niters); + else + skip_niters = gimple_convert (&stmts, new_type, skip_niters); + tree skip_step = gimple_build (&stmts, MULT_EXPR, new_type, + skip_niters, step_expr); + init_expr = gimple_build (&stmts, MINUS_EXPR, new_type, + init_expr, skip_step); + } } + /* Convert the step to the desired type. */ + step_expr = gimple_convert (&stmts, TREE_TYPE (vectype), step_expr); + if (stmts) { new_bb = gsi_insert_seq_on_edge_immediate (pe, stmts); @@ -7718,15 +7723,6 @@ vectorizable_induction (gimple *phi, /* Enforced above. */ unsigned int const_nunits = nunits.to_constant (); - /* Convert the init to the desired type. */ - stmts = NULL; - init_expr = gimple_convert (&stmts, TREE_TYPE (vectype), init_expr); - if (stmts) - { - new_bb = gsi_insert_seq_on_edge_immediate (pe, stmts); - gcc_assert (!new_bb); - } - /* Generate [VF*S, VF*S, ... ]. */ if (SCALAR_FLOAT_TYPE_P (TREE_TYPE (step_expr))) { Index: gcc/testsuite/gcc.dg/vect/pr83914.c =================================================================== --- /dev/null 2018-01-19 09:30:49.543814408 +0000 +++ gcc/testsuite/gcc.dg/vect/pr83914.c 2018-01-19 09:36:33.405191141 +0000 @@ -0,0 +1,15 @@ +/* { dg-do compile } */ +/* { dg-additional-options "-O3" } */ + +struct s { struct s *ptrs[16]; } *a, *b; +int c; +void +foo (int n) +{ + for (; n; a = b, n--) + { + b = a + 1; + for (c = 8; c; c--) + a->ptrs[c] = b; + } +}