From patchwork Tue Oct 22 11:16:03 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 1181240 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-511491-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="XLfedj+u"; 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 46y9tS0fcfz9s7T for ; Tue, 22 Oct 2019 22:16:15 +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=sUvtcOjBBX6WefsyULYCVR/PWAQp9oShjKhs748GYyxEl7HFbHAuz ynxf10vEgG124URpXmrUh3c3+OCR6qfqzioxRVBnfelf20g9P6sgEHwU9twBdKNn Z+Vh0ZEWVi1GO7q1GoJ+6wVjad/20K6CChL0x6xK3IrUXoHFX6kJrY= 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=0bW2alz063U3LNkvCC9J1OBFWLU=; b=XLfedj+ugRmVr4kGS5aN Y/z5Dg5rK3Zy3iwspSxXNE319/Sao4O4OEFA7XShtaj/hjBPuSF5AkTR+UxH0Odm v7EnaymiehrupBVC3O6siE8oNhBlXcV7JsQ3GCQcmoNZEUAQ76tShx8t+bsAf1nj JafIeNG/tmMXvmHAnZ4UcMM= Received: (qmail 100121 invoked by alias); 22 Oct 2019 11:16:08 -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 100109 invoked by uid 89); 22 Oct 2019 11:16:07 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-10.2 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, KAM_NUMSUBJECT, SPF_PASS autolearn=ham version=3.3.1 spammy= 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; Tue, 22 Oct 2019 11:16:05 +0000 Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 2E6E8B753 for ; Tue, 22 Oct 2019 11:16:03 +0000 (UTC) Date: Tue, 22 Oct 2019 13:16:03 +0200 (CEST) From: Richard Biener To: gcc-patches@gcc.gnu.org Subject: [PATCH] Fix PR92173 Message-ID: User-Agent: Alpine 2.21 (LSU 202 2017-01-01) MIME-Version: 1.0 The following fixes an ICE when vectorizable_reduction asks for the optab for a shift but passes optab_default. Simply pass optab_vector since that's what it code-generates later. As optimization if its own code-generator fails try the regular one. Bootstrapped and tested on x86_64-unknown-linux-gnu, applied. Richard. 2019-10-22 Richard Biener PR tree-optimization/92173 * tree-vect-loop.c (vectorizable_reduction): If vect_transform_reduction cannot handle code-generation try without the single-def-use-cycle optimization. Pass optab_vector to optab_for_tree_code to get vector shifts as that's what we'd generate. * gcc.dg/torture/pr92173.c: New testcase. Index: gcc/tree-vect-loop.c =================================================================== --- gcc/tree-vect-loop.c (revision 277280) +++ gcc/tree-vect-loop.c (working copy) @@ -6240,61 +6240,67 @@ vectorizable_reduction (stmt_vec_info st && (!STMT_VINFO_IN_PATTERN_P (use_stmt_info) || !STMT_VINFO_PATTERN_DEF_SEQ (use_stmt_info)) && vect_stmt_to_vectorize (use_stmt_info) == stmt_info) - STMT_VINFO_FORCE_SINGLE_CYCLE (reduc_info) = single_defuse_cycle = true; + single_defuse_cycle = true; - if (single_defuse_cycle - || code == DOT_PROD_EXPR - || code == WIDEN_SUM_EXPR - || code == SAD_EXPR) + bool lane_reduc_code_p + = (code == DOT_PROD_EXPR || code == WIDEN_SUM_EXPR || code == SAD_EXPR); + if (single_defuse_cycle || lane_reduc_code_p) { gcc_assert (code != COND_EXPR); /* 4. Supportable by target? */ + bool ok = true; /* 4.1. check support for the operation in the loop */ - optab optab = optab_for_tree_code (code, vectype_in, optab_default); + optab optab = optab_for_tree_code (code, vectype_in, optab_vector); if (!optab) - { - if (dump_enabled_p ()) + { + if (dump_enabled_p ()) dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location, "no optab.\n"); - - return false; + ok = false; } machine_mode vec_mode = TYPE_MODE (vectype_in); - if (optab_handler (optab, vec_mode) == CODE_FOR_nothing) + if (ok && optab_handler (optab, vec_mode) == CODE_FOR_nothing) { if (dump_enabled_p ()) dump_printf (MSG_NOTE, "op not supported by target.\n"); - if (maybe_ne (GET_MODE_SIZE (vec_mode), UNITS_PER_WORD) || !vect_worthwhile_without_simd_p (loop_vinfo, code)) - return false; - - if (dump_enabled_p ()) - dump_printf (MSG_NOTE, "proceeding using word mode.\n"); + ok = false; + else + if (dump_enabled_p ()) + dump_printf (MSG_NOTE, "proceeding using word mode.\n"); } /* Worthwhile without SIMD support? */ - if (!VECTOR_MODE_P (TYPE_MODE (vectype_in)) + if (ok + && !VECTOR_MODE_P (TYPE_MODE (vectype_in)) && !vect_worthwhile_without_simd_p (loop_vinfo, code)) { if (dump_enabled_p ()) dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location, "not worthwhile without SIMD support.\n"); - - return false; + ok = false; } + + /* lane-reducing operations have to go through vect_transform_reduction. + For the other cases try without the single cycle optimization. */ + if (!ok) + { + if (lane_reduc_code_p) + return false; + else + single_defuse_cycle = false; + } } + STMT_VINFO_FORCE_SINGLE_CYCLE (reduc_info) = single_defuse_cycle; /* If the reduction stmt is one of the patterns that have lane reduction embedded we cannot handle the case of ! single_defuse_cycle. */ - if ((ncopies > 1 - && ! single_defuse_cycle) - && (code == DOT_PROD_EXPR - || code == WIDEN_SUM_EXPR - || code == SAD_EXPR)) + if ((ncopies > 1 && ! single_defuse_cycle) + && lane_reduc_code_p) { if (dump_enabled_p ()) dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location, Index: gcc/testsuite/gcc.dg/torture/pr92173.c =================================================================== --- gcc/testsuite/gcc.dg/torture/pr92173.c (nonexistent) +++ gcc/testsuite/gcc.dg/torture/pr92173.c (working copy) @@ -0,0 +1,11 @@ +/* { dg-do compile } */ +/* { dg-additional-options "-ftree-vectorize" } */ + +unsigned int +yo (unsigned int o0, signed char s1) +{ + for (s1 = 0; s1 < 1; s1 -= 2) + o0 += o0; + + return o0 + s1; +}