From patchwork Sun Sep 18 11:39:08 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ira Rosen X-Patchwork-Id: 4158 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id AB74023EFB for ; Sun, 18 Sep 2011 11:39:11 +0000 (UTC) Received: from mail-fx0-f52.google.com (mail-fx0-f52.google.com [209.85.161.52]) by fiordland.canonical.com (Postfix) with ESMTP id 94C8FA18633 for ; Sun, 18 Sep 2011 11:39:11 +0000 (UTC) Received: by fxe23 with SMTP id 23so4337430fxe.11 for ; Sun, 18 Sep 2011 04:39:11 -0700 (PDT) Received: by 10.223.34.143 with SMTP id l15mr3052329fad.46.1316345951326; Sun, 18 Sep 2011 04:39:11 -0700 (PDT) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.152.18.198 with SMTP id y6cs4361lad; Sun, 18 Sep 2011 04:39:10 -0700 (PDT) Received: by 10.150.163.17 with SMTP id l17mr1141238ybe.250.1316345949136; Sun, 18 Sep 2011 04:39:09 -0700 (PDT) Received: from mail-gx0-f178.google.com (mail-gx0-f178.google.com [209.85.161.178]) by mx.google.com with ESMTPS id e3si8166257ybg.21.2011.09.18.04.39.08 (version=TLSv1/SSLv3 cipher=OTHER); Sun, 18 Sep 2011 04:39:08 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.161.178 is neither permitted nor denied by best guess record for domain of ira.rosen@linaro.org) client-ip=209.85.161.178; Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.161.178 is neither permitted nor denied by best guess record for domain of ira.rosen@linaro.org) smtp.mail=ira.rosen@linaro.org Received: by gxk21 with SMTP id 21so16811113gxk.37 for ; Sun, 18 Sep 2011 04:39:08 -0700 (PDT) MIME-Version: 1.0 Received: by 10.150.200.18 with SMTP id x18mr1143849ybf.219.1316345948169; Sun, 18 Sep 2011 04:39:08 -0700 (PDT) Received: by 10.151.100.9 with HTTP; Sun, 18 Sep 2011 04:39:08 -0700 (PDT) Date: Sun, 18 Sep 2011 14:39:08 +0300 Message-ID: Subject: [patch] Fix tree-optimization/50414 From: Ira Rosen To: gcc-patches@gcc.gnu.org Cc: Patch Tracking Hi, This patch adds a missing handling of MAX/MIN_EXPR in SLP reduction. Boostrapped and tested on powerpc64-suse-linux. Committed to trunk. Ira ChangeLog: PR tree-optimization/50414 * tree-vect-slp.c (vect_get_constant_vectors): Handle MAX_EXPR and MIN_EXPR. testsuite/ChangeLog: PR tree-optimization/50414 * gfortran.dg/vect/Ofast-pr50414.f90: New. * gfortran.dg/vect/vect.exp: Run Ofast-* tests with -Ofast. * gcc.dg/vect/no-scevccp-noreassoc-slp-reduc-7.c: New. +/* { dg-final { cleanup-tree-dump "vect" } } */ + Index: tree-vect-slp.c =================================================================== --- tree-vect-slp.c (revision 178939) +++ tree-vect-slp.c (working copy) @@ -1902,6 +1902,8 @@ vect_get_constant_vectors (tree op, slp_tree slp_n bool constant_p, is_store; tree neutral_op = NULL; enum tree_code code = gimple_assign_rhs_code (stmt); + gimple def_stmt; + struct loop *loop; if (STMT_VINFO_DEF_TYPE (stmt_vinfo) == vect_reduction_def) { @@ -1943,8 +1945,16 @@ vect_get_constant_vectors (tree op, slp_tree slp_n neutral_op = build_int_cst (TREE_TYPE (op), -1); break; + case MAX_EXPR: + case MIN_EXPR: + def_stmt = SSA_NAME_DEF_STMT (op); + loop = (gimple_bb (stmt))->loop_father; + neutral_op = PHI_ARG_DEF_FROM_EDGE (def_stmt, + loop_preheader_edge (loop)); + break; + default: - neutral_op = NULL; + neutral_op = NULL; } } @@ -1997,8 +2007,8 @@ vect_get_constant_vectors (tree op, slp_tree slp_n if (reduc_index != -1) { - struct loop *loop = (gimple_bb (stmt))->loop_father; - gimple def_stmt = SSA_NAME_DEF_STMT (op); + loop = (gimple_bb (stmt))->loop_father; + def_stmt = SSA_NAME_DEF_STMT (op); gcc_assert (loop); Index: testsuite/gfortran.dg/vect/Ofast-pr50414.f90 =================================================================== --- testsuite/gfortran.dg/vect/Ofast-pr50414.f90 (revision 0) +++ testsuite/gfortran.dg/vect/Ofast-pr50414.f90 (revision 0) @@ -0,0 +1,11 @@ +! { dg-do compile } + + SUBROUTINE SUB (A,L,YMAX) + DIMENSION A(L) + YMA=A(1) + DO 2 I=1,L,2 + 2 YMA=MAX(YMA,A(I),A(I+1)) + CALL PROUND(YMA) + END + +! { dg-final { cleanup-tree-dump "vect" } } Index: testsuite/gfortran.dg/vect/vect.exp =================================================================== --- testsuite/gfortran.dg/vect/vect.exp (revision 178939) +++ testsuite/gfortran.dg/vect/vect.exp (working copy) @@ -84,6 +84,12 @@ lappend DEFAULT_VECTCFLAGS "-O3" dg-runtest [lsort [glob -nocomplain $srcdir/$subdir/O3-*.\[fF\]{,90,95,03,08} ]] \ "" $DEFAULT_VECTCFLAGS +# With -Ofast +set DEFAULT_VECTCFLAGS $SAVED_DEFAULT_VECTCFLAGS +lappend DEFAULT_VECTCFLAGS "-Ofast" +dg-runtest [lsort [glob -nocomplain $srcdir/$subdir/Ofast-*.\[fF\]{,90,95,03,08} ]] \ + "" $DEFAULT_VECTCFLAGS + # Clean up. set dg-do-what-default ${save-dg-do-what-default} Index: testsuite/gcc.dg/vect/no-scevccp-noreassoc-slp-reduc-7.c =================================================================== --- testsuite/gcc.dg/vect/no-scevccp-noreassoc-slp-reduc-7.c (revision 0) +++ testsuite/gcc.dg/vect/no-scevccp-noreassoc-slp-reduc-7.c (revision 0) @@ -0,0 +1,42 @@ +/* { dg-require-effective-target vect_int } */ + +#include +#include "tree-vect.h" + +#define N 16 +#define MAX 121 + +unsigned int ub[N] = {0,3,6,9,12,15,18,121,24,27,113,33,36,39,42,45}; + +/* Vectorization of reduction using loop-aware SLP (with unrolling). */ + +__attribute__ ((noinline)) +int main1 (int n) +{ + int i; + unsigned int max = 50; + + for (i = 0; i < n; i++) { + max = max < ub[2*i] ? ub[2*i] : max; + max = max < ub[2*i + 1] ? ub[2*i + 1] : max; + } + + /* Check results: */ + if (max != MAX) + abort (); + + return 0; +} + +int main (void) +{ + check_vect (); + + main1 (N/2); + return 0; +} + +/* { dg-final { scan-tree-dump-times "vectorized 1 loops" 1 "vect" { xfail vect_no_int_max } } } */ +/* { dg-final { scan-tree-dump-times "vectorizing stmts using SLP" 1 "vect" { xfail vect_no_int_max } } } */