https://gcc.gnu.org/g:6c41f4ab1f64bcd0dad8abc68073e3b6118c12b0

commit 6c41f4ab1f64bcd0dad8abc68073e3b6118c12b0
Author: Mikael Morin <mik...@gcc.gnu.org>
Date:   Mon Dec 2 10:37:01 2024 +0100

    tree-optimization: Always select a representative available in the block 
[PR115494]
    
    Force the creation of a new representative if phi-translation returns a
    leader whose definition doesn't dominate the source block.  This avoids
    using the flow-sensitive information (value range, known bits) of the leader
    during simplification, in a block that is out of the scope where that
    information is valid.
    
            PR tree-optimization/115494
    
    gcc/ChangeLog:
    
            * tree-ssa-pre.cc (phi_translate_1): Force the selection of a
            representative available in the block in the case where the leader
            is left untouched by phi-translation.

Diff:
---
 gcc/tree-ssa-pre.cc | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/gcc/tree-ssa-pre.cc b/gcc/tree-ssa-pre.cc
index c696111690f1..fe55d1126f92 100644
--- a/gcc/tree-ssa-pre.cc
+++ b/gcc/tree-ssa-pre.cc
@@ -1430,12 +1430,16 @@ phi_translate_1 (bitmap_set_t dest,
                unsigned int op_val_id = VN_INFO (newnary->op[i])->value_id;
                leader = find_leader_in_sets (op_val_id, set1, set2);
                result = phi_translate (dest, leader, set1, set2, e);
-               if (result && result != leader)
+               if (result)
                  /* If op has a leader in the sets we translate make
                     sure to use the value of the translated expression.
-                    We might need a new representative for that.  */
+                    We might need a new representative for that.  We have to
+                    restrict to a representative whose definition dominates
+                    PRED, as its flow-sensitive information such as value range
+                    or known bits may be used by the simplification attempt
+                    further down.  */
                  newnary->op[i] = get_representative_for (result, pred);
-               else if (!result)
+               else
                  return NULL;
 
                changed |= newnary->op[i] != nary->op[i];

Reply via email to