From patchwork Thu Oct 24 06:17:45 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 1182646 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-511640-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=suse.de Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="jthhiuTM"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 46zH9Q0SWgz9sPc for ; Thu, 24 Oct 2019 17:17:59 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:subject:message-id:mime-version:content-type; q=dns; s= default; b=ibDZH3LbWs7/xaN541A2yL+vZ+WRz1TbipsaTMCRWQG9SV5XOtnsV h4MUNq2XlwW6+pzWYriGeJzFyPtIMwD9QEWJfMy7cJofyuQpqUB1shZ7yJsz7BQM +UG+RkAdOyCHXW5mWDhvRTdsKCh5p+uhFBorrW8j1IO6+U1HbW1gIc= 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:date :from:to:subject:message-id:mime-version:content-type; s= default; bh=h/y6A7guv6Gab8ciSzQiQmDW5Io=; b=jthhiuTMaEZ8t8xG4f/9 wRb+UNJ+gsJ6qJLOZUTji9WiL1b/DuY91gmjenB0GL9Bc5KqmdTlhiggjg/hHXkY PLHhPuX1QLLpA0QCaIUbdytJRyqOZE9eWTtc39WuE/4637wN5IWAWPhunAAeY6vl FnyA/xnOgoSLNgR4DCuuer8= Received: (qmail 78057 invoked by alias); 24 Oct 2019 06:17:49 -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 78045 invoked by uid 89); 24 Oct 2019 06:17:49 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-10.5 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, SPF_PASS autolearn=ham version=3.3.1 spammy=discovery, 2*i, reductions X-HELO: mx1.suse.de Received: from mx2.suse.de (HELO mx1.suse.de) (195.135.220.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 24 Oct 2019 06:17:48 +0000 Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id E72A6B46C for ; Thu, 24 Oct 2019 06:17:45 +0000 (UTC) Date: Thu, 24 Oct 2019 08:17:45 +0200 (CEST) From: Richard Biener To: gcc-patches@gcc.gnu.org Subject: [PATCH] Fall back to SLP reduction discovery when reduction group fails Message-ID: User-Agent: Alpine 2.21 (LSU 202 2017-01-01) MIME-Version: 1.0 This helps saving some IVs (though I guess the situation where it matches in practice is scarce). Bootstrapped and tested on x86_64-unknown-linux-gnu, applied to trunk. Richard. 2019-10-24 Richard Biener * tree-vect-slp.c (vect_analyze_slp): When reduction group SLP discovery fails try to handle the reduction as part of SLP reduction discovery. * gcc.dg/vect/slp-reduc-9.c: New testcase. Index: gcc/tree-vect-slp.c =================================================================== --- gcc/tree-vect-slp.c (revision 277330) +++ gcc/tree-vect-slp.c (working copy) @@ -2271,14 +2271,18 @@ vect_analyze_slp (vec_info *vinfo, unsig { /* Dissolve reduction chain group. */ stmt_vec_info vinfo = first_element; + stmt_vec_info last = NULL; while (vinfo) { stmt_vec_info next = REDUC_GROUP_NEXT_ELEMENT (vinfo); REDUC_GROUP_FIRST_ELEMENT (vinfo) = NULL; REDUC_GROUP_NEXT_ELEMENT (vinfo) = NULL; + last = vinfo; vinfo = next; } STMT_VINFO_DEF_TYPE (first_element) = vect_internal_def; + /* It can be still vectorized as part of an SLP reduction. */ + loop_vinfo->reductions.safe_push (last); } } Index: gcc/testsuite/gcc.dg/vect/slp-reduc-9.c =================================================================== --- gcc/testsuite/gcc.dg/vect/slp-reduc-9.c (nonexistent) +++ gcc/testsuite/gcc.dg/vect/slp-reduc-9.c (working copy) @@ -0,0 +1,25 @@ +/* { dg-do compile } */ +/* { dg-require-effective-target vect_int_mult } */ + +int +bar (int *x, int a, int b, int n) +{ + x = __builtin_assume_aligned (x, __BIGGEST_ALIGNMENT__); + int sum1 = 0; + int sum2 = 0; + for (int i = 0; i < n; ++i) + { + /* Reduction chain vectorization fails here because of the + different operations but we can still vectorize both + reductions as SLP reductions, saving IVs. */ + sum1 += x[2*i] - a; + sum1 += x[2*i+1] * b; + sum2 += x[2*i] - b; + sum2 += x[2*i+1] * a; + } + return sum1 + sum2; +} + +/* { dg-final { scan-tree-dump "Loop contains only SLP stmts" "vect" } } */ +/* { dg-final { scan-tree-dump "vectorizing stmts using SLP" "vect" } } */ +/* { dg-final { scan-tree-dump "vectorized 1 loops" "vect" } } */