New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
eliminate -fwrapv #20584
eliminate -fwrapv #20584
Conversation
This was added late in the 5.20 release cycle to eliminate optimizations done by gcc that reflect the limits of well-defined behavior from the C standard. Recent testing and updates mean that such behaviour has been eliminated in the core itself, so remove what was intended to be a temporary change (at least to me.)
Unless there are benchmarks that show that |
How would we benchmark this, before and after the change? |
The Leaving it in masks undefined behavior defined by the C standard and means for our most common test cases (gcc) we aren't testing against what the C standard defines (or undefines). Leaving I certainly expected it to be removed when I proposed the change. |
I agree we should avoid relying on signed integer overflow to keep our code portable.
The problem is that signed integer overflow doesn't cause hard errors. The compiler can silently and subtly break the code in ways that our test suite won't detect, even with with ASan. The behaviour is unpredictable, it varies from compiler to compiler and it may change in the future versions. It's scary. There's a reason why so many C codebases (for example, the Linux kernel) use both My personal opinion is we should catch accidental signed overflows in our CI with e.g. ASan, but |
On Mon, Dec 05, 2022 at 05:07:11AM -0800, James E Keenan wrote:
> Unless there are benchmarks that show that `-fwrapv` noticeably decreases Perl's performance, I really don't see the point in asking the compiler to punish us with more UB.
How would we benchmark this, before and after the change?
With Porting/bench.pl, which is particularly good at detecting changes
involving just executing one extra CPU instruction or one more memory
read or write.
…--
31 Dec 1661: "I have newly taken a solemne oath about abstaining from plays".
1 Jan 1662: "And after ... we went by coach to the play".
-- The Diary of Samuel Pepys
|
You've largely convinced me, though we'll need to find a similar option for MSVC, since that also optimizes assuming no signed integer overflows (the mentioned switch wasn't accepted for me in compiler explorer). I haven't been able to find any documentation of the optimization changes caused by
Compiles to:
Unfortunately perl uses type punning so extensively that I don't think we'll ever be able to use strict aliasing, though maybe we'll be able to use Closing. |
This was added late in the 5.20 release cycle to eliminate optimizations done by gcc that reflect the limits of well-defined behavior from the C standard.
Recent testing and updates mean that such behavior has been eliminated in the core itself, so remove what was intended to be a temporary change (at least to me.)
The fixes the last remnants of #13690.
Now we just need to eliminate the need for
-fno-strict-aliasing
, which was also "only temporary" 34d1710