]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Allow IPA_CP to handle UNDEFINED as VARYING.
authorAndrew MacLeod <amacleod@redhat.com>
Fri, 2 May 2025 19:48:08 +0000 (15:48 -0400)
committerAndrew MacLeod <amacleod@redhat.com>
Mon, 5 May 2025 15:13:18 +0000 (11:13 -0400)
When applying a bitmask to reflect ranges, it is sometimes deferred and
this can result in an UNDEFINED result.  IPA is not expecting this, and
add a check for it, and convert to VARYING if encountered.

PR tree-optimization/120048
gcc/
* ipa-cp.cc (ipcp_store_vr_results): Check for UNDEFINED.

gcc/testsuite/
* gcc.dg/pr120048.c: New.

gcc/ipa-cp.cc
gcc/testsuite/gcc.dg/pr120048.c [new file with mode: 0644]

index f7e5aa9bfd5cdefd789d82c16e79c67985110419..b41148c74de36527a4f993b0a2b6a1065fc65ec7 100644 (file)
@@ -6362,6 +6362,11 @@ ipcp_store_vr_results (void)
                                                     TYPE_PRECISION (type),
                                                     TYPE_SIGN (type)));
                  tmp.update_bitmask (bm);
+                 // Reflecting the bitmask on the ranges can sometime
+                 // produce an UNDEFINED value if the the bitmask update
+                 // was previously deferred.  See PR 120048.
+                 if (tmp.undefined_p ())
+                   tmp.set_varying (type);
                  ipa_vr vr (tmp);
                  ts->m_vr->quick_push (vr);
                }
@@ -6383,6 +6388,11 @@ ipcp_store_vr_results (void)
                                                 TYPE_PRECISION (type),
                                                 TYPE_SIGN (type)));
              tmp.update_bitmask (bm);
+             // Reflecting the bitmask on the ranges can sometime
+             // produce an UNDEFINED value if the the bitmask update
+             // was previously deferred.  See PR 120048.
+             if (tmp.undefined_p ())
+               tmp.set_varying (type);
              ipa_vr vr (tmp);
              ts->m_vr->quick_push (vr);
            }
diff --git a/gcc/testsuite/gcc.dg/pr120048.c b/gcc/testsuite/gcc.dg/pr120048.c
new file mode 100644 (file)
index 0000000..6bb34b0
--- /dev/null
@@ -0,0 +1,12 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fno-tree-vrp -fno-tree-fre" } */
+
+int a, b, c;
+static int d(short e) { return e || (a && e) ? 0 : a; }
+static void f(int e) {
+  if (!e) {
+    d(0);
+    b = d(e);
+  }
+}
+int main() { f(c | 1); }