From patchwork Wed Aug 5 15:00:03 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 140666 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 267624BAE7E4 for ; Wed, 5 Aug 2026 15:00:52 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 267624BAE7E4 Authentication-Results: sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=HYeK/ZLm; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=BDDMtNcy; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=aVo4BdqA; dkim=neutral header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=MKz/Sitv X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) by sourceware.org (Postfix) with ESMTPS id 428DB4BA79A6 for ; Wed, 5 Aug 2026 15:00:12 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 428DB4BA79A6 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.de ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 428DB4BA79A6 Authentication-Results: sourceware.org; arc=none smtp.remote-ip=195.135.223.130 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1785942012; cv=none; b=HywFf1WxZMppjKqJzElfTQhp6tkk/gp11cEo4kMEN52dz+AwViCG9bwtedQkcXlYVuW17nJUB1pf8/iWJ6BNDRdVsW8tRaQRUTrdm55OOZL9LSFdHrL1GOj9pCQ5CkoVGxYrRG2y7XMrLGlRsB/MNo7G4GcAfVPCEH50G0OIxn8= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1785942012; c=relaxed/simple; bh=zcdxkZ1IdY/hdVIJHZSyAZnd7ioI3sXyxExUMFY9R10=; h=DKIM-Signature:DKIM-Signature:DKIM-Signature:DKIM-Signature:Date: From:To:Subject:Message-ID:MIME-Version; b=KYt6N4gGfYkIa839WGxPCs+LFHht0cVuBJh3WlV+LlJxgEMX6It0tVzHKUjRI/YyR33gUrirM+r/XacuzciCOMWUIQuFbqNEvXkJU5B88jJ2rfabFtLC8fs/PBAm/7xi1nc/9ifLh75AgkllrmZygdqtp67jyQomb9tuGmRsguM= ARC-Authentication-Results: i=1; sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=HYeK/ZLm; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=BDDMtNcy; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=aVo4BdqA; dkim=neutral header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=MKz/Sitv DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 428DB4BA79A6 Received: from murzim.nue2.suse.org (unknown [10.168.4.243]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 38B3F7F18A for ; Wed, 5 Aug 2026 15:00:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1785942007; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type; bh=yDyBqhEaVonJl72ZZYO+meKl/FXmSfHDgzoROVYj33k=; b=HYeK/ZLmhpw56BJYjephI5z2LAZlXuLjoaBEFRc6ZX8x/I+XN38OGYUKr3pJ6Aj2VnCqCM skvqlIA6el1bgQt3aphMgKU5/usNgdy1xobpVV/bkauALXmUdapHflCj2vcHX76iBSgDW9 BO+IlObRz4oMZR+WKofcXbIvNRRZPmA= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1785942007; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type; bh=yDyBqhEaVonJl72ZZYO+meKl/FXmSfHDgzoROVYj33k=; b=BDDMtNcyu/cCaZCKKZUpMQdB4j8M6J3rar1N+GdNdG6szabC+ywlHgQq04Ly8FjDhk8Z4B ecN7Z62bRBdmPUBQ== Authentication-Results: smtp-out1.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1785942003; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type; bh=yDyBqhEaVonJl72ZZYO+meKl/FXmSfHDgzoROVYj33k=; b=aVo4BdqAMIkIVKQhlHH9FAGNHjPPLUwnORs92gzln+gqMasx3+Ak/6rjCTit3GkqRydu+7 Uj3jSaPHc+Fm5a4oIV1j/nziYEhO7KbhO+XclhDKwlogpKr2wFqwFfh3j+WpX1dYMQuYji 6iFjcz+WE+lUp6jAm7qkbZe/3PKqOrg= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1785942003; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type; bh=yDyBqhEaVonJl72ZZYO+meKl/FXmSfHDgzoROVYj33k=; b=MKz/Sitvjq9VbmfSbFY79PgGtxpEoMPYM0z6tJO9ryZyOfYRgrwPIPdcxAgOQvE2NGA6RB 8GwRH6/Z0KrVBcAw== Date: Wed, 5 Aug 2026 17:00:03 +0200 (CEST) From: Richard Biener To: gcc-patches@gcc.gnu.org Subject: [PATCH] Cleanup vectorizable_conversion Message-ID: <45no185q-nr63-pq0n-r657-s96r73q017s4@fhfr.qr> MIME-Version: 1.0 X-Spamd-Result: default: False [-4.30 / 50.00]; BAYES_HAM(-3.00)[100.00%]; NEURAL_HAM_LONG(-1.00)[-1.000]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain]; MISSING_XM_UA(0.00)[]; ARC_NA(0.00)[]; RCPT_COUNT_ONE(0.00)[1]; RCVD_COUNT_ZERO(0.00)[0]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; TO_MATCH_ENVRCPT_ALL(0.00)[]; MIME_TRACE(0.00)[0:+]; FROM_EQ_ENVFROM(0.00)[]; TO_DN_NONE(0.00)[]; FROM_HAS_DN(0.00)[] X-Spam-Score: -4.30 X-Spam-Level: X-Spam-Status: No, score=-11.2 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 shortcircuit=no autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces~patchwork=sourceware.org@gcc.gnu.org The following elides the requirements for scalar op0/op1 which, when fed by SLP permutes, cannot be computed. A new overload for vect_is_simple_use provides an easier transition. Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed. * tree-vect-stmts.cc (vectorizable_conversion): Elide op0/op1. (vect_is_simple_use): New overload. (supportable_indirect_convert_operation): Drop optional and unused scalar op argument. * tree-vectorizer.h (supportable_indirect_convert_operation): Adjust prototype. (vect_is_simple_use): New overload. --- gcc/tree-vect-stmts.cc | 53 ++++++++++++++++++++---------------------- gcc/tree-vectorizer.h | 4 +++- 2 files changed, 28 insertions(+), 29 deletions(-) diff --git a/gcc/tree-vect-stmts.cc b/gcc/tree-vect-stmts.cc index 0627dfaefac..2f279ee9288 100644 --- a/gcc/tree-vect-stmts.cc +++ b/gcc/tree-vect-stmts.cc @@ -5287,7 +5287,6 @@ vectorizable_conversion (vec_info *vinfo, { tree vec_dest, cvt_op = NULL_TREE; tree scalar_dest; - tree op0, op1 = NULL_TREE; tree_code tc1; code_helper code, code1, code2; code_helper codecvt1 = ERROR_MARK, codecvt2 = ERROR_MARK; @@ -5369,7 +5368,7 @@ vectorizable_conversion (vec_info *vinfo, /* Check the operands of the operation. */ slp_tree slp_op0, slp_op1 = NULL; if (!vect_is_simple_use (vinfo, slp_node, - 0, &op0, &slp_op0, &dt[0], &vectype_in)) + 0, &slp_op0, &dt[0], &vectype_in)) { if (dump_enabled_p ()) dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location, @@ -5377,7 +5376,7 @@ vectorizable_conversion (vec_info *vinfo, return false; } - rhs_type = TREE_TYPE (op0); + rhs_type = TREE_TYPE (gimple_arg (stmt, 0)); if ((code != FIX_TRUNC_EXPR && code != FLOAT_EXPR) && !((INTEGRAL_TYPE_P (lhs_type) && INTEGRAL_TYPE_P (rhs_type)) @@ -5401,11 +5400,9 @@ vectorizable_conversion (vec_info *vinfo, || code == WIDEN_LSHIFT_EXPR || widening_fn_p (code)); - op1 = is_gimple_assign (stmt) ? gimple_assign_rhs2 (stmt) : - gimple_call_arg (stmt, 0); tree vectype1_in; if (!vect_is_simple_use (vinfo, slp_node, 1, - &op1, &slp_op1, &dt[1], &vectype1_in)) + &slp_op1, &dt[1], &vectype1_in)) { if (dump_enabled_p ()) dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location, @@ -5418,12 +5415,12 @@ vectorizable_conversion (vec_info *vinfo, vectype_in = vectype1_in; } - /* If op0 is an external or constant def, infer the vector type + /* If slp_op0 is an external or constant def, infer the vector type from the scalar type. */ - if (!vectype_in) - vectype_in = get_vectype_for_scalar_type (vinfo, rhs_type, slp_node); if (!cost_vec) gcc_assert (vectype_in); + if (!vectype_in) + vectype_in = get_vectype_for_scalar_type (vinfo, rhs_type, slp_node); if (!vectype_in) { if (dump_enabled_p ()) @@ -5477,7 +5474,7 @@ vectorizable_conversion (vec_info *vinfo, gcc_assert (code.is_tree_code ()); if (supportable_indirect_convert_operation (code, vectype_out, vectype_in, - converts, op0, slp_op0)) + converts, slp_op0)) { gcc_assert (converts.length () <= 2); if (converts.length () == 1) @@ -5626,7 +5623,7 @@ vectorizable_conversion (vec_info *vinfo, &interm_types)) break; } - /* If op0 can be represented with low precision integer, + /* If slp_op0 can be represented with low precision integer, truncate it to cvt_type and the do FLOAT_EXPR. */ else if (code == FLOAT_EXPR) { @@ -5731,14 +5728,6 @@ vectorizable_conversion (vec_info *vinfo, if (dump_enabled_p ()) dump_printf_loc (MSG_NOTE, vect_location, "transform conversion.\n"); - if (op_type == binary_op) - { - if (CONSTANT_CLASS_P (op0)) - op0 = fold_convert (TREE_TYPE (op1), op0); - else if (CONSTANT_CLASS_P (op1)) - op1 = fold_convert (TREE_TYPE (op0), op1); - } - /* In case of multi-step conversion, we first generate conversion operations to the intermediate types, and then from that types to the final one. We create vector destinations for the intermediate type (TYPES) received @@ -5813,7 +5802,7 @@ vectorizable_conversion (vec_info *vinfo, int oprnds_size = vec_oprnds0.length (); vec_oprnds1.create (oprnds_size); for (i = 0; i < oprnds_size; ++i) - vec_oprnds1.quick_push (op1); + vec_oprnds1.quick_push (vect_get_slp_scalar_def (slp_op1, 0)); } /* Arguments are ready. Create the new vector stmts. */ for (i = multi_step_cvt; i >= 0; i--) @@ -5874,7 +5863,7 @@ vectorizable_conversion (vec_info *vinfo, stmt_info, vec_dsts, gsi, slp_node, code1, modifier == NARROW_SRC); - /* After demoting op0 to cvt_type, convert it to dest. */ + /* After demoting slp_op0 to cvt_type, convert it to dest. */ if (cvt_type && code == FLOAT_EXPR) { for (unsigned int i = 0; i != vec_oprnds0.length() / 2; i++) @@ -14020,6 +14009,18 @@ vect_is_simple_use (vec_info *vinfo, slp_tree slp_node, } } +/* Wrapper around vect_is_simple_use that elides the scalar op output. */ + +bool +vect_is_simple_use (vec_info *vinfo, slp_tree slp_node, + unsigned operand, slp_tree *slp_def, + enum vect_def_type *dt, tree *vectype) +{ + tree op; + return vect_is_simple_use (vinfo, slp_node, operand, &op, slp_def, dt, + vectype); +} + /* If OP is not NULL and is external or constant update its vector type with VECTYPE. Returns true if successful or false if not, for example when conflicting vector types are present. */ @@ -14559,7 +14560,7 @@ supportable_indirect_convert_operation (code_helper code, tree vectype_out, tree vectype_in, vec > &converts, - tree op0, slp_tree slp_op0) + slp_tree slp_op0) { bool found_mode = false; scalar_mode lhs_mode = GET_MODE_INNER (TYPE_MODE (vectype_out)); @@ -14626,7 +14627,7 @@ supportable_indirect_convert_operation (code_helper code, if (demotion && float_expr_p) { wide_int op_min_value, op_max_value; - /* For vector form, it looks like op0 doesn't have RANGE_INFO. + /* For vector form, it looks like slp_op0 doesn't have RANGE_INFO. In the future, if it is supported, changes may need to be made to this part, such as checking the RANGE of each element in the vector. */ @@ -14640,11 +14641,7 @@ supportable_indirect_convert_operation (code_helper code, &op_min_value, &op_max_value)) break; } - else if (!op0 - || TREE_CODE (op0) != SSA_NAME - || !SSA_NAME_RANGE_INFO (op0) - || !vect_get_range_info (op0, &op_min_value, - &op_max_value)) + else break; if (cvt_type == NULL_TREE diff --git a/gcc/tree-vectorizer.h b/gcc/tree-vectorizer.h index fd43eaae668..f32364d3160 100644 --- a/gcc/tree-vectorizer.h +++ b/gcc/tree-vectorizer.h @@ -2536,6 +2536,9 @@ extern bool vect_is_simple_use (vec_info *, slp_tree, unsigned, tree *, slp_tree *, enum vect_def_type *, tree *, stmt_vec_info * = NULL); +extern bool vect_is_simple_use (vec_info *, slp_tree, + unsigned, slp_tree *, + enum vect_def_type *, tree *); extern bool vect_maybe_update_slp_op_vectype (slp_tree, tree); extern tree perm_mask_for_reverse (tree); extern bool supportable_widening_operation (code_helper, tree, tree, bool, @@ -2547,7 +2550,6 @@ extern bool supportable_narrowing_operation (code_helper, tree, tree, extern bool supportable_indirect_convert_operation (code_helper, tree, tree, vec > &, - tree = NULL_TREE, slp_tree = NULL); extern int compare_step_with_zero (vec_info *, stmt_vec_info);