Efficient Integer Overflow Checking in LLVM (2016)
blog.regehr.org
blog.regehr.org
Presumably .Net goes to great lengths to optimise overflow-checking, as the checks are enabled for production use. I wonder if they manage to get the overhead to below the 8.7% mentioned in the article.
edit: I had put OpenJDK and .Net but tom_mellior is right to point out that Java has wrapping arithmetic
Are you maybe mixing this up with array bounds checking?
I was right about .Net though. Assuming a checked context, .Net (and C#) throw on overflow, rather than wrapping. [1]
[0] https://docs.oracle.com/en/java/javase/11/docs/api/java.base...
[1] https://docs.microsoft.com/en-us/dotnet/csharp/language-refe...
You're right of course. Please see my response to tom_mellior.
That's when I added them to perl's add operator. Being about 10% faster than manual checking the high bits. gcc added them about one year later.
So LLVM could do runtime profiling if it wanted. But I suspect that in the majority of the cases the cost of the profiling would be worse than the potential gains.
I’m talking about:
- abstract interpretation using a streamlined version of the octagon domain.
- instruction selection and register allocation hacks to emit the best possible code for checked math. I don’t think llvm has parity with B3 here, particularly in cases where inputs to the math are live on the failing case.
- probably other stuff. IRs that start out with checked math tend to include checked math reasoning in more optimizations.
Do you have any links/source code where I can read up about this (possibly in the context of compilers)? I've never heard of the term octagon domain before.
https://www.cs.utexas.edu/~tdillig/cs395/octagon.pdf
https://www-apr.lip6.fr/~mine/publi/article-mine-HOSC06.pdf
If you don't know about abstract interpretation, start at https://en.wikipedia.org/wiki/Data-flow_analysis and https://en.wikipedia.org/wiki/Abstract_interpretation
https://news.ycombinator.com/item?id=11462308 (24 comments)
I don't want this in release mode.
Please tell me that this overflow checking is turned off by default.
-fsanitize=signed-integer-overflow
See the UBSan docs: https://clang.llvm.org/docs/UndefinedBehaviorSanitizer.html