[AMDGPU] HIP miscompilation bug triggered by si-fold-operands
The following HIP test triggers a miscompilation bug. The test computes and prints a single deterministic value. It is free of UB so no divergence is allowed to happen when optimizations are enabled. The bug manifests by enabling optimizations which cause a divergence in the printed value. The error manifests in commit https://github.com/llvm/llvm-project/commit/b6d7afe53465517ed944a43165b6885fab460c4e.
The submitted test comes from fuzzing and has been generated by @ElliotBLabs. I've been helping in debugging it.
Test files:
How to reproduce:
clang++ -O0 -x hip HIPProg.hip -I<headers_dir> -Wno-c++11-narrowing --offload-arch=gfx90a -o O0.outclang++ -O1 -x hip HIPProg.hip -I<headers_dir> -Wno-c++11-narrowing --offload-arch=gfx90a -o O1.out./O0.out./O1.out- Compare output values
Analysis:
The root of the divergence starts after this statement *bl |= safe_add_func_int64_t_s_s(*bg->am < 3, -8L) ;. bl has a different value depending on the optimization flags.
After some further reduction at the IR level, this is the bitcode that triggers the bug. --opt-bisect-limit points to si-fold-operands as the likely optimization that introduces the bug.
@llvm/issue-subscribers-backend-amdgpu
Author: Manuel Carrasco (mgcarrasco)
The submitted test comes from fuzzing and has been generated by @ElliotBLabs. I've been helping in debugging it.
Test files:
How to reproduce:
clang++ -O0 -x hip HIPProg.hip -I<headers_dir> -Wno-c++11-narrowing --offload-arch=gfx90a -o O0.outclang++ -O1 -x hip HIPProg.hip -I<headers_dir> -Wno-c++11-narrowing --offload-arch=gfx90a -o O1.out./O0.out./O1.out
Analysis:
The root of the divergence starts after this statement *bl |= safe_add_func_int64_t_s_s(*bg->am < 3, -8L) ;. bl has a different value depending on the optimization flags.
After some further reduction at the IR level, this is the bitcode that triggers the bug. --opt-bisect-limit points to si-fold-operand as the likely optimization that introduces the bug.