From: Jakub Jelinek Date: Thu, 10 Aug 2023 15:29:23 +0000 (+0200) Subject: phiopt: Fix phiopt ICE on vops [PR102989] X-Git-Tag: basepoints/gcc-15~7011 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8afe9d5d2fdd047cbd4e3531170af6b66d30e74a;p=thirdparty%2Fgcc.git phiopt: Fix phiopt ICE on vops [PR102989] I've ran into ICE on gcc.dg/torture/bitint-42.c with -O1 or -Os when enabling expensive tests, and unfortunately I can't reproduce without _BitInt. The IL before phiopt3 has: [local count: 203190070]: # .MEM_428 = VDEF <.MEM_367> bitint.159 = VIEW_CONVERT_EXPR(*.LC3); goto ; [100.00%] [local count: 203190070]: # .MEM_427 = VDEF <.MEM_367> bitint.159 = VIEW_CONVERT_EXPR(*.LC4); [local count: 406380139]: # .MEM_368 = PHI <.MEM_428(87), .MEM_427(88)> # VUSE <.MEM_368> _123 = VIEW_CONVERT_EXPR(r495[i_107].D.2780)[0]; and factor_out_conditional_operation is called on the vop PHI, it sees it has exactly two operands and defining statements of both PHI arguments are converts (VCEs in this case), so it thinks it is a good idea to try to optimize that and while doing that it constructs void type SSA_NAMEs and the like. 2023-08-10 Jakub Jelinek PR c/102989 * tree-ssa-phiopt.cc (single_non_singleton_phi_for_edges): Never return virtual phis and return NULL if there is a virtual phi where the arguments from E0 and E1 edges aren't equal. --- diff --git a/gcc/tree-ssa-phiopt.cc b/gcc/tree-ssa-phiopt.cc index ff36bb0119b5..485662dfcc7c 100644 --- a/gcc/tree-ssa-phiopt.cc +++ b/gcc/tree-ssa-phiopt.cc @@ -63,7 +63,13 @@ single_non_singleton_phi_for_edges (gimple_seq seq, edge e0, edge e1) gimple_stmt_iterator i; gphi *phi = NULL; if (gimple_seq_singleton_p (seq)) - return as_a (gsi_stmt (gsi_start (seq))); + { + phi = as_a (gsi_stmt (gsi_start (seq))); + /* Never return virtual phis. */ + if (virtual_operand_p (gimple_phi_result (phi))) + return NULL; + return phi; + } for (i = gsi_start (seq); !gsi_end_p (i); gsi_next (&i)) { gphi *p = as_a (gsi_stmt (i)); @@ -72,6 +78,10 @@ single_non_singleton_phi_for_edges (gimple_seq seq, edge e0, edge e1) gimple_phi_arg_def (p, e1->dest_idx))) continue; + /* Punt on virtual phis with different arguments from the edges. */ + if (virtual_operand_p (gimple_phi_result (p))) + return NULL; + /* If we already have a PHI that has the two edge arguments are different, then return it is not a singleton for these PHIs. */ if (phi)