https://gcc.gnu.org/bugzilla/show_bug.cgi?id=118565
Bug ID: 118565 Summary: match.pd patterns with non-leaf useless conversions result in SSA copies Product: gcc Version: 15.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: rguenth at gcc dot gnu.org Target Milestone: --- In PR117875 we can see that patterns like /* A >= B ? A : B -> max (A, B) and friends. The code is still in fold_cond_expr_with_comparison for GENERIC folding with some extra constraints. */ (for cmp (eq ne le lt unle unlt ge gt unge ungt uneq ltgt) (simplify (cond (cmp:c (nop_convert1?@c0 @0) (nop_convert2?@c1 @1)) (convert3? @0) (convert4? @1)) ... (if (!HONOR_NANS (type)) (if (VECTOR_TYPE_P (type)) (view_convert (max @c0 @c1)) (convert (max @c0 @c1))))) can end up doing the following via VN done after if-conversion before vectorization: Value numbering stmt = _ifc__350 = _1287 ? _ifc__348 : _ifc__349; Applying pattern match.pd:6569, gimple-match-3.cc:47593 Setting value number of _ifc__350 to _ifc__350 (changed) Applying pattern match.pd:5271, gimple-match-4.cc:7879 Applying pattern match.pd:6365, gimple-match-5.cc:6177 Applying pattern match.pd:6569, gimple-match-3.cc:47593 gimple_simplified to _1750 = MAX_EXPR <_1359, -987654321>; _ifc__350 = _1750; Making available beyond BB58 _ifc__350 for value _ifc__350 where the SSA copy is redundant caused by pushing (max ..) to 'seq' before simplifying the (convert ..). Also VN elimination does fold substituted into stmts with allowing multiple replacement stmts but it does not (when not iterating) value-number those which would have eliminated the copy. It's best to not create such copies, thus for a fix in genmatch.