The problem here is that we're exporting a range for an SSA range that
happens on the other side of a __builtin_unreachable, but the SSA does
not post-dominate the definition point. This is causing ivcanon to
unroll things incorrectly.
This was a snafu when converting the code from evrp.
PR tree-optimization/107293
gcc/ChangeLog:
* tree-ssa-dom.cc
(dom_opt_dom_walker::set_global_ranges_from_unreachable_edges):
Check that condition post-dominates the definition point.
gcc/testsuite/ChangeLog:
* gcc.dg/tree-ssa/pr107293.c: New test.
--- /dev/null
+// { dg-do run }
+// { dg-options "-w -Os" }
+
+short a;
+int b[1];
+
+int c(int p) {
+ return (p < 0) ? 0 : 10 + ((p / 100 - 16) / 4);
+}
+
+void f(int n) {
+ while (1) {
+ int m = n;
+ while ((m ) )
+ m /= 2;
+ break;
+ }
+}
+
+void g() {
+ int h = a = 0;
+ for (; h + a <= 0; a++) {
+ if (b[c(a - 6)])
+ break;
+ f(a);
+ }
+}
+int main() {
+ g();
+ if (a != 1)
+ __builtin_abort ();
+}
tree name;
gori_compute &gori = m_ranger->gori ();
FOR_EACH_GORI_EXPORT_NAME (gori, pred_e->src, name)
- if (all_uses_feed_or_dominated_by_stmt (name, stmt))
+ if (all_uses_feed_or_dominated_by_stmt (name, stmt)
+ // The condition must post-dominate the definition point.
+ && (SSA_NAME_IS_DEFAULT_DEF (name)
+ || (gimple_bb (SSA_NAME_DEF_STMT (name))
+ == pred_e->src)))
{
Value_Range r (TREE_TYPE (name));