[llvm] update_test_checks: improve IR value name stability (PR #110940)

Nicolai Hähnle via llvm-commits llvm-commits at lists.llvm.org
Fri Oct 4 03:17:10 PDT 2024


================
@@ -1554,39 +1575,62 @@ def diffify_line(line, mapper):
                     else:
                         break
 
-                if rhs_value.name in local_commits:
+                if rhs_value.name in new_color.mapping:
                     # Same, but for a possible commit happening on the same line
-                    if local_commits[rhs_value.name] == lhs_value.name:
+                    if new_color.color[rhs_value.name] == lhs_value.name:
                         continue
                     else:
                         break
 
-                if lhs_value.name in committed_names:
-                    # We can't map this value because the name we would map it to has already been
-                    # committed for something else. Give up on this line.
+                if lhs_value.name in committed_names or lhs_value.name in new_color.committed:
+                    # We can't map this value because the name we would map it
+                    # to has already been committed for something else. Give up
+                    # on this line.
                     break
 
-                local_commits[rhs_value.name] = lhs_value.name
-            else:
-                # No reason not to add any commitments for this line
-                for rhs_var, lhs_var in local_commits.items():
-                    new_mapping[rhs_var] = lhs_var
-                    committed_names.add(lhs_var)
-                    committed_anything = True
-
-                    if (
-                        lhs_var != rhs_var
-                        and lhs_var in new_mapping
-                        and new_mapping[lhs_var] == lhs_var
-                    ):
-                        new_mapping[lhs_var] = "conflict_" + lhs_var
+                new_color.mapping[rhs_value.name] = lhs_value.name
+                new_color.committed.add(lhs_value.name)
 
-                matches.append((lhs_idx, rhs_idx))
+                color_idx = 0
+                while color_idx < len(compatible_colors):
+                    color = compatible_colors[color_idx]
+                    compatible = True
+                    if rhs_value.name in color.mapping:
+                        compatible = color.mapping[rhs_value.name] == lhs_value.name
+                    else:
+                        compatible = lhs_value.name not in color.committed
+                    if compatible:
+                        color_idx += 1
+                    else:
+                        del compatible_colors[color_idx]
+            else:
+                # At a minimum, this line is viable standalone
+                if compatible_colors:
+                    compatible_colors[0].mapping.update(new_color.mapping)
+                    compatible_colors[0].committed.update(new_color.committed)
+                    compatible_colors[0].matches.append((lhs_idx, rhs_idx))
+                else:
+                    colors.append(new_color)
+
+        if colors:
+            # Pick the largest color class. This gives us a large independent
+            # (non-conflicting) set of candidate matches. Assign all names
+            # required by the independent set and recurse.
+            max_color = max(colors, key=lambda color: len(color.matches))
+
+            for rhs_var, lhs_var in max_color.mapping.items():
+                new_mapping[rhs_var] = lhs_var
+                committed_names.add(lhs_var)
+
+                if (
+                    lhs_var != rhs_var
+                    and lhs_var in new_mapping
+                    and new_mapping[lhs_var] == lhs_var
+                ):
+                    new_mapping[lhs_var] = "conflict_" + lhs_var
 
-        matches.append((old_end, new_end))
+            matches = [(old_begin - 1, new_begin - 1)] + max_color.matches + [(old_end, new_end)]
----------------
nhaehnle wrote:

Yes, that's a bugfix.

https://github.com/llvm/llvm-project/pull/110940


More information about the llvm-commits mailing list