[gcc r15-6945] tree-optimization/115494 - PRE PHI translation and ranges
Richard Biener
rguenth@gcc.gnu.org
Thu Jan 16 08:43:21 GMT 2025
https://gcc.gnu.org/g:ea1deefe54ea1c5182bfa179abf36469c9ec6974
commit r15-6945-gea1deefe54ea1c5182bfa179abf36469c9ec6974
Author: Richard Biener <rguenther@suse.de>
Date: Wed Jan 15 14:31:57 2025 +0100
tree-optimization/115494 - PRE PHI translation and ranges
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>
Diff:
---
gcc/testsuite/gcc.dg/torture/pr115494.c | 24 ++++++++++++++++++++++++
gcc/tree-ssa-pre.cc | 4 ++--
2 files changed, 26 insertions(+), 2 deletions(-)
diff --git a/gcc/testsuite/gcc.dg/torture/pr115494.c b/gcc/testsuite/gcc.dg/torture/pr115494.c
new file mode 100644
index 000000000000..a8c614433a67
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/pr115494.c
@@ -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();
+}
+
diff --git a/gcc/tree-ssa-pre.cc b/gcc/tree-ssa-pre.cc
index 32bcd9b1b7af..735893bb191e 100644
--- a/gcc/tree-ssa-pre.cc
+++ b/gcc/tree-ssa-pre.cc
@@ -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];
More information about the Gcc-cvs
mailing list