We can handle _1 = PHI <_1, _2> as a copy.

Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed.

        PR tree-optimization/84646
        * tree-ssa-forwprop.cc (pass_forwprop::execute): Improve
        copy propagation across PHIs.
---
 gcc/tree-ssa-forwprop.cc | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/gcc/tree-ssa-forwprop.cc b/gcc/tree-ssa-forwprop.cc
index 4b693ef095c..7c7942600ef 100644
--- a/gcc/tree-ssa-forwprop.cc
+++ b/gcc/tree-ssa-forwprop.cc
@@ -3384,7 +3384,12 @@ pass_forwprop::execute (function *fun)
          FOR_EACH_PHI_ARG (use_p, phi, it, SSA_OP_USE)
            {
              tree use = USE_FROM_PTR (use_p);
-             if (! first)
+             if (use == res)
+               /* The PHI result can also appear on a backedge, if so
+                  we can ignore this case for the purpose of determining
+                  the singular value.  */
+               ;
+             else if (! first)
                first = use;
              else if (! operand_equal_p (first, use, 0))
                {
-- 
2.35.3

Reply via email to