* [PATCH] MATCH: Fix invalid signed boolean type usage
@ 2023-11-28 4:43 Andrew Pinski
2023-11-28 16:13 ` Richard Biener
0 siblings, 1 reply; 2+ messages in thread
From: Andrew Pinski @ 2023-11-28 4:43 UTC (permalink / raw)
To: gcc-patches
This fixes the incorrect assumption that was done in r14-3721-ge6bcf839894783,
that being able to doing the negative after the conversion would be a valid thing
but really it is not valid for boolean types.
OK? Bootstrapped and tested on x86_64-linux-gnu.
gcc/ChangeLog:
PR tree-optimization/112738
* match.pd (`(nop_convert)-(convert)a`): Reject
when the outer type is boolean.
Signed-off-by: Andrew Pinski <quic_apinski@quicinc.com>
---
gcc/match.pd | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/gcc/match.pd b/gcc/match.pd
index 95225e4ca5f..294e58ebf44 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -1033,12 +1033,16 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
/* (nop_outer_cast)-(inner_cast)var -> -(outer_cast)(var)
if var is smaller in precision.
This is always safe for both doing the negative in signed or unsigned
- as the value for undefined will not show up. */
+ as the value for undefined will not show up.
+ Note the outer cast cannot be a boolean type as the only valid values
+ are 0,-1/1 (depending on the signedness of the boolean) and the negative
+ is there to get the correct value. */
(simplify
(convert (negate:s@1 (convert:s @0)))
(if (INTEGRAL_TYPE_P (type)
&& tree_nop_conversion_p (type, TREE_TYPE (@1))
- && TYPE_PRECISION (type) > TYPE_PRECISION (TREE_TYPE (@0)))
+ && TYPE_PRECISION (type) > TYPE_PRECISION (TREE_TYPE (@0))
+ && TREE_CODE (type) != BOOLEAN_TYPE)
(negate (convert @0))))
(for op (negate abs)
--
2.39.3
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] MATCH: Fix invalid signed boolean type usage
2023-11-28 4:43 [PATCH] MATCH: Fix invalid signed boolean type usage Andrew Pinski
@ 2023-11-28 16:13 ` Richard Biener
0 siblings, 0 replies; 2+ messages in thread
From: Richard Biener @ 2023-11-28 16:13 UTC (permalink / raw)
To: Andrew Pinski; +Cc: gcc-patches
On Tue, Nov 28, 2023 at 5:44 AM Andrew Pinski <quic_apinski@quicinc.com> wrote:
>
> This fixes the incorrect assumption that was done in r14-3721-ge6bcf839894783,
> that being able to doing the negative after the conversion would be a valid thing
> but really it is not valid for boolean types.
>
> OK? Bootstrapped and tested on x86_64-linux-gnu.
OK
> gcc/ChangeLog:
>
> PR tree-optimization/112738
> * match.pd (`(nop_convert)-(convert)a`): Reject
> when the outer type is boolean.
>
> Signed-off-by: Andrew Pinski <quic_apinski@quicinc.com>
> ---
> gcc/match.pd | 8 ++++++--
> 1 file changed, 6 insertions(+), 2 deletions(-)
>
> diff --git a/gcc/match.pd b/gcc/match.pd
> index 95225e4ca5f..294e58ebf44 100644
> --- a/gcc/match.pd
> +++ b/gcc/match.pd
> @@ -1033,12 +1033,16 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
> /* (nop_outer_cast)-(inner_cast)var -> -(outer_cast)(var)
> if var is smaller in precision.
> This is always safe for both doing the negative in signed or unsigned
> - as the value for undefined will not show up. */
> + as the value for undefined will not show up.
> + Note the outer cast cannot be a boolean type as the only valid values
> + are 0,-1/1 (depending on the signedness of the boolean) and the negative
> + is there to get the correct value. */
> (simplify
> (convert (negate:s@1 (convert:s @0)))
> (if (INTEGRAL_TYPE_P (type)
> && tree_nop_conversion_p (type, TREE_TYPE (@1))
> - && TYPE_PRECISION (type) > TYPE_PRECISION (TREE_TYPE (@0)))
> + && TYPE_PRECISION (type) > TYPE_PRECISION (TREE_TYPE (@0))
> + && TREE_CODE (type) != BOOLEAN_TYPE)
> (negate (convert @0))))
>
> (for op (negate abs)
> --
> 2.39.3
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2023-11-28 16:13 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-11-28 4:43 [PATCH] MATCH: Fix invalid signed boolean type usage Andrew Pinski
2023-11-28 16:13 ` 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).