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 26B183858D28 for ; Wed, 3 May 2023 10:13:11 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 26B183858D28 Authentication-Results: sourceware.org; dmarc=pass (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 2863520202 for ; Wed, 3 May 2023 10:13:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1683108790; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type; bh=iP0RNQIxyK3zajg0vk5K4PpBLy90cilY6VgZvAFb9RM=; b=TBVQromahUqzsFZ/gukWJ7XKwdF13n/l5WhcCYIFX2IjaGlhePWt4lPnITNFaUm+Wn2U4q zs/+2K6Vl1m7NtpJD1ryjDWfkhfbPbiwHE5Q77O+2eeB7x55U6e/F+LeOzWgUR6eZhv6zq +6RmWvLJj3T2HfTUSDFiXhZrZGbsa2s= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1683108790; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type; bh=iP0RNQIxyK3zajg0vk5K4PpBLy90cilY6VgZvAFb9RM=; b=PXhCFCK2aiuIfbEXgbO/sGUJZbkVB5R7GhgHpg+Z6XNdhMURD+AsLWwaDfNHbsWehvQvlI 4nFl6IfwiiG7RrCg== 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 143791331F for ; Wed, 3 May 2023 10:13:10 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id 3M24A7YzUmQ9LgAAMHmgww (envelope-from ) for ; Wed, 03 May 2023 10:13:10 +0000 Date: Wed, 3 May 2023 12:13:09 +0200 (CEST) From: Richard Biener To: gcc-patches@gcc.gnu.org Subject: [PATCH][GCC 11] tree-optimization/109473 - fix type mismatch in reduction vectorization MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Message-Id: <20230503101310.143791331F@imap2.suse-dmz.suse.de> X-Spam-Status: No, score=-11.8 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,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: When backporting the PR109473 fix I failed to realize its testcase will run into an unrelated similar bug. With GCC 12 the code has seen substantial refactoring so the following applies a local fix to make sure we are using the correct types when building initial values for reductions. Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed. PR tree-optimization/109473 * tree-vect-loop.cc (get_initial_def_for_reduction): Convert the scalar values to the vector component type before using it to build the vector for the initial value. --- gcc/tree-vect-loop.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/gcc/tree-vect-loop.c b/gcc/tree-vect-loop.c index bb021ccf382..ebdba65c55e 100644 --- a/gcc/tree-vect-loop.c +++ b/gcc/tree-vect-loop.c @@ -4730,10 +4730,14 @@ get_initial_def_for_reduction (loop_vec_info loop_vinfo, else def_for_init = build_int_cst (scalar_type, int_init_val); - if (adjustment_def || operand_equal_p (def_for_init, init_val, 0)) + bool same_p = operand_equal_p (def_for_init, init_val, 0); + init_val = gimple_convert (&stmts, TREE_TYPE (vectype), init_val); + def_for_init = gimple_convert (&stmts, TREE_TYPE (vectype), def_for_init); + + if (adjustment_def || same_p) { /* Option1: the first element is '0' or '1' as well. */ - if (!operand_equal_p (def_for_init, init_val, 0)) + if (!same_p) *adjustment_def = init_val; init_def = gimple_build_vector_from_val (&stmts, vectype, def_for_init); -- 2.35.3