* [PATCH] check undefine_p for one more vr
@ 2023-09-21 2:31 Jiufu Guo
2023-09-21 5:09 ` Richard Biener
0 siblings, 1 reply; 3+ messages in thread
From: Jiufu Guo @ 2023-09-21 2:31 UTC (permalink / raw)
To: gcc-patches
Cc: rguenther, jeffreyalaw, richard.sandiford, segher, dje.gcc,
linkw, bergner, guojiufu, amacleod, aldyh
Hi,
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)".
Bootstrap & regtest pass on ppc64{,le}.
Is this ok for trunk?
BR,
Jeff (Jiufu Guo)
PR tree-optimization/111355
gcc/ChangeLog:
* match.pd ((X + C) / N): Update pattern.
gcc/testsuite/ChangeLog:
* gcc.dg/pr111355.c: New test.
---
gcc/match.pd | 2 +-
gcc/testsuite/gcc.dg/pr111355.c | 8 ++++++++
2 files changed, 9 insertions(+), 1 deletion(-)
create mode 100644 gcc/testsuite/gcc.dg/pr111355.c
diff --git a/gcc/match.pd b/gcc/match.pd
index 39c9c81966a..5fdfba14d47 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -1033,7 +1033,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 00000000000..8bacbc69d31
--- /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;
+}
--
2.25.1
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] check undefine_p for one more vr
2023-09-21 2:31 [PATCH] check undefine_p for one more vr Jiufu Guo
@ 2023-09-21 5:09 ` Richard Biener
2023-09-21 5:23 ` Jiufu Guo
0 siblings, 1 reply; 3+ messages in thread
From: Richard Biener @ 2023-09-21 5:09 UTC (permalink / raw)
To: Jiufu Guo
Cc: gcc-patches, jeffreyalaw, richard.sandiford, segher, dje.gcc,
linkw, bergner, amacleod, aldyh
> Am 21.09.2023 um 05:10 schrieb Jiufu Guo <guojiufu@linux.ibm.com>:
>
> Hi,
>
> 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)".
>
> Bootstrap & regtest pass on ppc64{,le}.
> Is this ok for trunk?
Ok
Richard
> BR,
> Jeff (Jiufu Guo)
>
>
> PR tree-optimization/111355
>
> gcc/ChangeLog:
>
> * match.pd ((X + C) / N): Update pattern.
>
> gcc/testsuite/ChangeLog:
>
> * gcc.dg/pr111355.c: New test.
>
> ---
> gcc/match.pd | 2 +-
> gcc/testsuite/gcc.dg/pr111355.c | 8 ++++++++
> 2 files changed, 9 insertions(+), 1 deletion(-)
> create mode 100644 gcc/testsuite/gcc.dg/pr111355.c
>
> diff --git a/gcc/match.pd b/gcc/match.pd
> index 39c9c81966a..5fdfba14d47 100644
> --- a/gcc/match.pd
> +++ b/gcc/match.pd
> @@ -1033,7 +1033,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 00000000000..8bacbc69d31
> --- /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;
> +}
> --
> 2.25.1
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] check undefine_p for one more vr
2023-09-21 5:09 ` Richard Biener
@ 2023-09-21 5:23 ` Jiufu Guo
0 siblings, 0 replies; 3+ messages in thread
From: Jiufu Guo @ 2023-09-21 5:23 UTC (permalink / raw)
To: Richard Biener
Cc: gcc-patches, jeffreyalaw, richard.sandiford, segher, dje.gcc,
linkw, bergner, amacleod, aldyh
Hi,
Richard Biener <rguenther@suse.de> writes:
>> Am 21.09.2023 um 05:10 schrieb Jiufu Guo <guojiufu@linux.ibm.com>:
>>
>> Hi,
>>
>> 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)".
>>
>> Bootstrap & regtest pass on ppc64{,le}.
>> Is this ok for trunk?
>
> Ok
Thanks! Committed via r14-4192.
BR,
Jeff (Jiufu Guo)
>
> Richard
>
>> BR,
>> Jeff (Jiufu Guo)
>>
>>
>> PR tree-optimization/111355
>>
>> gcc/ChangeLog:
>>
>> * match.pd ((X + C) / N): Update pattern.
>>
>> gcc/testsuite/ChangeLog:
>>
>> * gcc.dg/pr111355.c: New test.
>>
>> ---
>> gcc/match.pd | 2 +-
>> gcc/testsuite/gcc.dg/pr111355.c | 8 ++++++++
>> 2 files changed, 9 insertions(+), 1 deletion(-)
>> create mode 100644 gcc/testsuite/gcc.dg/pr111355.c
>>
>> diff --git a/gcc/match.pd b/gcc/match.pd
>> index 39c9c81966a..5fdfba14d47 100644
>> --- a/gcc/match.pd
>> +++ b/gcc/match.pd
>> @@ -1033,7 +1033,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 00000000000..8bacbc69d31
>> --- /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;
>> +}
>> --
>> 2.25.1
>>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2023-09-21 5:23 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-09-21 2:31 [PATCH] check undefine_p for one more vr Jiufu Guo
2023-09-21 5:09 ` Richard Biener
2023-09-21 5:23 ` Jiufu Guo
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).