diff --git a/gcc/profile-count.h b/gcc/profile-count.h index b3d776475e2..6bbd476cb7f 100644 --- a/gcc/profile-count.h +++ b/gcc/profile-count.h @@ -910,7 +910,8 @@ public: profile_count ret; gcc_checking_assert (compatible_p (other)); - ret.m_val = m_val + other.m_val; + uint64_t ret_val = m_val + other.m_val; + ret.m_val = MIN (ret_val, max_count); ret.m_quality = MIN (m_quality, other.m_quality); return ret; } @@ -929,7 +930,8 @@ public: else { gcc_checking_assert (compatible_p (other)); - m_val += other.m_val; + uint64_t ret_val = m_val + other.m_val; + m_val = MIN (ret_val, max_count); m_quality = MIN (m_quality, other.m_quality); } return *this; @@ -957,7 +959,7 @@ public: else { gcc_checking_assert (compatible_p (other)); - m_val = m_val >= other.m_val ? m_val - other.m_val: 0; + m_val = m_val >= other.m_val ? m_val - other.m_val : 0; m_quality = MIN (m_quality, other.m_quality); } return *this; @@ -1127,7 +1129,9 @@ public: if (!initialized_p ()) return uninitialized (); profile_count ret; - ret.m_val = RDIV (m_val * prob, REG_BR_PROB_BASE); + uint64_t tmp; + safe_scale_64bit (m_val, prob, REG_BR_PROB_BASE, &tmp); + ret.m_val = tmp; ret.m_quality = MIN (m_quality, ADJUSTED); return ret; } diff --git a/gcc/testsuite/gcc.c-torture/compile/pr112303.c b/gcc/testsuite/gcc.c-torture/compile/pr112303.c new file mode 100644 index 00000000000..01937da53cf --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/compile/pr112303.c @@ -0,0 +1,25 @@ +/* PR tree-optimization/112303 */ + +int a, b, d, e, f, **g, h; +char c; + +int * +foo (void) +{ + for (int i = 0; i < 3; i++) + { + for (h = 0; h < 2; h++) + ; + if (!b) + break; + } + while (f) + while (e) + { + c = 0; + while (d) + while (a) + *g = foo (); + } + return 0; +}