* [Bug target/109896] Missed optimisation: overflow detection in multiplication instructions for operator new
2023-05-17 18:34 [Bug target/109896] New: Missed optimisation: overflow detection in multiplication instructions for operator new thiago at kde dot org
@ 2023-05-17 18:45 ` pinskia at gcc dot gnu.org
2023-05-17 20:39 ` hjl.tools at gmail dot com
` (9 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-05-17 18:45 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109896
--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
I suspect the overflow code was added before __builtin_*_overflow were added
which is why the generated code is this way.
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug target/109896] Missed optimisation: overflow detection in multiplication instructions for operator new
2023-05-17 18:34 [Bug target/109896] New: Missed optimisation: overflow detection in multiplication instructions for operator new thiago at kde dot org
2023-05-17 18:45 ` [Bug target/109896] " pinskia at gcc dot gnu.org
@ 2023-05-17 20:39 ` hjl.tools at gmail dot com
2023-05-17 23:42 ` thiago at kde dot org
` (8 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: hjl.tools at gmail dot com @ 2023-05-17 20:39 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109896
--- Comment #2 from H.J. Lu <hjl.tools at gmail dot com> ---
(In reply to Andrew Pinski from comment #1)
> I suspect the overflow code was added before __builtin_*_overflow were added
> which is why the generated code is this way.
Should the C++ front-end use __builtin_mul_overflow?
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug target/109896] Missed optimisation: overflow detection in multiplication instructions for operator new
2023-05-17 18:34 [Bug target/109896] New: Missed optimisation: overflow detection in multiplication instructions for operator new thiago at kde dot org
2023-05-17 18:45 ` [Bug target/109896] " pinskia at gcc dot gnu.org
2023-05-17 20:39 ` hjl.tools at gmail dot com
@ 2023-05-17 23:42 ` thiago at kde dot org
2023-05-17 23:46 ` pinskia at gcc dot gnu.org
` (7 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: thiago at kde dot org @ 2023-05-17 23:42 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109896
--- Comment #3 from Thiago Macieira <thiago at kde dot org> ---
(In reply to H.J. Lu from comment #2)
> (In reply to Andrew Pinski from comment #1)
> > I suspect the overflow code was added before __builtin_*_overflow were added
> > which is why the generated code is this way.
>
> Should the C++ front-end use __builtin_mul_overflow?
That's what that code is doing, yes.
But mind you that not all examples are doing actual multiplications. That's why
I had the weird size of 47.
A size that is a power of 2 is just doing bit checks. For example, 16:
movq %rdi, %rax
shrq $59, %rax
jne .L2
Other sizes do the compare, but there's no multiplication involved. For 24:
movabsq $384307168202282325, %rax
cmpq %rdi, %rax
jb .L2
leaq (%rdi,%rdi,2), %rdi
salq $3, %rdi
5 instructions, 4 cycles (not including front-end decode), so roughly the same
as the imulq example above (4 cycles), but with far more ports to dispatch to.
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug target/109896] Missed optimisation: overflow detection in multiplication instructions for operator new
2023-05-17 18:34 [Bug target/109896] New: Missed optimisation: overflow detection in multiplication instructions for operator new thiago at kde dot org
` (2 preceding siblings ...)
2023-05-17 23:42 ` thiago at kde dot org
@ 2023-05-17 23:46 ` pinskia at gcc dot gnu.org
2023-05-18 0:13 ` thiago at kde dot org
` (6 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-05-17 23:46 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109896
--- Comment #4 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to Thiago Macieira from comment #3)
> 5 instructions, 4 cycles (not including front-end decode), so roughly the
> same as the imulq example above (4 cycles), but with far more ports to
> dispatch to.
If you are that picky for cycles, these cycles are not going to be a problem
compared to the dynamic allocation that is just about to happen ......
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug target/109896] Missed optimisation: overflow detection in multiplication instructions for operator new
2023-05-17 18:34 [Bug target/109896] New: Missed optimisation: overflow detection in multiplication instructions for operator new thiago at kde dot org
` (3 preceding siblings ...)
2023-05-17 23:46 ` pinskia at gcc dot gnu.org
@ 2023-05-18 0:13 ` thiago at kde dot org
2023-05-18 8:33 ` redi at gcc dot gnu.org
` (5 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: thiago at kde dot org @ 2023-05-18 0:13 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109896
--- Comment #5 from Thiago Macieira <thiago at kde dot org> ---
(In reply to Andrew Pinski from comment #4)
> If you are that picky for cycles, these cycles are not going to be a problem
> compared to the dynamic allocation that is just about to happen ......
Yeah, I realised that after I posted the reply. If the calculation is
successful, we're going to allocate memory and that's neither fast nor
determinstic. If it overflows, we're going to unwind the stack, which is even
worse. I had only looked at the multiplication and failed to consider what
comes after it.
So, yeah, do this if it's a low-hanging fruit.
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug target/109896] Missed optimisation: overflow detection in multiplication instructions for operator new
2023-05-17 18:34 [Bug target/109896] New: Missed optimisation: overflow detection in multiplication instructions for operator new thiago at kde dot org
` (4 preceding siblings ...)
2023-05-18 0:13 ` thiago at kde dot org
@ 2023-05-18 8:33 ` redi at gcc dot gnu.org
2023-05-18 14:08 ` thiago at kde dot org
` (4 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: redi at gcc dot gnu.org @ 2023-05-18 8:33 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109896
--- Comment #6 from Jonathan Wakely <redi at gcc dot gnu.org> ---
With placement-new there's no allocation:
https://gcc.godbolt.org/z/68e4PaeYz
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug target/109896] Missed optimisation: overflow detection in multiplication instructions for operator new
2023-05-17 18:34 [Bug target/109896] New: Missed optimisation: overflow detection in multiplication instructions for operator new thiago at kde dot org
` (5 preceding siblings ...)
2023-05-18 8:33 ` redi at gcc dot gnu.org
@ 2023-05-18 14:08 ` thiago at kde dot org
2024-06-06 16:49 ` [Bug c++/109896] " pinskia at gcc dot gnu.org
` (3 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: thiago at kde dot org @ 2023-05-18 14:08 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109896
--- Comment #7 from Thiago Macieira <thiago at kde dot org> ---
(In reply to Jonathan Wakely from comment #6)
> With placement-new there's no allocation:
> https://gcc.godbolt.org/z/68e4PaeYz
Is the exception expected there, though?
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug c++/109896] Missed optimisation: overflow detection in multiplication instructions for operator new
2023-05-17 18:34 [Bug target/109896] New: Missed optimisation: overflow detection in multiplication instructions for operator new thiago at kde dot org
` (6 preceding siblings ...)
2023-05-18 14:08 ` thiago at kde dot org
@ 2024-06-06 16:49 ` pinskia at gcc dot gnu.org
2024-06-06 22:03 ` pinskia at gcc dot gnu.org
` (2 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-06-06 16:49 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109896
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Last reconfirmed| |2024-06-06
Status|UNCONFIRMED |ASSIGNED
Component|target |c++
CC| |pinskia at gcc dot gnu.org
Ever confirmed|0 |1
--- Comment #8 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Confirmed. Let me see if I can optimize this better ...
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug c++/109896] Missed optimisation: overflow detection in multiplication instructions for operator new
2023-05-17 18:34 [Bug target/109896] New: Missed optimisation: overflow detection in multiplication instructions for operator new thiago at kde dot org
` (7 preceding siblings ...)
2024-06-06 16:49 ` [Bug c++/109896] " pinskia at gcc dot gnu.org
@ 2024-06-06 22:03 ` pinskia at gcc dot gnu.org
2024-06-07 1:42 ` pinskia at gcc dot gnu.org
2024-06-07 14:05 ` pinskia at gcc dot gnu.org
10 siblings, 0 replies; 12+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-06-06 22:03 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109896
--- Comment #9 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Created attachment 58374
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=58374&action=edit
Patch which I am testing
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug c++/109896] Missed optimisation: overflow detection in multiplication instructions for operator new
2023-05-17 18:34 [Bug target/109896] New: Missed optimisation: overflow detection in multiplication instructions for operator new thiago at kde dot org
` (8 preceding siblings ...)
2024-06-06 22:03 ` pinskia at gcc dot gnu.org
@ 2024-06-07 1:42 ` pinskia at gcc dot gnu.org
2024-06-07 14:05 ` pinskia at gcc dot gnu.org
10 siblings, 0 replies; 12+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-06-07 1:42 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109896
--- Comment #10 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to Andrew Pinski from comment #9)
> Created attachment 58374 [details]
> Patch which I am testing
There were some regressions. I have to go back and figure out how to fix them.
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug c++/109896] Missed optimisation: overflow detection in multiplication instructions for operator new
2023-05-17 18:34 [Bug target/109896] New: Missed optimisation: overflow detection in multiplication instructions for operator new thiago at kde dot org
` (9 preceding siblings ...)
2024-06-07 1:42 ` pinskia at gcc dot gnu.org
@ 2024-06-07 14:05 ` pinskia at gcc dot gnu.org
10 siblings, 0 replies; 12+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-06-07 14:05 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109896
--- Comment #11 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to Andrew Pinski from comment #10)
> (In reply to Andrew Pinski from comment #9)
> > Created attachment 58374 [details]
> > Patch which I am testing
>
> There were some regressions. I have to go back and figure out how to fix
> them.
I am will come back to this but maybe in a few months.
^ permalink raw reply [flat|nested] 12+ messages in thread