[llvm-dev] [RFC] Should we bump the bitcode version in LLVM 6.0?
llvm-dev at lists.llvm.org
Mon Feb 12 15:04:50 PST 2018
>> Just wanted to point out part of this even becoming a problem is the use of `isFast()`.
>> There should be warnings against using isFast() and the existing code should be
>> changed to query specific flags instead...
> Agree, but that wouldn’t solve the downgrade problem plus this is probably too late to
> fix LLVM 6.0 for all the isFast uses.
Just to be explicit, the point that the use of `isFast()` is a problem isn't new. I agree it's too late to fix it for LLVM 6.0, but that problem exists in earlier releases.
Prior to r317488 the problem already existed, except it was the use of `unsafeAlgebra()` that was the problem (that is, many of those really should have been changed to query the specific flags). But prior to r317488 the situation was worse, because the umbrella aspect of the `UnsafeAlgebra` flag essentially made it impossible to "subtract" a precise portion of the FastMathFlags.
In short, before and after r317488, `-ffast-math` on its own worked well, and still works well. But `-ffast-math <minus_some_portion>` (e.g., `-ffast-math -fno-reciprocal-math`) didn't work well prior to r317488, and was more or less impossible to make work well until the re-work of r317488. FTR, `-ffast-math <minus_some_portion>` has never worked well. The “way it doesn't work well” has changed over time. (In particular, going further back, pre-r297837 didn't work, but it didn't work in a way that's different from the way it doesn't work now. r297837 and r317488 both are steps to opening the door to allow changes that will make it work.)
Unless I'm missing something, when using bitcode from the "consistent" compiler (that is, pre-r317488 bitcode with a pre-r317488 compiler, and post-r317488 bitcode with a post-r317488 compiler), there are no examples of test-cases that are broken by r317488.
Which brings us back to Quentin's original question:
Should we bump the bitcode version and have the upgrader do the right thing (and do that before releasing llvm 6.0, making this question fairly urgent).
My opinion is we should.
From: llvm-dev [mailto:llvm-dev-bounces at lists.llvm.org] On Behalf Of Quentin Colombet via llvm-dev
Sent: Friday, February 9, 2018 11:07 AM
To: Matthias Braun
Subject: Re: [llvm-dev] [RFC] Should we bump the bitcode version in LLVM 6.0?
Agree, but that wouldn’t solve the downgrade problem plus this is probably too late to fix LLVM 6.0 for all the isFast uses.
On Feb 9, 2018, at 10:05 AM, Matthias Braun <mbraun at apple.com<mailto:mbraun at apple.com>> wrote:
Just wanted to point out part of this even becoming a problem is the use of `isFast()`.
There should be warnings against using isFast() and the existing code should be changed to query specific flags instead...
On Feb 8, 2018, at 5:34 PM, Quentin Colombet via llvm-dev <llvm-dev at lists.llvm.org<mailto:llvm-dev at lists.llvm.org>> wrote:
r317488 changed the way fast math flags are laid out in the bitcode and anyone compiling a pre-llvm-6.0 bitcode with llvm-6.0 will lose all the optimizations guarded by isFast and a pre-llvm-6.0 compiler compiling a llvm-6.0 bitcode will potentially generate incorrect code w.r.t. fast math expectations.
Should we bump the bitcode version because of that and have the autoupgrader properly rewrite the fast-math to preserve that semantic?
(I believe we should!)
* Context *
With https://reviews.llvm.org/D39304 / r317488 we got rid of the umbrella UnsafeMath flag and introduced 3 more flags that better represent the different things that happen under fast-math.
From a bitcode perspective, this change looks like this:
Before r317488 we had 6 bits that respectively represented:
(The order may not match what is exactly in the bitcode.)
After r317488 we had 7 bits that respectively represented:
reassoc (-UnsafeMath- is gone)
*afn* (new bit)
Before r317488, fast-math was true if UnsafeMath was true (this should also imply all the other flags are sets). After r317488, fast-math is true if all the bits are set, in particular the afn, new one, too.
* Problem *
Given we currently have no way to check if a bitcode file has been generated pre-r317488 or post-r317488 that means that:
1. a post-r317488 compiler is going to skip any optimization guarded by isFast for all pre-r317488 bitcode file (remember the afn bit is not set here)
2. a pre-r317488 compiler is going to run any optimization guarded by unsafeAlgebra for any post-r317488 bitcode file that has the reassoc bit (remember we repurposed UnsafeMath)
Scenario #2 might be unlikely but we’re potentially breaking the semantic of the program. It is particularly dangerous because there is nothing that is going to tell us that we are in this situation “downgrade" situation.
#1 means that any code that uses unsafeMath is going to get a performance hit.
In other words, one scenario implies generating wrong code and the other, runtime performance regressions.
* Feedback Needed *
I believe this change is big enough that it would be worth bumping the bitcode version so that the upgrader can do the right thing *before* we release it to the public with LLVM-6.0.
That being said, I don’t know what are the implications of such bump and if people really don’t care about the performance problem that might be okay. The silent downgrade path is however concerning.
Should we bump the bitcode version because of that change and have the autoupgrader properly rewrite the fast-math flags to
preserve the semantic and make sure there are no silent downgrade?
LLVM Developers mailing list
llvm-dev at lists.llvm.org<mailto:llvm-dev at lists.llvm.org>
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the llvm-dev