From patchwork Fri Nov 11 17:13:05 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 125224 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id 94701B6FF5 for ; Sat, 12 Nov 2011 04:13:30 +1100 (EST) Received: (qmail 1548 invoked by alias); 11 Nov 2011 17:13:25 -0000 Received: (qmail 1536 invoked by uid 22791); 11 Nov 2011 17:13:23 -0000 X-SWARE-Spam-Status: No, hits=-7.2 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, SPF_HELO_PASS, TW_TM X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 11 Nov 2011 17:13:08 +0000 Received: from int-mx12.intmail.prod.int.phx2.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id pABHD8Qo007977 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 11 Nov 2011 12:13:08 -0500 Received: from tyan-ft48-01.lab.bos.redhat.com (tyan-ft48-01.lab.bos.redhat.com [10.16.42.4]) by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id pABHD7Tc020842 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Fri, 11 Nov 2011 12:13:07 -0500 Received: from tyan-ft48-01.lab.bos.redhat.com (tyan-ft48-01.lab.bos.redhat.com [127.0.0.1]) by tyan-ft48-01.lab.bos.redhat.com (8.14.4/8.14.4) with ESMTP id pABHD6xO011242; Fri, 11 Nov 2011 18:13:06 +0100 Received: (from jakub@localhost) by tyan-ft48-01.lab.bos.redhat.com (8.14.4/8.14.4/Submit) id pABHD6VC010717; Fri, 11 Nov 2011 18:13:06 +0100 Date: Fri, 11 Nov 2011 18:13:05 +0100 From: Jakub Jelinek To: Ira Rosen , Richard Guenther Cc: gcc-patches@gcc.gnu.org Subject: Re: [PATCH] Don't ICE on SLP calls if the same call is used in multiple SLP instances (PR tree-optimization/51058) Message-ID: <20111111171305.GY27242@tyan-ft48-01.lab.bos.redhat.com> Reply-To: Jakub Jelinek References: <20111111153205.GU27242@tyan-ft48-01.lab.bos.redhat.com> <20111111170618.GX27242@tyan-ft48-01.lab.bos.redhat.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20111111170618.GX27242@tyan-ft48-01.lab.bos.redhat.com> User-Agent: Mutt/1.5.21 (2010-09-15) X-IsSubscribed: yes 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 On Fri, Nov 11, 2011 at 06:06:18PM +0100, Jakub Jelinek wrote: > > Please add > > ! { dg-final { cleanup-tree-dump "vect" } } > > > > OK otherwise. > > This is not a /vect/ testcase, but fortran torture. I guess > if you really want I could move it over to gfortran.dg/vect/ instead, > then the ! { dg-final { cleanup-tree-dump "vect" } } > would be indeed needed there. That would be following, incrementally tested with make check-gfortran RUNTESTFLAGS='--target_board=unix\{-m32,-m64\} vect.exp=pr51*' with both unpatched and patched f951. 2011-11-11 Jakub Jelinek PR tree-optimization/51058 * tree-vect-slp.c (vect_remove_slp_scalar_calls): New function. (vect_schedule_slp): Call it. * tree-vect-stmts.c (vectorizable_call): If slp_node != NULL, don't replace scalar calls with clearing of their lhs here. * gcc.dg/vect/fast-math-vect-call-1.c: Add f4 test. * gfortran.dg/vect/pr51058-2.f90: New test. Jakub --- gcc/tree-vect-slp.c.jj 2011-11-11 16:02:40.475359160 +0100 +++ gcc/tree-vect-slp.c 2011-11-11 18:08:29.784708271 +0100 @@ -2902,6 +2902,46 @@ vect_schedule_slp_instance (slp_tree nod return is_store; } +/* Replace scalar calls from SLP node NODE with clearing of their lhs. + For loop vectorization this is done in vectorizable_call, but for SLP + it needs to be deferred until end of vect_schedule_slp, because multiple + SLP instances may refer to the same scalar stmt. */ + +static void +vect_remove_slp_scalar_calls (slp_tree node) +{ + gimple stmt, new_stmt; + gimple_stmt_iterator gsi; + int i; + slp_void_p child; + tree lhs; + stmt_vec_info stmt_info; + + if (!node) + return; + + FOR_EACH_VEC_ELT (slp_void_p, SLP_TREE_CHILDREN (node), i, child) + vect_remove_slp_scalar_calls ((slp_tree) child); + + FOR_EACH_VEC_ELT (gimple, SLP_TREE_SCALAR_STMTS (node), i, stmt) + { + if (!is_gimple_call (stmt) || gimple_bb (stmt) == NULL) + continue; + stmt_info = vinfo_for_stmt (stmt); + if (stmt_info == NULL + || is_pattern_stmt_p (stmt_info) + || !PURE_SLP_STMT (stmt_info)) + continue; + lhs = gimple_call_lhs (stmt); + new_stmt = gimple_build_assign (lhs, build_zero_cst (TREE_TYPE (lhs))); + set_vinfo_for_stmt (new_stmt, stmt_info); + set_vinfo_for_stmt (stmt, NULL); + STMT_VINFO_STMT (stmt_info) = new_stmt; + gsi = gsi_for_stmt (stmt); + gsi_replace (&gsi, new_stmt, false); + SSA_NAME_DEF_STMT (gimple_assign_lhs (new_stmt)) = new_stmt; + } +} /* Generate vector code for all SLP instances in the loop/basic block. */ @@ -2941,6 +2981,8 @@ vect_schedule_slp (loop_vec_info loop_vi unsigned int j; gimple_stmt_iterator gsi; + vect_remove_slp_scalar_calls (root); + for (j = 0; VEC_iterate (gimple, SLP_TREE_SCALAR_STMTS (root), j, store) && j < SLP_INSTANCE_GROUP_SIZE (instance); j++) { --- gcc/tree-vect-stmts.c.jj 2011-11-11 16:02:28.343433924 +0100 +++ gcc/tree-vect-stmts.c 2011-11-11 18:08:29.786708241 +0100 @@ -1886,6 +1886,9 @@ vectorizable_call (gimple stmt, gimple_s it defines is mapped to the new definition. So just replace rhs of the statement with something harmless. */ + if (slp_node) + return true; + type = TREE_TYPE (scalar_dest); if (is_pattern_stmt_p (stmt_info)) lhs = gimple_call_lhs (STMT_VINFO_RELATED_STMT (stmt_info)); @@ -1893,8 +1896,7 @@ vectorizable_call (gimple stmt, gimple_s lhs = gimple_call_lhs (stmt); new_stmt = gimple_build_assign (lhs, build_zero_cst (type)); set_vinfo_for_stmt (new_stmt, stmt_info); - if (!slp_node) - set_vinfo_for_stmt (stmt, NULL); + set_vinfo_for_stmt (stmt, NULL); STMT_VINFO_STMT (stmt_info) = new_stmt; gsi_replace (gsi, new_stmt, false); SSA_NAME_DEF_STMT (gimple_assign_lhs (new_stmt)) = new_stmt; --- gcc/testsuite/gcc.dg/vect/fast-math-vect-call-1.c.jj 2011-11-11 16:02:28.026435857 +0100 +++ gcc/testsuite/gcc.dg/vect/fast-math-vect-call-1.c 2011-11-11 18:08:29.792708207 +0100 @@ -38,6 +38,18 @@ f3 (void) a[i] = copysignf (b[i], c[i]) + 1.0f + sqrtf (d[i]); } +__attribute__((noinline, noclone)) void +f4 (int n) +{ + int i; + for (i = 0; i < 2 * n; i++) + { + a[3 * i + 0] = copysignf (b[3 * i + 0], c[3 * i + 0]) + 1.0f + sqrtf (d[3 * i + 0]); + a[3 * i + 1] = copysignf (b[3 * i + 1], c[3 * i + 1]) + 2.0f + sqrtf (d[3 * i + 1]); + a[3 * i + 2] = copysignf (b[3 * i + 2], c[3 * i + 2]) + 3.0f + sqrtf (d[3 * i + 2]); + } +} + __attribute__((noinline, noclone)) int main1 () { @@ -66,6 +78,12 @@ main1 () for (i = 0; i < 64; i++) if (fabsf (((i & 2) ? -4 * i : 4 * i) + 1 + i - a[i]) >= 0.0001f) abort (); + else + a[i] = 131.25; + f4 (10); + for (i = 0; i < 60; i++) + if (fabsf (((i & 2) ? -4 * i : 4 * i) + 1 + (i % 3) + i - a[i]) >= 0.0001f) + abort (); return 0; } @@ -76,6 +94,6 @@ main () return main1 (); } -/* { dg-final { scan-tree-dump-times "vectorized 1 loops" 3 "vect" { target { vect_call_copysignf && vect_call_sqrtf } } } } */ -/* { dg-final { scan-tree-dump-times "vectorizing stmts using SLP" 2 "vect" { target { vect_call_copysignf && vect_call_sqrtf } } } } */ +/* { dg-final { scan-tree-dump-times "vectorized 1 loops" 4 "vect" { target { vect_call_copysignf && vect_call_sqrtf } } } } */ +/* { dg-final { scan-tree-dump-times "vectorizing stmts using SLP" 3 "vect" { target { vect_call_copysignf && vect_call_sqrtf } } } } */ /* { dg-final { cleanup-tree-dump "vect" } } */ --- gcc/testsuite/gfortran.dg/vect/pr51058-2.f90.jj 2011-11-11 18:08:29.792708207 +0100 +++ gcc/testsuite/gfortran.dg/vect/pr51058-2.f90 2011-11-11 18:09:22.378400344 +0100 @@ -0,0 +1,20 @@ +! PR tree-optimization/51058 +! { dg-do compile } +subroutine pr51058(n, u, v, w, z) + double precision :: x(3,-2:16384), y(3,-2:16384), b, u, v, w, z + integer :: i, n + common /c/ x, y + do i = 1, n + b = u * int(x(1,i)) + sign(z,x(1,i)) + x(1,i) = x(1,i) - b + y(1,i) = y(1,i) - b + b = v * int(x(2,i)) + sign(z,x(2,i)) + x(2,i) = x(2,i) - b + y(2,i) = y(2,i) - b + b = w * int(x(3,i)) + sign(z,x(3,i)) + x(3,i) = x(3,i) - b + y(3,i) = y(3,i) - b + end do +end subroutine + +! { dg-final { cleanup-tree-dump "vect" } }