* [PATCH] tree-vect-patterns: Fix up ICE in upper_bound [PR109115]
@ 2023-03-14 8:01 Jakub Jelinek
2023-03-14 8:05 ` Richard Biener
0 siblings, 1 reply; 2+ messages in thread
From: Jakub Jelinek @ 2023-03-14 8:01 UTC (permalink / raw)
To: Richard Biener, Andrew MacLeod, Aldy Hernandez; +Cc: gcc-patches
Hi!
As mentioned in the PR, range_of_expr returns false if the type
of the expression isn't suitable for corresponding range type,
but doesn't if the range is undefined for other reasons. Still,
lower/upper_bound is defined only for ranges which actually have
at least one pair of subranges, VR_UNDEFINED range doesn't have it.
Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux,
ok for trunk?
2023-03-14 Jakub Jelinek <jakub@redhat.com>
PR tree-optimization/109115
* tree-vect-patterns.cc (vect_recog_divmod_pattern): Don't use
r.upper_bound () on r.undefined_p () range.
* gcc.dg/pr109115.c: New test.
--- gcc/tree-vect-patterns.cc.jj 2023-03-12 22:36:06.388177607 +0100
+++ gcc/tree-vect-patterns.cc 2023-03-13 22:49:18.278476093 +0100
@@ -3973,7 +3973,7 @@ vect_recog_divmod_pattern (vec_info *vin
/* Check that no overflow will occur. If we don't have range
information we can't perform the optimization. */
- if (ranger.range_of_expr (r, oprnd0, stmt))
+ if (ranger.range_of_expr (r, oprnd0, stmt) && !r.undefined_p ())
{
wide_int max = r.upper_bound ();
wide_int one = wi::shwi (1, prec);
--- gcc/testsuite/gcc.dg/pr109115.c.jj 2023-03-13 22:56:27.269428198 +0100
+++ gcc/testsuite/gcc.dg/pr109115.c 2023-03-13 22:56:04.174753778 +0100
@@ -0,0 +1,20 @@
+/* PR tree-optimization/109115 */
+/* { dg-do compile } */
+/* { dg-options "-O2" } */
+
+int a, b;
+
+int
+main ()
+{
+ unsigned short c = a, e = -1;
+ if (b)
+ {
+ unsigned d = (a ^ 1U) / a & c;
+ int f = (~d >> ~a) / e;
+ if (a)
+ f = a;
+ a = f;
+ }
+ return 0;
+}
Jakub
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] tree-vect-patterns: Fix up ICE in upper_bound [PR109115]
2023-03-14 8:01 [PATCH] tree-vect-patterns: Fix up ICE in upper_bound [PR109115] Jakub Jelinek
@ 2023-03-14 8:05 ` Richard Biener
0 siblings, 0 replies; 2+ messages in thread
From: Richard Biener @ 2023-03-14 8:05 UTC (permalink / raw)
To: Jakub Jelinek; +Cc: Andrew MacLeod, Aldy Hernandez, gcc-patches
On Tue, 14 Mar 2023, Jakub Jelinek wrote:
> Hi!
>
> As mentioned in the PR, range_of_expr returns false if the type
> of the expression isn't suitable for corresponding range type,
> but doesn't if the range is undefined for other reasons. Still,
> lower/upper_bound is defined only for ranges which actually have
> at least one pair of subranges, VR_UNDEFINED range doesn't have it.
>
> Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux,
> ok for trunk?
OK.
> 2023-03-14 Jakub Jelinek <jakub@redhat.com>
>
> PR tree-optimization/109115
> * tree-vect-patterns.cc (vect_recog_divmod_pattern): Don't use
> r.upper_bound () on r.undefined_p () range.
>
> * gcc.dg/pr109115.c: New test.
>
> --- gcc/tree-vect-patterns.cc.jj 2023-03-12 22:36:06.388177607 +0100
> +++ gcc/tree-vect-patterns.cc 2023-03-13 22:49:18.278476093 +0100
> @@ -3973,7 +3973,7 @@ vect_recog_divmod_pattern (vec_info *vin
> /* Check that no overflow will occur. If we don't have range
> information we can't perform the optimization. */
>
> - if (ranger.range_of_expr (r, oprnd0, stmt))
> + if (ranger.range_of_expr (r, oprnd0, stmt) && !r.undefined_p ())
> {
> wide_int max = r.upper_bound ();
> wide_int one = wi::shwi (1, prec);
> --- gcc/testsuite/gcc.dg/pr109115.c.jj 2023-03-13 22:56:27.269428198 +0100
> +++ gcc/testsuite/gcc.dg/pr109115.c 2023-03-13 22:56:04.174753778 +0100
> @@ -0,0 +1,20 @@
> +/* PR tree-optimization/109115 */
> +/* { dg-do compile } */
> +/* { dg-options "-O2" } */
> +
> +int a, b;
> +
> +int
> +main ()
> +{
> + unsigned short c = a, e = -1;
> + if (b)
> + {
> + unsigned d = (a ^ 1U) / a & c;
> + int f = (~d >> ~a) / e;
> + if (a)
> + f = a;
> + a = f;
> + }
> + return 0;
> +}
>
> Jakub
>
>
--
Richard Biener <rguenther@suse.de>
SUSE Software Solutions Germany GmbH, Frankenstrasse 146, 90461 Nuernberg,
Germany; GF: Ivo Totev, Andrew Myers, Andrew McDonald, Boudien Moerman;
HRB 36809 (AG Nuernberg)
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2023-03-14 8:05 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-14 8:01 [PATCH] tree-vect-patterns: Fix up ICE in upper_bound [PR109115] Jakub Jelinek
2023-03-14 8:05 ` Richard Biener
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).