public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/114967] New: Missed optimization: std::min((int) f, -a) ==> -a where (bool f, unsigned char a)
@ 2024-05-07 8:12 652023330028 at smail dot nju.edu.cn
2024-05-07 8:26 ` [Bug tree-optimization/114967] " pinskia at gcc dot gnu.org
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: 652023330028 at smail dot nju.edu.cn @ 2024-05-07 8:12 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114967
Bug ID: 114967
Summary: Missed optimization: std::min((int) f, -a) ==> -a
where (bool f, unsigned char a)
Product: gcc
Version: 15.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: 652023330028 at smail dot nju.edu.cn
Target Milestone: ---
Hello, we noticed that the code below can be optimized as stated in the title
(std::min((int) f, -a) ==> -a), but gcc -O3 seems to have missed it.
Reduced code:
https://godbolt.org/z/soWxqTMz8
#include <algorithm>
int n;
void func(bool f, unsigned char a) {
n = std::min((int) f, -a);
}
GCC -O3:
<bb 2> [local count: 1073741824]:
# DEBUG BEGIN_STMT
_1 = (int) a_5(D);
_2 = -_1;
_3 = (int) f_7(D);
# DEBUG __a => &D.18872
# DEBUG __b => &D.18873
# DEBUG INLINE_ENTRY min
if (_2 < _3)
goto <bb 3>; [34.00%]
else
goto <bb 4>; [66.00%]
<bb 3> [local count: 365072224]:
<bb 4> [local count: 1073741824]:
# _4 = PHI <0(2), _2(3)>
# DEBUG __a => NULL
# DEBUG __b => NULL
n = _4;
return;
func(bool, unsigned char):
movzx esi, sil
movzx edi, dil
xor eax, eax
neg esi
cmp esi, edi
cmovge esi, eax
mov DWORD PTR n[rip], esi
ret
Expected code (Clang):
func(bool, unsigned char): # @func(bool, unsigned
char)
neg esi
mov dword ptr [rip + n], esi
ret
Thank you very much for your time and effort! We look forward to hearing from
you.
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug tree-optimization/114967] Missed optimization: std::min((int) f, -a) ==> -a where (bool f, unsigned char a)
2024-05-07 8:12 [Bug tree-optimization/114967] New: Missed optimization: std::min((int) f, -a) ==> -a where (bool f, unsigned char a) 652023330028 at smail dot nju.edu.cn
@ 2024-05-07 8:26 ` pinskia at gcc dot gnu.org
2024-05-08 3:42 ` pinskia at gcc dot gnu.org
2024-05-08 3:59 ` pinskia at gcc dot gnu.org
2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-05-07 8:26 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114967
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Keywords| |missed-optimization
Last reconfirmed| |2024-05-07
Ever confirmed|0 |1
Assignee|unassigned at gcc dot gnu.org |pinskia at gcc dot gnu.org
Status|UNCONFIRMED |ASSIGNED
--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
I think this is a dup of another issue I filed. Where vrp decides to replace
the value in the phi of the max and then it goes down hill from there.
I will take a look.
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug tree-optimization/114967] Missed optimization: std::min((int) f, -a) ==> -a where (bool f, unsigned char a)
2024-05-07 8:12 [Bug tree-optimization/114967] New: Missed optimization: std::min((int) f, -a) ==> -a where (bool f, unsigned char a) 652023330028 at smail dot nju.edu.cn
2024-05-07 8:26 ` [Bug tree-optimization/114967] " pinskia at gcc dot gnu.org
@ 2024-05-08 3:42 ` pinskia at gcc dot gnu.org
2024-05-08 3:59 ` pinskia at gcc dot gnu.org
2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-05-08 3:42 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114967
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
See Also| |https://gcc.gnu.org/bugzill
| |a/show_bug.cgi?id=107888
--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
We are able to handle this:
```
void func1(bool f, unsigned char a) {
int t = f;
int tt = -a;
int ttt = t <= tt ? t : tt;
n = ttt;
}
```
And we able to handle func if we disable evrp.
So yes the issue is the same as what I mentioned. Basically this is what I
mentioned in bug 107888 comment #2 . But in the original testcase in bug 107888
was able to be handled differently, it is the other testcase that still needs
to be handled.
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug tree-optimization/114967] Missed optimization: std::min((int) f, -a) ==> -a where (bool f, unsigned char a)
2024-05-07 8:12 [Bug tree-optimization/114967] New: Missed optimization: std::min((int) f, -a) ==> -a where (bool f, unsigned char a) 652023330028 at smail dot nju.edu.cn
2024-05-07 8:26 ` [Bug tree-optimization/114967] " pinskia at gcc dot gnu.org
2024-05-08 3:42 ` pinskia at gcc dot gnu.org
@ 2024-05-08 3:59 ` pinskia at gcc dot gnu.org
2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-05-08 3:59 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114967
--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
I had a patch for this which I didn't finish up and I hope to get it done for
GCC 15.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2024-05-08 3:59 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-05-07 8:12 [Bug tree-optimization/114967] New: Missed optimization: std::min((int) f, -a) ==> -a where (bool f, unsigned char a) 652023330028 at smail dot nju.edu.cn
2024-05-07 8:26 ` [Bug tree-optimization/114967] " pinskia at gcc dot gnu.org
2024-05-08 3:42 ` pinskia at gcc dot gnu.org
2024-05-08 3:59 ` 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).