From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) by sourceware.org (Postfix) with ESMTPS id E0CDD3858D3C for ; Wed, 6 Dec 2023 09:48:02 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E0CDD3858D3C 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 E0CDD3858D3C Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=195.135.223.130 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701856085; cv=none; b=rWjP5FbrY28vKZMueGOetEdN5byCQEos3mzaygAkFifuoTovGJ3ejiDXgQGccx2r6G1nOuR+1438lnD5VP9Y/2CyPY29dWbylMzeEQEBHpJNWq9/vYSX0Ly0wih5IYUparx0K0vBMLloHABB+T/+mjXaF1eRTbJ3rS3VwxdiJgM= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701856085; c=relaxed/simple; bh=5BYTDCWux33qlMbHpsCqiWeI4UW7DGuWNbMfFTdp7MI=; h=DKIM-Signature:DKIM-Signature:Date:From:To:Subject:Message-ID: MIME-Version; b=nfO+SPa0bAGcg7rqIx/O5qO7RnqFfa3WLf8zw7FpgBNOLvxxr80sDfOLIp3dv1WAqmkrNRfxe0iYXYv5M3acx1h54E1jfIa31JFlByDBvunNVh4R4sTQRLjlJVBoR64oqhFzysreNAxG8NriSO9VmNG4F8poAfB9eCqp1dGlYH0= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from [10.168.4.150] (unknown [10.168.4.150]) (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 E147C21EEF; Wed, 6 Dec 2023 09:48:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1701856080; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=VmdWdMWYVCqB8uFl8+DDGSW7YVzcROYVjH2M53Ulx6o=; b=OA+aqqhqOOzM9UZ/cFdV7vFS+P4MIA9rr0th3FLQxveToNFG6K0CuAs7yAhStyAocS6QLV 3XFEqwfiso/by+ELO6qzr3pItx9j07E6EjVfeEa5g+DliPRMz3QXCq89Ddgqn8Ztq1RA3z AomDJVBbBwXXb0svEOS3c4X6yHoNuQo= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1701856080; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=VmdWdMWYVCqB8uFl8+DDGSW7YVzcROYVjH2M53Ulx6o=; b=0LIbFGjWhlFdI51o4+D0lkk7XnRCHl3vYikFNWmD4qYCFyN+k6IMQ66P643HzyBJ9U0ZjX WQfswCXz5yWv0RAg== Date: Wed, 6 Dec 2023 10:44:15 +0100 (CET) From: Richard Biener To: Tamar Christina cc: "gcc-patches@gcc.gnu.org" , nd , "jlaw@ventanamicro.com" Subject: RE: [PATCH 10/21]middle-end: implement relevancy analysis support for control flow In-Reply-To: Message-ID: <3q001r16-r585-p5sr-16q2-6o06783sqs71@fhfr.qr> References: <5q17320p-3978-40o2-p8qn-415982q767nn@fhfr.qr> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-Spamd-Result: default: False [-4.25 / 50.00]; ARC_NA(0.00)[]; TO_DN_EQ_ADDR_SOME(0.00)[]; FROM_HAS_DN(0.00)[]; RCPT_COUNT_THREE(0.00)[4]; TO_DN_SOME(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; MIME_GOOD(-0.10)[text/plain]; NEURAL_HAM_LONG(-1.00)[-1.000]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; NEURAL_HAM_SHORT(-0.15)[-0.770]; DBL_BLOCKED_OPENRESOLVER(0.00)[tree-vect-stmts.cc:url,suse.de:email,tree-vect-patterns.cc:url]; FUZZY_BLOCKED(0.00)[rspamd.com]; RCVD_COUNT_ZERO(0.00)[0]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; BAYES_HAM(-3.00)[100.00%] X-Spam-Score: -4.25 Authentication-Results: smtp-out1.suse.de; none X-Spam-Level: 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,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: On Wed, 6 Dec 2023, Tamar Christina wrote: > > > > + && LOOP_VINFO_LOOP_IV_COND (loop_vinfo) != cond) > > > > + *relevant = vect_used_in_scope; > > > > but why not simply mark all gconds as vect_used_in_scope? > > > > We break outer-loop vectorization since doing so would pull the inner loop's > exit into scope for the outerloop. Also we can't force the loop's main IV exit > to be in scope, since it will be replaced by the vectorizer. > > I've updated the code to remove the quadratic lookup. > > > > > + } > > > > > > > > /* changing memory. */ > > > > if (gimple_code (stmt_info->stmt) != GIMPLE_PHI) @@ -374,6 +379,11 @@ > > > > vect_stmt_relevant_p (stmt_vec_info stmt_info, loop_vec_info loop_vinfo, > > > > *relevant = vect_used_in_scope; > > > > } > > > > > > > > + auto_vec exits = get_loop_exit_edges (loop); auto_bitmap > > > > + exit_bbs; for (edge exit : exits) > > > > is it your mail client messing patches up? missing line-break > > again. > > > > Yeah, seems it was, hopefully fixed now. > > > > > + bitmap_set_bit (exit_bbs, exit->dest->index); > > > > + > > > > you don't seem to use the bitmap? > > > > > > /* uses outside the loop. */ > > > > FOR_EACH_PHI_OR_STMT_DEF (def_p, stmt_info->stmt, op_iter, > > > > SSA_OP_DEF) > > > > { > > > > @@ -392,7 +402,6 @@ vect_stmt_relevant_p (stmt_vec_info stmt_info, > > > > loop_vec_info loop_vinfo, > > > > /* We expect all such uses to be in the loop exit phis > > > > (because of loop closed form) */ > > > > gcc_assert (gimple_code (USE_STMT (use_p)) == GIMPLE_PHI); > > > > - gcc_assert (bb == single_exit (loop)->dest); > > > > > > > > *live_p = true; > > > > } > > > > @@ -793,6 +802,20 @@ vect_mark_stmts_to_be_vectorized (loop_vec_info > > > > loop_vinfo, bool *fatal) > > > > return res; > > > > } > > > > } > > > > + } > > > > + else if (gcond *cond = dyn_cast (stmt_vinfo->stmt)) > > > > + { > > > > + enum tree_code rhs_code = gimple_cond_code (cond); > > > > + gcc_assert (TREE_CODE_CLASS (rhs_code) == tcc_comparison); > > > > + opt_result res > > > > + = process_use (stmt_vinfo, gimple_cond_lhs (cond), > > > > + loop_vinfo, relevant, &worklist, false); > > > > + if (!res) > > > > + return res; > > > > + res = process_use (stmt_vinfo, gimple_cond_rhs (cond), > > > > + loop_vinfo, relevant, &worklist, false); > > > > + if (!res) > > > > + return res; > > > > } > > > > I guess we're missing an > > > > else > > gcc_unreachable (); > > > > to catch not handled stmt kinds (do we have gcond patterns yet?) > > > > > > else if (gcall *call = dyn_cast (stmt_vinfo->stmt)) > > > > { > > > > @@ -13043,11 +13066,15 @@ vect_analyze_stmt (vec_info *vinfo, > > > > node_instance, cost_vec); > > > > if (!res) > > > > return res; > > > > - } > > > > + } > > > > + > > > > + if (is_ctrl_stmt (stmt_info->stmt)) > > > > + STMT_VINFO_DEF_TYPE (stmt_info) = vect_early_exit_def; > > > > I think it should rather be vect_condition_def. It's also not > > this functions business to set STMT_VINFO_DEF_TYPE. If we ever > > get to handle not if-converted code (or BB vectorization of that) > > then a gcond would define the mask stmts are under. > > > > Hmm sure, I've had to place it in multiple other places but moved it > away from here. The main ones are set during dataflow analysis when > we determine which statements need to be moved. I'd have set it where we set STMT_VINFO_TYPE on conds to loop_exit_ctrl_vec_info_type. The patch below has it in vect_mark_pattern_stmts only? Guess it's in the other patch(es) now. > > > > switch (STMT_VINFO_DEF_TYPE (stmt_info)) > > > > { > > > > case vect_internal_def: > > > > + case vect_early_exit_def: > > > > break; > > > > > > > > case vect_reduction_def: > > > > @@ -13080,6 +13107,7 @@ vect_analyze_stmt (vec_info *vinfo, > > > > { > > > > gcall *call = dyn_cast (stmt_info->stmt); > > > > gcc_assert (STMT_VINFO_VECTYPE (stmt_info) > > > > + || gimple_code (stmt_info->stmt) == GIMPLE_COND > > > > || (call && gimple_call_lhs (call) == NULL_TREE)); > > > > *need_to_vectorize = true; > > > > } > > > > @@ -13835,6 +13863,14 @@ vect_is_simple_use (vec_info *vinfo, > > > > stmt_vec_info stmt, slp_tree slp_node, > > > > else > > > > *op = gimple_op (ass, operand + 1); > > > > } > > > > + else if (gcond *cond = dyn_cast (stmt->stmt)) > > > > + { > > > > + gimple_match_op m_op; > > > > + if (!gimple_extract_op (cond, &m_op)) > > > > + return false; > > > > + gcc_assert (m_op.code.is_tree_code ()); > > > > + *op = m_op.ops[operand]; > > > > + } > > > > Please do not use gimple_extract_op, use > > > > *op = gimple_op (cond, operand); > > > > > > else if (gcall *call = dyn_cast (stmt->stmt)) > > > > *op = gimple_call_arg (call, operand); > > > > else > > > > @@ -14445,6 +14481,8 @@ vect_get_vector_types_for_stmt (vec_info > > > > *vinfo, stmt_vec_info stmt_info, > > > > *nunits_vectype_out = NULL_TREE; > > > > > > > > if (gimple_get_lhs (stmt) == NULL_TREE > > > > + /* Allow vector conditionals through here. */ > > > > + && !is_ctrl_stmt (stmt) > > > > !is_a (stmt) > > > > > > /* MASK_STORE has no lhs, but is ok. */ > > > > && !gimple_call_internal_p (stmt, IFN_MASK_STORE)) > > > > { > > > > @@ -14461,7 +14499,7 @@ vect_get_vector_types_for_stmt (vec_info > > > > *vinfo, stmt_vec_info stmt_info, > > > > } > > > > > > > > return opt_result::failure_at (stmt, > > > > - "not vectorized: irregular stmt.%G", stmt); > > > > + "not vectorized: irregular stmt: %G", stmt); > > > > } > > > > > > > > tree vectype; > > > > @@ -14490,6 +14528,14 @@ vect_get_vector_types_for_stmt (vec_info > > > > *vinfo, stmt_vec_info stmt_info, > > > > scalar_type = TREE_TYPE (DR_REF (dr)); > > > > else if (gimple_call_internal_p (stmt, IFN_MASK_STORE)) > > > > scalar_type = TREE_TYPE (gimple_call_arg (stmt, 3)); > > > > + else if (is_ctrl_stmt (stmt)) > > > > else if (gcond *cond = dyn_cast <...>) > > > > > > + { > > > > + gcond *cond = dyn_cast (stmt); > > > > + if (!cond) > > > > + return opt_result::failure_at (stmt, "not vectorized: unsupported" > > > > + " control flow statement.\n"); > > > > + scalar_type = TREE_TYPE (gimple_cond_rhs (stmt)); > > > > As said in the other patch STMT_VINFO_VECTYPE of the gcond should > > be the _mask_ type the compare produces, not the vector type of > > the inputs (the nunits_vectype might be that one though). > > You possibly need to adjust vect_get_smallest_scalar_type for this. > > > > Fixed, but is in other patch now. > > Ok for master? OK. Richard. > Thanks, > Tamar > > gcc/ChangeLog: > > * tree-vect-patterns.cc (vect_mark_pattern_stmts): Support gcond > patterns. > * tree-vect-stmts.cc (vect_stmt_relevant_p, > vect_mark_stmts_to_be_vectorized, vect_analyze_stmt, vect_is_simple_use, > vect_get_vector_types_for_stmt): Support early breaks. > > --- inline copy of patch --- > > diff --git a/gcc/tree-vect-patterns.cc b/gcc/tree-vect-patterns.cc > index c6cedf4fe7c1f1e1126ce166a059a4b2a2b49cbd..ea59ad337f14d802607850e8a7cf0125777ce2bc 100644 > --- a/gcc/tree-vect-patterns.cc > +++ b/gcc/tree-vect-patterns.cc > @@ -6987,6 +6987,10 @@ vect_mark_pattern_stmts (vec_info *vinfo, > vect_set_pattern_stmt (vinfo, > pattern_stmt, orig_stmt_info, pattern_vectype); > > + /* For any conditionals mark them as vect_condition_def. */ > + if (is_a (pattern_stmt)) > + STMT_VINFO_DEF_TYPE (STMT_VINFO_RELATED_STMT (orig_stmt_info)) = vect_condition_def; > + > /* Transfer reduction path info to the pattern. */ > if (STMT_VINFO_REDUC_IDX (orig_stmt_info_saved) != -1) > { > diff --git a/gcc/tree-vect-stmts.cc b/gcc/tree-vect-stmts.cc > index d801b72a149ebe6aa4d1f2942324b042d07be530..1e2698fcb7e95ae7f0009d10a79ba8c891a8227d 100644 > --- a/gcc/tree-vect-stmts.cc > +++ b/gcc/tree-vect-stmts.cc > @@ -361,7 +361,9 @@ vect_stmt_relevant_p (stmt_vec_info stmt_info, loop_vec_info loop_vinfo, > > /* cond stmt other than loop exit cond. */ > gimple *stmt = STMT_VINFO_STMT (stmt_info); > - if (dyn_cast (stmt)) > + if (is_a (stmt) > + && LOOP_VINFO_LOOP_IV_COND (loop_vinfo) != stmt > + && (!loop->inner || gimple_bb (stmt)->loop_father == loop)) > *relevant = vect_used_in_scope; > > /* changing memory. */ > @@ -393,7 +395,6 @@ vect_stmt_relevant_p (stmt_vec_info stmt_info, loop_vec_info loop_vinfo, > /* We expect all such uses to be in the loop exit phis > (because of loop closed form) */ > gcc_assert (gimple_code (USE_STMT (use_p)) == GIMPLE_PHI); > - gcc_assert (bb == single_exit (loop)->dest); > > *live_p = true; > } > @@ -807,6 +808,20 @@ vect_mark_stmts_to_be_vectorized (loop_vec_info loop_vinfo, bool *fatal) > return res; > } > } > + } > + else if (gcond *cond = dyn_cast (stmt_vinfo->stmt)) > + { > + enum tree_code rhs_code = gimple_cond_code (cond); > + gcc_assert (TREE_CODE_CLASS (rhs_code) == tcc_comparison); > + opt_result res > + = process_use (stmt_vinfo, gimple_cond_lhs (cond), > + loop_vinfo, relevant, &worklist, false); > + if (!res) > + return res; > + res = process_use (stmt_vinfo, gimple_cond_rhs (cond), > + loop_vinfo, relevant, &worklist, false); > + if (!res) > + return res; > } > else if (gcall *call = dyn_cast (stmt_vinfo->stmt)) > { > @@ -820,6 +835,8 @@ vect_mark_stmts_to_be_vectorized (loop_vec_info loop_vinfo, bool *fatal) > return res; > } > } > + else > + gcc_unreachable (); > } > else > FOR_EACH_PHI_OR_STMT_USE (use_p, stmt_vinfo->stmt, iter, SSA_OP_USE) > @@ -13044,11 +13061,12 @@ vect_analyze_stmt (vec_info *vinfo, > node_instance, cost_vec); > if (!res) > return res; > - } > + } > > switch (STMT_VINFO_DEF_TYPE (stmt_info)) > { > case vect_internal_def: > + case vect_condition_def: > break; > > case vect_reduction_def: > @@ -13081,6 +13099,7 @@ vect_analyze_stmt (vec_info *vinfo, > { > gcall *call = dyn_cast (stmt_info->stmt); > gcc_assert (STMT_VINFO_VECTYPE (stmt_info) > + || gimple_code (stmt_info->stmt) == GIMPLE_COND > || (call && gimple_call_lhs (call) == NULL_TREE)); > *need_to_vectorize = true; > } > @@ -13855,6 +13874,8 @@ vect_is_simple_use (vec_info *vinfo, stmt_vec_info stmt, slp_tree slp_node, > else > *op = gimple_op (ass, operand + 1); > } > + else if (gcond *cond = dyn_cast (stmt->stmt)) > + *op = gimple_op (cond, operand); > else if (gcall *call = dyn_cast (stmt->stmt)) > *op = gimple_call_arg (call, operand); > else > @@ -14465,6 +14486,8 @@ vect_get_vector_types_for_stmt (vec_info *vinfo, stmt_vec_info stmt_info, > *nunits_vectype_out = NULL_TREE; > > if (gimple_get_lhs (stmt) == NULL_TREE > + /* Allow vector conditionals through here. */ > + && !is_a (stmt) > /* MASK_STORE has no lhs, but is ok. */ > && !gimple_call_internal_p (stmt, IFN_MASK_STORE)) > { > @@ -14481,7 +14504,7 @@ vect_get_vector_types_for_stmt (vec_info *vinfo, stmt_vec_info stmt_info, > } > > return opt_result::failure_at (stmt, > - "not vectorized: irregular stmt.%G", stmt); > + "not vectorized: irregular stmt: %G", stmt); > } > > tree vectype; > -- Richard Biener SUSE Software Solutions Germany GmbH, Frankenstrasse 146, 90461 Nuernberg, Germany; GF: Ivo Totev, Andrew McDonald, Werner Knoblich; (HRB 36809, AG Nuernberg)