diff options
author | Jiufu Guo <guojiufu@linux.ibm.com> | 2023-09-20 11:11:58 +0800 |
---|---|---|
committer | guojiufu <guojiufu@linux.ibm.com> | 2023-09-21 13:18:22 +0800 |
commit | 4d80863d7f93c0a839d1fe5dc59be83153e89110 (patch) | |
tree | 0de97edbf7789038540438060373cadbe0fee2e8 | |
parent | d946fc1c71bdc21e3bb23721cc4d770e48bed2e2 (diff) | |
download | gcc-4d80863d7f93c0a839d1fe5dc59be83153e89110.zip gcc-4d80863d7f93c0a839d1fe5dc59be83153e89110.tar.gz gcc-4d80863d7f93c0a839d1fe5dc59be83153e89110.tar.bz2 |
check undefine_p for one more vr
The root cause of PR111355 and PR111482 is missing to check if vr0
is undefined_p before call vr0.lower_bound.
In the pattern "(X + C) / N",
(if (INTEGRAL_TYPE_P (type)
&& get_range_query (cfun)->range_of_expr (vr0, @0))
(if (...)
(plus (op @0 @2) { wide_int_to_tree (type, plus_op1 (c)); })
(if (TYPE_UNSIGNED (type) && c.sign_mask () < 0 ...
&& wi::geu_p (vr0.lower_bound (), -c))
In "(if (...)", there is code to prevent vr0's undefined_p,
But in the "else" part, vr0's undefined_p is not checked before
"wi::geu_p (vr0.lower_bound (), -c)".
PR tree-optimization/111355
gcc/ChangeLog:
* match.pd ((X + C) / N): Update pattern.
gcc/testsuite/ChangeLog:
* gcc.dg/pr111355.c: New test.
-rw-r--r-- | gcc/match.pd | 2 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/pr111355.c | 8 |
2 files changed, 9 insertions, 1 deletions
diff --git a/gcc/match.pd b/gcc/match.pd index ce24957..0aa815f 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -1009,7 +1009,7 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) || (vr0.nonnegative_p () && vr3.nonnegative_p ()) || (vr0.nonpositive_p () && vr3.nonpositive_p ()))) (plus (op @0 @2) { wide_int_to_tree (type, plus_op1 (c)); }) - (if (TYPE_UNSIGNED (type) && c.sign_mask () < 0 + (if (!vr0.undefined_p () && TYPE_UNSIGNED (type) && c.sign_mask () < 0 && exact_mod (-c) /* unsigned "X-(-C)" doesn't underflow. */ && wi::geu_p (vr0.lower_bound (), -c)) diff --git a/gcc/testsuite/gcc.dg/pr111355.c b/gcc/testsuite/gcc.dg/pr111355.c new file mode 100644 index 0000000..7b522d9 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr111355.c @@ -0,0 +1,8 @@ +/* { dg-do compile } */ +/* { dg-options "-O3 -Wno-div-by-zero" } */ + +/* Make sure no ICE. */ +int main() { + unsigned b; + return b ? 1 << --b / 0 : 0; +} |