public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/112949] New: evrp produces incorrect range for __builtin_clz
@ 2023-12-10 22:48 kristerw at gcc dot gnu.org
2023-12-10 22:50 ` [Bug tree-optimization/112949] " pinskia at gcc dot gnu.org
` (6 more replies)
0 siblings, 7 replies; 8+ messages in thread
From: kristerw at gcc dot gnu.org @ 2023-12-10 22:48 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112949
Bug ID: 112949
Summary: evrp produces incorrect range for __builtin_clz
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 evrp pass generates incorrect ranges for __builtin_clz when it is called
within a function named __builtin_clz. While calling it in this manner seems
questionable, two relatively recent tests in the testsuite (gcc.dg/pr100521.c
and gcc.dg/pr100790.c) suggest that gcc should handle this.
The test case gcc.dg/pr100790.c is as follows:
__builtin_clz(int x) { x ? __builtin_clz(x) : 32; }
Compiling this for x86_64 using -O3 -fpermissive results in the evrp IR:
Global Exported: iftmp.0_3 = [irange] int [1, 31]
__attribute__((nothrow, leaf, const))
int __builtin_clz (int x)
{
int iftmp.0_3;
<bb 2> :
if (x_1(D) != 0)
goto <bb 3>; [INV]
else
goto <bb 4>; [INV]
<bb 3> :
iftmp.0_3 = __builtin_clz (x_1(D));
<bb 4> :
return;
}
The range for iftmp.0_3 (which is an internal call to CFN_BUILT_IN_CLZ) should
be [0, 31], not [1, 31].
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug tree-optimization/112949] evrp produces incorrect range for __builtin_clz
2023-12-10 22:48 [Bug tree-optimization/112949] New: evrp produces incorrect range for __builtin_clz kristerw at gcc dot gnu.org
@ 2023-12-10 22:50 ` pinskia at gcc dot gnu.org
2023-12-10 22:53 ` pinskia at gcc dot gnu.org
` (5 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-12-10 22:50 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112949
--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
I think the testcase is broken rather than anything else.
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug tree-optimization/112949] evrp produces incorrect range for __builtin_clz
2023-12-10 22:48 [Bug tree-optimization/112949] New: evrp produces incorrect range for __builtin_clz kristerw at gcc dot gnu.org
2023-12-10 22:50 ` [Bug tree-optimization/112949] " pinskia at gcc dot gnu.org
@ 2023-12-10 22:53 ` pinskia at gcc dot gnu.org
2023-12-10 23:03 ` kristerw at gcc dot gnu.org
` (4 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-12-10 22:53 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112949
--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
defining __builtin_clz makes this code undefined. Especially when it comes to
calling itself.
That is the ranges here are ok and correct but rather the usage is undefined.
gcc.dg/pr100521.c is just testing to make sure we don't ICE rather than
anything else.
Likewise for gcc.dg/pr100790.c .
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug tree-optimization/112949] evrp produces incorrect range for __builtin_clz
2023-12-10 22:48 [Bug tree-optimization/112949] New: evrp produces incorrect range for __builtin_clz kristerw at gcc dot gnu.org
2023-12-10 22:50 ` [Bug tree-optimization/112949] " pinskia at gcc dot gnu.org
2023-12-10 22:53 ` pinskia at gcc dot gnu.org
@ 2023-12-10 23:03 ` kristerw at gcc dot gnu.org
2023-12-10 23:09 ` pinskia at gcc dot gnu.org
` (3 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: kristerw at gcc dot gnu.org @ 2023-12-10 23:03 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112949
--- Comment #3 from Krister Walfridsson <kristerw at gcc dot gnu.org> ---
The C program is obviously UB. But the optimization is done on GIMPLE, and it
is not obvious to me that the GIMPLE code is UB -- we have a function called
__builtin_clz that calls an internal function, so they are different...
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug tree-optimization/112949] evrp produces incorrect range for __builtin_clz
2023-12-10 22:48 [Bug tree-optimization/112949] New: evrp produces incorrect range for __builtin_clz kristerw at gcc dot gnu.org
` (2 preceding siblings ...)
2023-12-10 23:03 ` kristerw at gcc dot gnu.org
@ 2023-12-10 23:09 ` pinskia at gcc dot gnu.org
2023-12-10 23:11 ` pinskia at gcc dot gnu.org
` (2 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-12-10 23:09 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112949
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Resolution|--- |INVALID
Status|UNCONFIRMED |RESOLVED
--- Comment #4 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to Krister Walfridsson from comment #3)
> The C program is obviously UB. But the optimization is done on GIMPLE, and
> it is not obvious to me that the GIMPLE code is UB -- we have a function
> called __builtin_clz that calls an internal function, so they are
> different...
Not exactly. GCC does not distinguish between __builtin_* the builtin vs an
user function really.
You mention "internal call" but __builtin_clz is not an `internal call` but
rather a call to a function decl called __builtin_clz where the decl is a
builtin call.
That is the call to __builtin_clz is the same decl as the function being
defined.
There is no undefinedness in the range here since they are exactly the same.
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug tree-optimization/112949] evrp produces incorrect range for __builtin_clz
2023-12-10 22:48 [Bug tree-optimization/112949] New: evrp produces incorrect range for __builtin_clz kristerw at gcc dot gnu.org
` (3 preceding siblings ...)
2023-12-10 23:09 ` pinskia at gcc dot gnu.org
@ 2023-12-10 23:11 ` pinskia at gcc dot gnu.org
2023-12-10 23:31 ` pinskia at gcc dot gnu.org
2023-12-10 23:32 ` pinskia at gcc dot gnu.org
6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-12-10 23:11 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112949
--- Comment #5 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Oh the definition of __builtin_clz does not have return value so the value is
undefined to begin with.
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug tree-optimization/112949] evrp produces incorrect range for __builtin_clz
2023-12-10 22:48 [Bug tree-optimization/112949] New: evrp produces incorrect range for __builtin_clz kristerw at gcc dot gnu.org
` (4 preceding siblings ...)
2023-12-10 23:11 ` pinskia at gcc dot gnu.org
@ 2023-12-10 23:31 ` pinskia at gcc dot gnu.org
2023-12-10 23:32 ` pinskia at gcc dot gnu.org
6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-12-10 23:31 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112949
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
See Also| |https://gcc.gnu.org/bugzill
| |a/show_bug.cgi?id=32455
--- Comment #6 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
See PR 32455 and PR 99211 on why this really should have been rejected rather
than allowing a definition of __builtin_* .
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug tree-optimization/112949] evrp produces incorrect range for __builtin_clz
2023-12-10 22:48 [Bug tree-optimization/112949] New: evrp produces incorrect range for __builtin_clz kristerw at gcc dot gnu.org
` (5 preceding siblings ...)
2023-12-10 23:31 ` pinskia at gcc dot gnu.org
@ 2023-12-10 23:32 ` pinskia at gcc dot gnu.org
6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-12-10 23:32 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112949
--- Comment #7 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Specifically https://gcc.gnu.org/bugzilla/show_bug.cgi?id=32455#c4 .
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2023-12-10 23:32 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-12-10 22:48 [Bug tree-optimization/112949] New: evrp produces incorrect range for __builtin_clz kristerw at gcc dot gnu.org
2023-12-10 22:50 ` [Bug tree-optimization/112949] " pinskia at gcc dot gnu.org
2023-12-10 22:53 ` pinskia at gcc dot gnu.org
2023-12-10 23:03 ` kristerw at gcc dot gnu.org
2023-12-10 23:09 ` pinskia at gcc dot gnu.org
2023-12-10 23:11 ` pinskia at gcc dot gnu.org
2023-12-10 23:31 ` pinskia at gcc dot gnu.org
2023-12-10 23:32 ` 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).