From patchwork Tue Nov 5 10:59:02 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 1189590 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-512425-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="Ozr0fCBw"; 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 476mrK0pYHz9s4Y for ; Tue, 5 Nov 2019 21:59:12 +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=aE2js5XR4QxpYJLSACTIQXaRIK655sBcoheZUQDUrQoGTM+4858YU nv3FSpU1q3XYrZFAIsZ5dJzLwdWaoalFEYVdcGqKt9mADKSbTiuXay6/OR8tuCYn X6saLezWhkPpzLcWpuyNDD9bN4Rtl0dGLoRceo5U0WuGCgSD3zzqkE= 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=0/EoYYYAVGBcs/NszoAEfbZtarQ=; b=Ozr0fCBwwNBTyKYPDcsM IQ2e85eKm3hcpRsm8yYCu/plBdC5DunrKag9oRx42eMNjwUnqxMbGphQx99jdnXw Sp796XhhFzvqVjnsJulB6hilRjMx83oan99RBsrbEClCliBalWRmj97I4YDle8c3 4orb9UlwxgM0yNihX4BA7vo= Received: (qmail 22374 invoked by alias); 5 Nov 2019 10:59:05 -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 22362 invoked by uid 89); 5 Nov 2019 10:59:05 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-10.3 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=HX-Languages-Length:2067 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, 05 Nov 2019 10:59:04 +0000 Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 1A957AF41 for ; Tue, 5 Nov 2019 10:59:02 +0000 (UTC) Date: Tue, 5 Nov 2019 11:59:02 +0100 (CET) From: Richard Biener To: gcc-patches@gcc.gnu.org Subject: [PATCH] Fix part of PR92324 Message-ID: User-Agent: Alpine 2.21 (LSU 202 2017-01-01) MIME-Version: 1.0 We have to be able to choose one signedness for the epilogue part of the reduction - for MIN/MAX this means if we have two both have to be of the same signedness. Bootstrapped and tested on x86_64-unknown-linux-gnu, applied. Richard. 2019-11-05 Richard Biener PR tree-optimization/92324 * tree-vect-loop.c (check_reduction_path): For MIN/MAX require all signed or unsigned operations. * gcc.dg/vect/pr92324-3.c: New testcase. Index: gcc/tree-vect-loop.c =================================================================== --- gcc/tree-vect-loop.c (revision 277782) +++ gcc/tree-vect-loop.c (working copy) @@ -2744,6 +2744,7 @@ pop: /* Check whether the reduction path detected is valid. */ bool fail = path.length () == 0; bool neg = false; + int sign = -1; *code = ERROR_MARK; for (unsigned i = 1; i < path.length (); ++i) { @@ -2787,12 +2788,22 @@ pop: TREE_TYPE (gimple_assign_rhs1 (use_stmt)))) ; else if (*code == ERROR_MARK) - *code = use_code; + { + *code = use_code; + sign = TYPE_SIGN (TREE_TYPE (gimple_assign_lhs (use_stmt))); + } else if (use_code != *code) { fail = true; break; } + else if ((use_code == MIN_EXPR + || use_code == MAX_EXPR) + && sign != TYPE_SIGN (TREE_TYPE (gimple_assign_lhs (use_stmt)))) + { + fail = true; + break; + } } return ! fail && ! neg && *code != ERROR_MARK; } Index: gcc/testsuite/gcc.dg/vect/pr92324-3.c =================================================================== --- gcc/testsuite/gcc.dg/vect/pr92324-3.c (nonexistent) +++ gcc/testsuite/gcc.dg/vect/pr92324-3.c (working copy) @@ -0,0 +1,27 @@ +#include "tree-vect.h" + +int a[1024]; +unsigned b[1024]; + +int __attribute__((noipa)) +foo (int n) +{ + int res = 0; + for (int i = 0; i < n; ++i) + { + res = res > a[i] ? res : a[i]; + res = res > b[i] ? res : b[i]; + } + return res; +} + +int main () +{ + check_vect (); + b[3] = (unsigned)__INT_MAX__ + 1; + if (foo (4) != -__INT_MAX__ - 1) + __builtin_abort (); + return 0; +} + +/* { dg-final { scan-tree-dump-not "vectorized \[1-9\] loops" "vect" } } */