News for hackers. Stuff that matters.
Re:Efficient Integer Overflow Checking in LLVM (2016) by MaxBarraclough on Thursday September 24, 2020 @05:31AM (#24576861)
Interesting post, as Regehr's posts tend to be.

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

Re:Efficient Integer Overflow Checking in LLVM (2016) by tom_mellior on Thursday September 24, 2020 @05:50AM (#24576969)
Why would OpenJDK do integer overflow checking? Java integers have well-defined two's complement wrapping semantics. When you add two positive numbers and get a negative result, this might not be what the programmer wanted, but it is not undefined behavior like it is in C.

Are you maybe mixing this up with array bounds checking?

Re:Efficient Integer Overflow Checking in LLVM (2016) by MaxBarraclough on Thursday September 24, 2020 @06:06AM (#24577047)
Oops, you're right! I forgot Java arithmetic wraps, offering (rarely used) methods for overflow-checked arithmetic. [0]

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...

Re:Efficient Integer Overflow Checking in LLVM (2016) by chrisseaton on Thursday September 24, 2020 @06:05AM (#24577039)
OpenJDK only does overflow checking in a tiny number of cases.
Re:Efficient Integer Overflow Checking in LLVM (2016) by MaxBarraclough on Thursday September 24, 2020 @06:10AM (#24577070)
Cunningham's Law strikes again!

You're right of course. Please see my response to tom_mellior.

Re:Efficient Integer Overflow Checking in LLVM (2016) by rurban on Thursday September 24, 2020 @06:11AM (#24577079)
@dang Can we have a (2016) in the title please.

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.

Re:Efficient Integer Overflow Checking in LLVM (2016) by pizlonator on Thursday September 24, 2020 @04:42AM (#24576612)
Maybe some day llvm will know how to optimize overflow checks as well as JavaScript engines do.
Re:Efficient Integer Overflow Checking in LLVM (2016) by saagarjha on Thursday September 24, 2020 @11:04AM (#24579270)
Maybe, but LLVM has the disadvantage that speculating “this won’t overflow” and creating a fast path with that information is not something that can be fixed if more profiling data comes in at runtime saying it was a poor choice.
Re:Efficient Integer Overflow Checking in LLVM (2016) by pizlonator on Thursday September 24, 2020 @02:49PM (#24582117)
Those aren’t the optimizations I’m talking about. That’s not even how JSC optimizes overflow checks.

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.

Re:Efficient Integer Overflow Checking in LLVM (2016) by frankpf on Thursday September 24, 2020 @06:34PM (#24584464)
> - abstract interpretation using a streamlined version of the octagon domain.

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.

Re:Efficient Integer Overflow Checking in LLVM (2016) by tom_mellior on Saturday September 26, 2020 @05:14PM (#24602175)
Re:Efficient Integer Overflow Checking in LLVM (2016) by tom_mellior on Wednesday September 30, 2020 @09:18AM (#24638413)
Having said the above, I can't find any other information on JavaScriptCore using octagons. Searching https://trac.webkit.org/browser/trunk/Source/JavaScriptCore for "octagon" yields nothing.
Re:Efficient Integer Overflow Checking in LLVM (2016) by im3w1l on Thursday September 24, 2020 @02:31PM (#24581882)
The C/C++ standards allow compilers to do whatever they want as long as it does not cause observable output changes.

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.

Re:Efficient Integer Overflow Checking in LLVM (2016) by nly on Thursday September 24, 2020 @04:50AM (#24576642)
Is this tongue in cheek? JavaScript numbers are floating point, are they not?
Re:Efficient Integer Overflow Checking in LLVM (2016) by titzer on Thursday September 24, 2020 @04:52AM (#24576657)
No, JS engines optimize heavily for small integers (31 or 32 bits) and dynamically overflow into double range as necessary.
Re:Efficient Integer Overflow Checking in LLVM (2016) by chrisseaton on Thursday September 24, 2020 @06:06AM (#24577048)
They aren’t literally implemented as floating point in most cases. That’d be crazy! If the number fits in an integer then a sensible implementation uses an integer.
Re:Efficient Integer Overflow Checking in LLVM (2016) by KindOne on Thursday September 24, 2020 @08:05AM (#24577762)
Re:Efficient Integer Overflow Checking in LLVM (2016) by stephc_int13 on Thursday September 24, 2020 @06:06AM (#24577052)
Wow.

I don't want this in release mode.

Please tell me that this overflow checking is turned off by default.

Re:Efficient Integer Overflow Checking in LLVM (2016) by cbarrick on Thursday September 24, 2020 @10:12AM (#24578766)
You have to explicitly enable UBSan checks:

    -fsanitize=signed-integer-overflow
See the UBSan docs: https://clang.llvm.org/docs/UndefinedBehaviorSanitizer.html
Re:Efficient Integer Overflow Checking in LLVM (2016) by commandlinefan on Thursday September 24, 2020 @09:49AM (#24578571)
Hm - I was wondering exactly what "ud2" does when it's triggered (looks like an "undefined opcode"... causes a seg fault?), but what's worse? An app that crashes with no apparent cause, or a bank account that resets to $0 if it gets too big?
Re:Efficient Integer Overflow Checking in LLVM (2016) by saagarjha on Thursday September 24, 2020 @11:05AM (#24579278)
You’ll get a SIGILL.
Re:Efficient Integer Overflow Checking in LLVM (2016) by Gaelan on Thursday September 24, 2020 @06:03AM (#24577032)
(2016)