From: Andrew MacLeod Date: Mon, 5 May 2025 16:17:13 +0000 (-0400) Subject: Allow IPA_CP to handle UNDEFINED as VARYING. X-Git-Tag: releases/gcc-14.3.0~54 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=93b85bdf830477fec8db1d8afcaca13530776161;p=thirdparty%2Fgcc.git Allow IPA_CP to handle UNDEFINED as VARYING. 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. --- diff --git a/gcc/ipa-cp.cc b/gcc/ipa-cp.cc index 6b772fae88f..222ba01c576 100644 --- a/gcc/ipa-cp.cc +++ b/gcc/ipa-cp.cc @@ -6355,6 +6355,11 @@ ipcp_store_vr_results (void) TYPE_PRECISION (type), TYPE_SIGN (type))); r.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); } @@ -6377,6 +6382,11 @@ ipcp_store_vr_results (void) TYPE_PRECISION (type), TYPE_SIGN (type))); r.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 index 00000000000..6bb34b0e168 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr120048.c @@ -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); }