public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/94911] New: Failure to optimize comparisons of VLA sizes
@ 2020-05-01 21:04 gabravier at gmail dot com
2020-05-01 21:40 ` [Bug tree-optimization/94911] " glisse at gcc dot gnu.org
` (5 more replies)
0 siblings, 6 replies; 7+ messages in thread
From: gabravier at gmail dot com @ 2020-05-01 21:04 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94911
Bug ID: 94911
Summary: Failure to optimize comparisons of VLA sizes
Product: gcc
Version: 10.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: gabravier at gmail dot com
Target Milestone: ---
inline void assume(_Bool b)
{
if (!b)
__builtin_unreachable();
}
_Bool f(int n)
{
assume(n >= 1);
typedef int A[n];
++n;
A a;
int b[n];
n -= 2;
typedef int C[n];
C c;
return (sizeof(a) < sizeof(b)) && (sizeof(a) > sizeof(c));
}
This C code (this will have different results in C++ with GCC) should always
`return true`. LLVM makes this transformation, but GCC does not.
Also, extra question, is the fact that this always returns `false` when
compiled as C++ normal ? Clang has it return `true` if compiled as C++.
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug tree-optimization/94911] Failure to optimize comparisons of VLA sizes
2020-05-01 21:04 [Bug tree-optimization/94911] New: Failure to optimize comparisons of VLA sizes gabravier at gmail dot com
@ 2020-05-01 21:40 ` glisse at gcc dot gnu.org
2020-05-01 22:10 ` pinskia at gcc dot gnu.org
` (4 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: glisse at gcc dot gnu.org @ 2020-05-01 21:40 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94911
--- Comment #1 from Marc Glisse <glisse at gcc dot gnu.org> ---
gcc computes sizeof(a) as 4ul*(size_t)n, and unsigned types don't provide nice
overflow guarantees, so that complicates things.
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug tree-optimization/94911] Failure to optimize comparisons of VLA sizes
2020-05-01 21:04 [Bug tree-optimization/94911] New: Failure to optimize comparisons of VLA sizes gabravier at gmail dot com
2020-05-01 21:40 ` [Bug tree-optimization/94911] " glisse at gcc dot gnu.org
@ 2020-05-01 22:10 ` pinskia at gcc dot gnu.org
2020-05-01 22:21 ` pinskia at gcc dot gnu.org
` (3 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu.org @ 2020-05-01 22:10 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94911
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Severity|normal |enhancement
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug tree-optimization/94911] Failure to optimize comparisons of VLA sizes
2020-05-01 21:04 [Bug tree-optimization/94911] New: Failure to optimize comparisons of VLA sizes gabravier at gmail dot com
2020-05-01 21:40 ` [Bug tree-optimization/94911] " glisse at gcc dot gnu.org
2020-05-01 22:10 ` pinskia at gcc dot gnu.org
@ 2020-05-01 22:21 ` pinskia at gcc dot gnu.org
2020-05-01 22:35 ` glisse at gcc dot gnu.org
` (2 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu.org @ 2020-05-01 22:21 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94911
--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to Marc Glisse from comment #1)
> gcc computes sizeof(a) as 4ul*(size_t)n, and unsigned types don't provide
> nice overflow guarantees, so that complicates things.
While the C++ front-end does:
(sizetype) ((ssizetype) n + -1) + 1) * 4)
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug tree-optimization/94911] Failure to optimize comparisons of VLA sizes
2020-05-01 21:04 [Bug tree-optimization/94911] New: Failure to optimize comparisons of VLA sizes gabravier at gmail dot com
` (2 preceding siblings ...)
2020-05-01 22:21 ` pinskia at gcc dot gnu.org
@ 2020-05-01 22:35 ` glisse at gcc dot gnu.org
2023-05-13 5:04 ` pinskia at gcc dot gnu.org
2023-05-13 12:25 ` gabravier at gmail dot com
5 siblings, 0 replies; 7+ messages in thread
From: glisse at gcc dot gnu.org @ 2020-05-01 22:35 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94911
--- Comment #3 from Marc Glisse <glisse at gcc dot gnu.org> ---
Since VLA is an extension for compatibility with C, it is strange that it
behaves differently (does one use the value of n at the time of the typedef and
the other at the time of the declaration?). This bug is about the optimization,
maybe a separate report about the C++ behavior would make sense.
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug tree-optimization/94911] Failure to optimize comparisons of VLA sizes
2020-05-01 21:04 [Bug tree-optimization/94911] New: Failure to optimize comparisons of VLA sizes gabravier at gmail dot com
` (3 preceding siblings ...)
2020-05-01 22:35 ` glisse at gcc dot gnu.org
@ 2023-05-13 5:04 ` pinskia at gcc dot gnu.org
2023-05-13 12:25 ` gabravier at gmail dot com
5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-05-13 5:04 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94911
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Last reconfirmed| |2023-05-13
Ever confirmed|0 |1
Status|UNCONFIRMED |NEW
--- Comment #4 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
# RANGE [irange] int [1, +INF] NONZERO 0x7fffffff
intD.7 n_11(D) = nD.4385;
sizetype _2;
_BoolD.4372 _16;
;; basic block 2, loop depth 0, count 1073741824 (estimated locally), maybe
hot
;; prev block 0, next block 1, flags: (NEW, REACHABLE, VISITED)
;; pred: ENTRY [always] count:1073741824 (estimated locally)
(FALLTHRU,EXECUTABLE)
# RANGE [irange] sizetype [1, 2147483647] NONZERO 0x7fffffff
_1 = (sizetype) n_11(D);
# RANGE [irange] sizetype [4, 8589934588] NONZERO 0x1fffffffc
_2 = _1 * 4;
_16 = _2 > 3;
We have the information to do the folding in optimize but not earlier ...
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug tree-optimization/94911] Failure to optimize comparisons of VLA sizes
2020-05-01 21:04 [Bug tree-optimization/94911] New: Failure to optimize comparisons of VLA sizes gabravier at gmail dot com
` (4 preceding siblings ...)
2023-05-13 5:04 ` pinskia at gcc dot gnu.org
@ 2023-05-13 12:25 ` gabravier at gmail dot com
5 siblings, 0 replies; 7+ messages in thread
From: gabravier at gmail dot com @ 2023-05-13 12:25 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94911
--- Comment #5 from Gabriel Ravier <gabravier at gmail dot com> ---
Also, as an extra note, w.r.t.
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94911#c3, I've just noticed that I
had indeed made a separate bug report at https://gcc.gnu.org/PR94912 (which
ended up being closed as a duplicate of https://gcc.gnu.org/PR68531) - just
wanted to clarify that so nobody ends up filing more duplicates like I almost
just did
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2023-05-13 12:25 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-01 21:04 [Bug tree-optimization/94911] New: Failure to optimize comparisons of VLA sizes gabravier at gmail dot com
2020-05-01 21:40 ` [Bug tree-optimization/94911] " glisse at gcc dot gnu.org
2020-05-01 22:10 ` pinskia at gcc dot gnu.org
2020-05-01 22:21 ` pinskia at gcc dot gnu.org
2020-05-01 22:35 ` glisse at gcc dot gnu.org
2023-05-13 5:04 ` pinskia at gcc dot gnu.org
2023-05-13 12:25 ` gabravier at gmail dot com
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).