-
Notifications
You must be signed in to change notification settings - Fork 262
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
[BUG] NDK r25c clang generates invalid code/crashes when optimizing for size (-Os) #1862
Comments
I managed to creduce compiler crash to get following example: int a, c, d;
long b[1];
void e() {
int f = c;
int *g;
long *h;
g = &a;
h = b;
for (; d; d++)
*h++ = f * (long)*g++;
}
int main() {} Slight modifying the testing script https://github.com/SanjaLV/NDK_r25c_repro/blob/master/test_crash.sh |
I'm able to repro this bug with:
|
https://android-review.googlesource.com/c/toolchain/llvm_android/+/2259912 has a bunch of patches related to vector instructions. This is the likely cause of the bug. I'm still investigating the root cause. |
Confirmed, I reproduced crash with -Os. Thank you for report! I will look for the reason. |
Thanks for taking a look at it. I can confirm that reverting: https://android-review.googlesource.com/c/toolchain/llvm_android/+/2259912/3/patches/cherry/Loop-Vectorizer-shouldMaximizeVectorBandwidth.patch fixes the crash although it might introduce regressions I assume? |
Error caused by "Set maximum VF with shouldMaximizeVectorBandwidth" patch ( https://android-review.googlesource.com/c/toolchain/llvm_android/+/2259912/3/patches/cherry/Loop-Vectorizer-shouldMaximizeVectorBandwidth.patch ). Figuring out the fix. |
You were first 😄 Yes, it is a performance patch and removing it would cause regressions. |
Does the crash still exist in newer LLVMs? |
It doesn't repro on newer Clang. I think that this might just be an issue with the batch of vectorization patches possibly missing something. |
Okay, so we just need a new clang for r26 (I think I saw the fix for the previous blocker go in, so we're maybe just waiting for new prebuilts?), since it doesn't sound like there's going to be bandwidth for you folks to support both an r25d toolchain and r26 development. If that's wrong lmk and I'll retriage. |
Hello,
The previous Uniforms[VF] is used again and it causes wrong cost of load instruction with
After applying below patch to ndk r25c clang, I can see the error is gone.
|
If we end up making another r25 release we'll do that, but I don't think that's happening. |
Description
Android NDK r25c produces invalid code (and crashes if we mark certain functions as
noinline
) for arm64-v8a target architecture when compiling with-Os
(optimize size) compiler flag.Bellow is attached minimized/striped sample that shows the problem (it uses functions from libtomcrypt).
Link to the repo repository: https://github.com/SanjaLV/NDK_r25c_repro
Prerequisites:
"ndk;25.2.9519653"
/"ndk;25.1.8937393"
installed in sdkmanagerHow to reproduce (invalid code):
test_manual.sh
REMOTE_0s_LOG.txt
differs fromREMOVE_02_LOG.txt
How to reproduce (compiler crash):
REPRO.c
in the editor of your choice#define MAKE_COMPILER_CRASH 1
test_manual.sh
-0s
Crash backtrace should look like:
Context:
Originally discovered that upgrading NDK from version r25b to r25c changes return values of certain cryptographic functions. After some investigations, we found that the first function where the return value changes with NDK r25c was
mp_montgomery_reduce
. Then we minimized the code by fixing the input argument tomp_montgomery_reduce
. (These values are not unique any valid random values will work too, as long asP
is odd).We tried to compare generated assembly, but clangs inlines the majority of the calls, so that complicates the investigation, thus we tried to apply
noinline
attribute. Which resulted in a compiler crash during Loop vectorization.Comparing
clang_source_info.md
of both NDK, I can spot a few patches regarding arm64 vectorization:I don't have access to patches, thus cannot verify this hypothesis. Clang with debug asserts enabled might also provide additional information, but I don't know how to build NDK clang.
Feel free to ask for more information.
Many thanks,
Aleksandrs
Affected versions
r25
Canary version
No response
Host OS
Linux, Mac
Host OS version
Ubuntu 22.04
Affected ABIs
arm64-v8a
Build system
ndk-build
Other build system
No response
minSdkVersion
31 (not relevant)
Device API level
27
The text was updated successfully, but these errors were encountered: