public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/114317] New: Missing optimization for multiple condition statements
@ 2024-03-12 14:10 carnet at student dot ethz.ch
2024-03-12 14:22 ` [Bug ipa/114317] " rguenth at gcc dot gnu.org
2024-03-12 14:43 ` hubicka at ucw dot cz
0 siblings, 2 replies; 3+ messages in thread
From: carnet at student dot ethz.ch @ 2024-03-12 14:10 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114317
Bug ID: 114317
Summary: Missing optimization for multiple condition statements
Product: gcc
Version: 14.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: carnet at student dot ethz.ch
Target Milestone: ---
GCC -O3 is not able to optimize the [b && (g = 0)] statement even though g is
static and 0. So the statement does not change the value of g. This further
prevents the optimiziation of the later statements.
https://godbolt.org/z/r7P7qajYn
Source:
int b;
int *e = &b;
static int g = 0;
int main() {
b && (g = 0);
if (3 - g){
*e = b;
}
if (253 - (9 | g)){
*e = b;
}
return *e;
}
x86 -O3 Assembly:
main:
movl b(%rip), %eax
testl %eax, %eax
je .L2
movq e(%rip), %rdx
xorl %edi, %edi
movl %edi, g(%rip)
movl %eax, (%rdx)
movl b(%rip), %eax
.L3:
movl %eax, (%rdx)
ret
.L2:
movl g(%rip), %ecx
movq e(%rip), %rdx
cmpl $3, %ecx
je .L3
xorl %esi, %esi
orl $9, %ecx
movl %esi, (%rdx)
cmpl $253, %ecx
jne .L8
ret
.L8:
movl b(%rip), %eax
jmp .L3
e:
.quad b
b:
.zero 4
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug ipa/114317] Missing optimization for multiple condition statements
2024-03-12 14:10 [Bug tree-optimization/114317] New: Missing optimization for multiple condition statements carnet at student dot ethz.ch
@ 2024-03-12 14:22 ` rguenth at gcc dot gnu.org
2024-03-12 14:43 ` hubicka at ucw dot cz
1 sibling, 0 replies; 3+ messages in thread
From: rguenth at gcc dot gnu.org @ 2024-03-12 14:22 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114317
Richard Biener <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Last reconfirmed| |2024-03-12
Component|tree-optimization |ipa
Status|UNCONFIRMED |NEW
CC| |hubicka at gcc dot gnu.org
Ever confirmed|0 |1
--- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> ---
Confirmed. I think this is known and there's possibly a duplicate. IPA
reference doesn't consider writing the same value as in the initializer
as a way to turn the variable read-only (it would need to elide the stores
of course).
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug ipa/114317] Missing optimization for multiple condition statements
2024-03-12 14:10 [Bug tree-optimization/114317] New: Missing optimization for multiple condition statements carnet at student dot ethz.ch
2024-03-12 14:22 ` [Bug ipa/114317] " rguenth at gcc dot gnu.org
@ 2024-03-12 14:43 ` hubicka at ucw dot cz
1 sibling, 0 replies; 3+ messages in thread
From: hubicka at ucw dot cz @ 2024-03-12 14:43 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114317
--- Comment #2 from Jan Hubicka <hubicka at ucw dot cz> ---
> (it would need to elide the stores of course).
We do have way to elide stores, since we can optimize out write-only
values. What we do not have readilly available is the value written to
a reference (ipa-refs only connects variables/functions to statements
that write/load/take address).
I think the plan is to add summary template for references, like we have
for callgraph edges and symbols. Then we can keep track of values and
do optimizations like this. It is on my todo for quite some time ;)
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2024-03-12 14:43 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-12 14:10 [Bug tree-optimization/114317] New: Missing optimization for multiple condition statements carnet at student dot ethz.ch
2024-03-12 14:22 ` [Bug ipa/114317] " rguenth at gcc dot gnu.org
2024-03-12 14:43 ` hubicka at ucw dot cz
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).