https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104601
Jakub Jelinek <jakub at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |rguenth at gcc dot gnu.org --- Comment #8 from Jakub Jelinek <jakub at gcc dot gnu.org> --- I believe the bug is in visit_reference_op_call: 5241 /* If we value numbered an indirect functions function to 5242 one not clobbering memory value number its VDEF to its 5243 VUSE. */ 5244 tree fn = gimple_call_fn (stmt); 5245 if (fn && TREE_CODE (fn) == SSA_NAME) 5246 { 5247 fn = SSA_VAL (fn); 5248 if (TREE_CODE (fn) == ADDR_EXPR 5249 && TREE_CODE (TREE_OPERAND (fn, 0)) == FUNCTION_DECL 5250 && (flags_from_decl_or_type (TREE_OPERAND (fn, 0)) 5251 & (ECF_CONST | ECF_PURE))) 5252 vdef_val = vuse_ssa_val (gimple_vuse (stmt)); 5253 } 5254 changed |= set_ssa_val_to (vdef, vdef_val); stmt in this case is: # .MEM_140 = VDEF <.MEM_96> *__pred$__d_43 = _50 (_49); and _50 value numbers to &f where f is a const function. I think we can value number the vdef to vuse_ssa_val (gimple_vuse (stmt)) only if the lhs of the call is not present or is an SSA_NAME, when the call (const or pure) acts as a store, we shouldn't do that. A few lines before this there is also: if (vnresult->result_vdef && vdef) changed |= set_ssa_val_to (vdef, vnresult->result_vdef); else if (vdef) /* If the call was discovered to be pure or const reflect that as far as possible. */ changed |= set_ssa_val_to (vdef, vuse_ssa_val (gimple_vuse (stmt))); I wonder if that doesn't suffer from the same problem.