]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
tree-optimization/115494 - PRE PHI translation and ranges
authorRichard Biener <rguenther@suse.de>
Wed, 15 Jan 2025 13:31:57 +0000 (14:31 +0100)
committerRichard Biener <rguenth@gcc.gnu.org>
Mon, 24 Feb 2025 08:05:24 +0000 (09:05 +0100)
When we PHI translate dependent expressions we keep SSA defs in
place of the translated expression in case the expression itself
did not change even though it's context did and thus the validity
of ranges associated with it.  That eventually leads to simplification
errors given we violate the precondition that used SSA defs fed to
vn_valueize are valid to use (including their associated ranges).
The following makes sure to replace those with new representatives
always, not only when the dependent expression translation changed it.

The fix was originally discovered by Michael Morin.

PR tree-optimization/115494
* tree-ssa-pre.cc (phi_translate_1): Always generate a
representative for translated dependent expressions.

* gcc.dg/torture/pr115494.c: New testcase.

Co-Authored-By: Mikael Morin <mikael@gcc.gnu.org>
(cherry picked from commit ea1deefe54ea1c5182bfa179abf36469c9ec6974)

gcc/testsuite/gcc.dg/torture/pr115494.c [new file with mode: 0644]
gcc/tree-ssa-pre.cc

diff --git a/gcc/testsuite/gcc.dg/torture/pr115494.c b/gcc/testsuite/gcc.dg/torture/pr115494.c
new file mode 100644 (file)
index 0000000..a8c6144
--- /dev/null
@@ -0,0 +1,24 @@
+/* { dg-do run } */
+
+unsigned char a;
+int b = 1, c, d;
+int __attribute__((noipa))
+f()
+{
+  char e;
+  c = b - c;
+  a = ~(c || a);
+  e = -(b ^ a);
+  d = e && b;
+  a = ~(b & a);
+  if (a < 2)
+    return 1;
+  return 0;
+}
+
+int main()
+{
+  if (f())
+    __builtin_abort();
+}
+
index 5cf1968bc265c946dc36d4ffc71686e2b38c6ccd..a4c93e4f26f2b89b0c2ae3122dd3a6800264786c 100644 (file)
@@ -1430,7 +1430,7 @@ 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.  */
@@ -1553,7 +1553,7 @@ phi_translate_1 (bitmap_set_t dest,
                op_val_id = VN_INFO (op[n])->value_id;
                leader = find_leader_in_sets (op_val_id, set1, set2);
                opresult = phi_translate (dest, leader, set1, set2, e);
-               if (opresult && opresult != leader)
+               if (opresult)
                  {
                    tree name = get_representative_for (opresult);
                    changed |= name != op[n];