From patchwork Mon Mar 4 22:32:34 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 1051522 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-497335-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="OWYcgLEx"; 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 44CvtD5KFVz9s00 for ; Tue, 5 Mar 2019 09:32:50 +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:cc:subject:message-id:reply-to:mime-version :content-type; q=dns; s=default; b=kImZzEkFU3tv3TM+Pq2AcsPjog4xt S1TCJshBYDYEJgrZe9g+h6MBzlWi3yAY7mEBcHJvyPU3zZ8niZdMXMVuvHVMt9x4 koxCWwlCoGKAwerKdtMQ/tn31Y6MWiCd/N3VcKOfM7ozSDX/BOpJQ6VV1mGh+HwA 5ScXclRD7Dv9f0= 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:cc:subject:message-id:reply-to:mime-version :content-type; s=default; bh=oWwdCY0+HowqKe5gKDApNnXvai8=; b=OWY cgLExH1HKx5IziytRYw3/IQegYxC5Wvwzj7FrR+US6ifBbyqr+q+P+LzfCZRvEQ6 MXoObH8xUOi/6rutmPjhJ1dcxh05FoWuf8I+CozEORo+0+vg7oAeacIq4ccTXfhc XHl29lCIRqHD6D+3gulv8qlqyrqFPyBnDpccWVwo= Received: (qmail 90068 invoked by alias); 4 Mar 2019 22:32:42 -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 90043 invoked by uid 89); 4 Mar 2019 22:32:42 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-11.9 required=5.0 tests=BAYES_00, GIT_PATCH_2, GIT_PATCH_3, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=availability, sk:vectori, Hx-languages-length:4204 X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 04 Mar 2019 22:32:40 +0000 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7C01630821E0; Mon, 4 Mar 2019 22:32:39 +0000 (UTC) Received: from tucnak.zalov.cz (ovpn-117-64.ams2.redhat.com [10.36.117.64]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 1C4F71001925; Mon, 4 Mar 2019 22:32:38 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.15.2/8.15.2) with ESMTP id x24MWa6r028633; Mon, 4 Mar 2019 23:32:36 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.15.2/8.15.2/Submit) id x24MWYuk028632; Mon, 4 Mar 2019 23:32:34 +0100 Date: Mon, 4 Mar 2019 23:32:34 +0100 From: Jakub Jelinek To: Richard Biener , Richard Sandiford Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] Guard binary/ternary match.pd patterns to IFN_COND_* with IFN_COND_* availability (PR tree-optimization/89570) Message-ID: <20190304223234.GR7611@tucnak> Reply-To: Jakub Jelinek MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.10.1 (2018-07-13) X-IsSubscribed: yes Hi! As the following testcase shows, these match.pd patterns create temporary GIMPLE stmts even when they aren't going to result in anything useful (all targets except aarch64 right now), besides compile time memory this is bad with -fno-tree-dce because those stmts might not be even valid for the target and we might ICE during expansion. Fixed by guarding them with a vectorized_internal_fn_supported_p test. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? Note, I have no idea how to test this on aarch64, Richard S., can you please do that? Thanks. 2019-03-04 Jakub Jelinek PR tree-optimization/89570 * match.pd (vec_cond into cond_op simplification): Guard with vectorized_internal_fn_supported_p test and #if GIMPLE. * gcc.dg/pr89570.c: New test. Jakub --- gcc/match.pd.jj 2019-01-16 09:35:08.421259263 +0100 +++ gcc/match.pd 2019-03-04 13:00:02.884284658 +0100 @@ -5177,17 +5177,24 @@ (define_operator_list COND_TERNARY if the target can do it in one go. This makes the operation conditional on c, so could drop potentially-trapping arithmetic, but that's a valid simplification if the result of the operation isn't needed. */ +#if GIMPLE (for uncond_op (UNCOND_BINARY) cond_op (COND_BINARY) (simplify (vec_cond @0 (view_convert? (uncond_op@4 @1 @2)) @3) - (with { tree op_type = TREE_TYPE (@4); } - (if (element_precision (type) == element_precision (op_type)) + (with { tree op_type = TREE_TYPE (@4); + internal_fn cond_fn = get_conditional_internal_fn (uncond_op); } + (if (cond_fn != IFN_LAST + && vectorized_internal_fn_supported_p (cond_fn, op_type) + && element_precision (type) == element_precision (op_type)) (view_convert (cond_op @0 @1 @2 (view_convert:op_type @3)))))) (simplify (vec_cond @0 @1 (view_convert? (uncond_op@4 @2 @3))) - (with { tree op_type = TREE_TYPE (@4); } - (if (element_precision (type) == element_precision (op_type)) + (with { tree op_type = TREE_TYPE (@4); + internal_fn cond_fn = get_conditional_internal_fn (uncond_op); } + (if (cond_fn != IFN_LAST + && vectorized_internal_fn_supported_p (cond_fn, op_type) + && element_precision (type) == element_precision (op_type)) (view_convert (cond_op (bit_not @0) @2 @3 (view_convert:op_type @1))))))) /* Same for ternary operations. */ @@ -5195,15 +5202,24 @@ (define_operator_list COND_TERNARY cond_op (COND_TERNARY) (simplify (vec_cond @0 (view_convert? (uncond_op@5 @1 @2 @3)) @4) - (with { tree op_type = TREE_TYPE (@5); } - (if (element_precision (type) == element_precision (op_type)) + (with { tree op_type = TREE_TYPE (@5); + internal_fn cond_fn + = get_conditional_internal_fn (as_internal_fn (uncond_op)); } + (if (cond_fn != IFN_LAST + && vectorized_internal_fn_supported_p (cond_fn, op_type) + && element_precision (type) == element_precision (op_type)) (view_convert (cond_op @0 @1 @2 @3 (view_convert:op_type @4)))))) (simplify (vec_cond @0 @1 (view_convert? (uncond_op@5 @2 @3 @4))) - (with { tree op_type = TREE_TYPE (@5); } - (if (element_precision (type) == element_precision (op_type)) + (with { tree op_type = TREE_TYPE (@5); + internal_fn cond_fn + = get_conditional_internal_fn (as_internal_fn (uncond_op)); } + (if (cond_fn != IFN_LAST + && vectorized_internal_fn_supported_p (cond_fn, op_type) + && element_precision (type) == element_precision (op_type)) (view_convert (cond_op (bit_not @0) @2 @3 @4 (view_convert:op_type @1))))))) +#endif /* Detect cases in which a VEC_COND_EXPR effectively replaces the "else" value of an IFN_COND_*. */ --- gcc/testsuite/gcc.dg/pr89570.c.jj 2019-03-04 13:04:00.459544926 +0100 +++ gcc/testsuite/gcc.dg/pr89570.c 2019-03-04 13:03:44.157801534 +0100 @@ -0,0 +1,15 @@ +/* PR tree-optimization/89570 */ +/* { dg-do compile } */ +/* { dg-options "-O1 -ftree-vectorize -fno-trapping-math -fno-tree-dce -fno-tree-dominator-opts" } */ +/* { dg-additional-options "-mvsx" { target powerpc_vsx_ok } } */ + +void +foo (double *x, double *y, double *z) +{ + int i; + for (i = 0; i < 7; i += 2) + { + x[i] = y[i] ? z[i] / 2.0 : z[i]; + x[i + 1] = y[i + 1] ? z[i + 1] / 2.0 : z[i + 1]; + } +}