public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/112738] New: forwprop4 introduces invalid wide signed Boolean values
@ 2023-11-27 23:21 kristerw at gcc dot gnu.org
2023-11-27 23:26 ` [Bug tree-optimization/112738] [14 Regression] " pinskia at gcc dot gnu.org
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: kristerw at gcc dot gnu.org @ 2023-11-27 23:21 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112738
Bug ID: 112738
Summary: forwprop4 introduces invalid wide signed Boolean
values
Product: gcc
Version: 14.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: kristerw at gcc dot gnu.org
Target Milestone: ---
The forwprop4 pass introduces an invalid wide Boolean when compiling the
following function with -O3 for X86_64:
int *a, b, c, d;
void
foo (void)
{
for (; d <= 0; d++)
b &= ((a || d) ^ c) == 1;
}
What is happening is that forwprop4 changes the IR
_38 = (signed int) _16;
_59 = -_38;
_65 = (<signed-boolean:32>) _59;
to the incorrect
_55 = (<signed-boolean:32>) _16;
_65 = -_55;
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug tree-optimization/112738] [14 Regression] forwprop4 introduces invalid wide signed Boolean values
2023-11-27 23:21 [Bug tree-optimization/112738] New: forwprop4 introduces invalid wide signed Boolean values kristerw at gcc dot gnu.org
@ 2023-11-27 23:26 ` pinskia at gcc dot gnu.org
2023-11-27 23:34 ` pinskia at gcc dot gnu.org
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-11-27 23:26 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112738
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |ASSIGNED
Summary|forwprop4 introduces |[14 Regression] forwprop4
|invalid wide signed Boolean |introduces invalid wide
|values |signed Boolean values
Assignee|unassigned at gcc dot gnu.org |pinskia at gcc dot gnu.org
Target Milestone|--- |14.0
Last reconfirmed| |2023-11-27
Keywords| |wrong-code
Ever confirmed|0 |1
--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Mine.
```
/* (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. */
(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)))
(negate (convert @0))))
```
This needs a check for !BOOLEAN_TYPE here I think. boolean is the special case
...
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug tree-optimization/112738] [14 Regression] forwprop4 introduces invalid wide signed Boolean values
2023-11-27 23:21 [Bug tree-optimization/112738] New: forwprop4 introduces invalid wide signed Boolean values kristerw at gcc dot gnu.org
2023-11-27 23:26 ` [Bug tree-optimization/112738] [14 Regression] " pinskia at gcc dot gnu.org
@ 2023-11-27 23:34 ` pinskia at gcc dot gnu.org
2023-11-28 17:52 ` cvs-commit at gcc dot gnu.org
2023-11-28 17:52 ` pinskia at gcc dot gnu.org
3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-11-27 23:34 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112738
--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
This is what I will be testing:
```
/* (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.
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))
&& TREE_CODE (type) != BOOLEAN_TYPE)
(negate (convert @0))))
```
It even records on why boolean check is needed.
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug tree-optimization/112738] [14 Regression] forwprop4 introduces invalid wide signed Boolean values
2023-11-27 23:21 [Bug tree-optimization/112738] New: forwprop4 introduces invalid wide signed Boolean values kristerw at gcc dot gnu.org
2023-11-27 23:26 ` [Bug tree-optimization/112738] [14 Regression] " pinskia at gcc dot gnu.org
2023-11-27 23:34 ` pinskia at gcc dot gnu.org
@ 2023-11-28 17:52 ` cvs-commit at gcc dot gnu.org
2023-11-28 17:52 ` pinskia at gcc dot gnu.org
3 siblings, 0 replies; 5+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-11-28 17:52 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112738
--- Comment #3 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The trunk branch has been updated by Andrew Pinski <pinskia@gcc.gnu.org>:
https://gcc.gnu.org/g:68ffaf839883253e0f288862ff20b8005c92df4e
commit r14-5938-g68ffaf839883253e0f288862ff20b8005c92df4e
Author: Andrew Pinski <quic_apinski@quicinc.com>
Date: Mon Nov 27 16:41:25 2023 -0800
MATCH: Fix invalid signed boolean type usage
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.
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>
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug tree-optimization/112738] [14 Regression] forwprop4 introduces invalid wide signed Boolean values
2023-11-27 23:21 [Bug tree-optimization/112738] New: forwprop4 introduces invalid wide signed Boolean values kristerw at gcc dot gnu.org
` (2 preceding siblings ...)
2023-11-28 17:52 ` cvs-commit at gcc dot gnu.org
@ 2023-11-28 17:52 ` pinskia at gcc dot gnu.org
3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-11-28 17:52 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112738
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|ASSIGNED |RESOLVED
Resolution|--- |FIXED
--- Comment #4 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Fixed.
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2023-11-28 17:52 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-11-27 23:21 [Bug tree-optimization/112738] New: forwprop4 introduces invalid wide signed Boolean values kristerw at gcc dot gnu.org
2023-11-27 23:26 ` [Bug tree-optimization/112738] [14 Regression] " pinskia at gcc dot gnu.org
2023-11-27 23:34 ` pinskia at gcc dot gnu.org
2023-11-28 17:52 ` cvs-commit at gcc dot gnu.org
2023-11-28 17:52 ` pinskia at gcc dot gnu.org
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).