From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by sourceware.org (Postfix) with ESMTPS id 0C1323853C19 for ; Wed, 4 Aug 2021 10:33:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 0C1323853C19 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.de Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id EEBDA1FDBF for ; Wed, 4 Aug 2021 10:33:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1628073193; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type; bh=SuEGCICsic71syrvU40eRbWBbfrcOmxjNb+TNVDes6U=; b=vqBKakU+Sfy8DZNbUvKSTXlX1EF63QbwjbCZOFBFwVbzMe9Q7WwI7e5vq7D8izpOB8773a NapvoaHltItynvQ6fotxJ5Cn92I7rZxTzvJUZkd9sQKw2XX+V7Lpz5MbQ5HxOIHcXS3Qz9 C8ElzJuznASMsyQDQCQ7dcL7vYnYofE= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1628073193; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type; bh=SuEGCICsic71syrvU40eRbWBbfrcOmxjNb+TNVDes6U=; b=SvnByylSP7FVXycVSO4DhSq9ZY5UUpf7H5sxidFO9nboI8nQeMt/sVv+PiQY4EXIvUMWPD ysxnOFw+N5EpC3CQ== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id DDAAF139FD for ; Wed, 4 Aug 2021 10:33:13 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id 7mkZNelsCmHWLAAAMHmgww (envelope-from ) for ; Wed, 04 Aug 2021 10:33:13 +0000 Date: Wed, 4 Aug 2021 12:33:13 +0200 (CEST) From: Richard Biener To: gcc-patches@gcc.gnu.org Subject: [PATCH] tree-optimization/101756 - avoid vectorizing boolean MAX reductions Message-ID: <86pror2n-q58o-n3qs-s9q3-79524p924oo9@fhfr.qr> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-Spam-Status: No, score=-11.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 04 Aug 2021 10:33:16 -0000 The following avoids vectorizing MIN/MAX reductions on bools which, when ending up as vector(2) would need to be adjusted because of the sign change. The fix instead avoids any reduction vectorization where the result isn't compatible to the original scalar type since we don't compensate for that either. Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed. 2021-08-04 Richard Biener PR tree-optimization/101756 * tree-vect-slp.c (vectorizable_bb_reduc_epilogue): Make sure the result of the reduction epilogue is compatible to the original scalar result. * gcc.dg/vect/bb-slp-pr101756.c: New testcase. --- gcc/testsuite/gcc.dg/vect/bb-slp-pr101756.c | 15 +++++++++++++++ gcc/tree-vect-slp.c | 8 +++++--- 2 files changed, 20 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/vect/bb-slp-pr101756.c diff --git a/gcc/testsuite/gcc.dg/vect/bb-slp-pr101756.c b/gcc/testsuite/gcc.dg/vect/bb-slp-pr101756.c new file mode 100644 index 00000000000..9420e77f64e --- /dev/null +++ b/gcc/testsuite/gcc.dg/vect/bb-slp-pr101756.c @@ -0,0 +1,15 @@ +/* { dg-do compile } */ + +__attribute__ ((simd)) int +tq (long int ea, int of, int kk) +{ + int bc; + + for (bc = 0; bc < 2; ++bc) + { + ++ea; + of |= !!kk < !!ea; + } + + return of; +} diff --git a/gcc/tree-vect-slp.c b/gcc/tree-vect-slp.c index a554c24e0fb..d169bed8e94 100644 --- a/gcc/tree-vect-slp.c +++ b/gcc/tree-vect-slp.c @@ -4847,15 +4847,17 @@ static bool vectorizable_bb_reduc_epilogue (slp_instance instance, stmt_vector_for_cost *cost_vec) { - enum tree_code reduc_code - = gimple_assign_rhs_code (instance->root_stmts[0]->stmt); + gassign *stmt = as_a (instance->root_stmts[0]->stmt); + enum tree_code reduc_code = gimple_assign_rhs_code (stmt); if (reduc_code == MINUS_EXPR) reduc_code = PLUS_EXPR; internal_fn reduc_fn; tree vectype = SLP_TREE_VECTYPE (SLP_INSTANCE_TREE (instance)); if (!reduction_fn_for_scalar_code (reduc_code, &reduc_fn) || reduc_fn == IFN_LAST - || !direct_internal_fn_supported_p (reduc_fn, vectype, OPTIMIZE_FOR_BOTH)) + || !direct_internal_fn_supported_p (reduc_fn, vectype, OPTIMIZE_FOR_BOTH) + || !useless_type_conversion_p (TREE_TYPE (gimple_assign_lhs (stmt)), + TREE_TYPE (vectype))) return false; /* There's no way to cost a horizontal vector reduction via REDUC_FN so -- 2.31.1