diff options
author | Andrew MacLeod <amacleod@redhat.com> | 2025-05-02 15:48:08 -0400 |
---|---|---|
committer | Andrew MacLeod <amacleod@redhat.com> | 2025-05-06 10:45:22 -0400 |
commit | b6f68c04f440f981b281c5ad4c335761bc7d2882 (patch) | |
tree | c39e6ed174f5e35ee837f432c8dad2a074b01ce2 /gcc | |
parent | 0d46cee2fe38b9a1aa576c8031ed22d298d88954 (diff) | |
download | gcc-b6f68c04f440f981b281c5ad4c335761bc7d2882.zip gcc-b6f68c04f440f981b281c5ad4c335761bc7d2882.tar.gz gcc-b6f68c04f440f981b281c5ad4c335761bc7d2882.tar.bz2 |
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.
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/ipa-cp.cc | 10 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/pr120048.c | 12 |
2 files changed, 22 insertions, 0 deletions
diff --git a/gcc/ipa-cp.cc b/gcc/ipa-cp.cc index 806c2bd..a8ff3c8 100644 --- a/gcc/ipa-cp.cc +++ b/gcc/ipa-cp.cc @@ -6398,6 +6398,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); } @@ -6419,6 +6424,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 index 0000000..6bb34b0 --- /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); } |