public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/114538] New: constant fold for (v + 1 == 0) == (v + 1 < v) fails when v + 1 is stored in variable
@ 2024-04-01 0:49 goon.pri.low at gmail dot com
2024-04-01 2:58 ` [Bug tree-optimization/114538] " pinskia at gcc dot gnu.org
0 siblings, 1 reply; 2+ messages in thread
From: goon.pri.low at gmail dot com @ 2024-04-01 0:49 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114538
Bug ID: 114538
Summary: constant fold for (v + 1 == 0) == (v + 1 < v) fails
when v + 1 is stored in variable
Product: gcc
Version: 14.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: goon.pri.low at gmail dot com
Target Milestone: ---
int unopt(unsigned v) {
unsigned n = v + 1;
return (n == 0) == (n < v);
}
int opt(unsigned v) {
return (v + 1 == 0) == (v + 1 < v);
}
unopt:
xor edx, edx
add edi, 1
setc dl
xor eax, eax
test edi, edi
setne al
xor eax, edx
ret
opt:
mov eax, 1
ret
^ permalink raw reply [flat|nested] 2+ messages in thread
* [Bug tree-optimization/114538] constant fold for (v + 1 == 0) == (v + 1 < v) fails when v + 1 is stored in variable
2024-04-01 0:49 [Bug tree-optimization/114538] New: constant fold for (v + 1 == 0) == (v + 1 < v) fails when v + 1 is stored in variable goon.pri.low at gmail dot com
@ 2024-04-01 2:58 ` pinskia at gcc dot gnu.org
0 siblings, 0 replies; 2+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-04-01 2:58 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114538
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Ever confirmed|0 |1
Severity|normal |enhancement
Last reconfirmed| |2024-04-01
Status|UNCONFIRMED |NEW
--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Note this can be expanded into non-CST even.
```
int unopt(unsigned v, unsigned t) {
unsigned n = v + t;
return (n < t) == (n < v);
}
int opt1(unsigned v, unsigned t) {
return (v + t < t) == (v + t < v);
}
```
Both are not optimized to 1.
In both cases, it is checking if `v+t` wraps (overflows).
Interesting is LLVM is not able to handle the non-CST form either.
That is it is able to handle:
```
int g(unsigned v, unsigned t) {
t = 555;
return (v + t < t) == (v + t < v);
}
```
Note the const form case is related to PR 114539 really which LLVM can handle
both cases.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2024-04-01 2:58 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-01 0:49 [Bug tree-optimization/114538] New: constant fold for (v + 1 == 0) == (v + 1 < v) fails when v + 1 is stored in variable goon.pri.low at gmail dot com
2024-04-01 2:58 ` [Bug tree-optimization/114538] " 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).