public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/114489] New: introduced redundant load facing different branches
@ 2024-03-26 20:09 absoler at smail dot nju.edu.cn
2024-03-26 20:18 ` [Bug tree-optimization/114489] " pinskia at gcc dot gnu.org
2024-03-26 20:19 ` pinskia at gcc dot gnu.org
0 siblings, 2 replies; 3+ messages in thread
From: absoler at smail dot nju.edu.cn @ 2024-03-26 20:09 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114489
Bug ID: 114489
Summary: introduced redundant load facing different branches
Product: gcc
Version: 13.2.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: absoler at smail dot nju.edu.cn
Target Milestone: ---
similar with https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107050, but without
function call.
```
int f = 1;
int g1, g2, arr[10];
int func_1() {
int a = 4;
int *p1 = &g1;
if (f) {
arr[0] = g2;
int *p2 = &a;
a = 1;
}
*p1 &= (a > 9) - 5;
return a;
}
int main() {
func_1();
}
```
gcc-13.2.0 -O1 generates:
```
func_1():
401106: mov 0x2f80(%rip),%eax # 40408c <g1> # first load
40110c: mov $0x4,%edx
401111: cmpl $0x0,0x2f10(%rip) # 404028 <f>
401118: je 401131 <func_1+0x2b>
40111a: mov 0x2f68(%rip),%eax # 404088 <g2>
401120: mov %eax,0x2f3a(%rip) # 404060 <arr>
401126: mov 0x2f60(%rip),%eax # 40408c <g1> # second load
40112c: mov $0x1,%edx
401131: and $0xfffffffb,%eax
401134: mov %eax,0x2f52(%rip) # 40408c <g1>
40113a: mov %edx,%eax
40113c: retq
```
I wonder why compiler won't use another register to hold `g2`, so that the
second load is unnecessary.
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug tree-optimization/114489] introduced redundant load facing different branches
2024-03-26 20:09 [Bug tree-optimization/114489] New: introduced redundant load facing different branches absoler at smail dot nju.edu.cn
@ 2024-03-26 20:18 ` pinskia at gcc dot gnu.org
2024-03-26 20:19 ` pinskia at gcc dot gnu.org
1 sibling, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-03-26 20:18 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114489
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution|--- |WONTFIX
--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
<bb 3> [local count: 375809640]:
_3 = g1;
goto <bb 5>; [100.00%]
<bb 4> [local count: 697932184]:
g2.1_2 = g2;
arr[0] = g2.1_2;
_8 = g1;
<bb 5> [local count: 1073741824]:
# _6 = PHI <_8(4), _3(3)>
Which does not optimize unless using -O2.
This is on purpose.
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug tree-optimization/114489] introduced redundant load facing different branches
2024-03-26 20:09 [Bug tree-optimization/114489] New: introduced redundant load facing different branches absoler at smail dot nju.edu.cn
2024-03-26 20:18 ` [Bug tree-optimization/114489] " pinskia at gcc dot gnu.org
@ 2024-03-26 20:19 ` pinskia at gcc dot gnu.org
1 sibling, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-03-26 20:19 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114489
--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to Andrew Pinski from comment #1)
> <bb 3> [local count: 375809640]:
> _3 = g1;
> goto <bb 5>; [100.00%]
>
> <bb 4> [local count: 697932184]:
> g2.1_2 = g2;
> arr[0] = g2.1_2;
> _8 = g1;
>
> <bb 5> [local count: 1073741824]:
> # _6 = PHI <_8(4), _3(3)>
>
> Which does not optimize unless using -O2.
>
> This is on purpose.
In that PRE is not enabled at -O1 but it is at -O2.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2024-03-26 20:19 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-26 20:09 [Bug tree-optimization/114489] New: introduced redundant load facing different branches absoler at smail dot nju.edu.cn
2024-03-26 20:18 ` [Bug tree-optimization/114489] " pinskia at gcc dot gnu.org
2024-03-26 20:19 ` 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).