llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

[AMDGPU] HIP miscompilation bug triggered by si-fold-operands

Open mgcarrasco opened this issue 8 months ago • 1 comments

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:

  1. clang++ -O0 -x hip HIPProg.hip -I<headers_dir> -Wno-c++11-narrowing --offload-arch=gfx90a -o O0.out
  2. clang++ -O1 -x hip HIPProg.hip -I<headers_dir> -Wno-c++11-narrowing --offload-arch=gfx90a -o O1.out
  3. ./O0.out
  4. ./O1.out
  5. 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.

mgcarrasco avatar Mar 31 '26 14:03 mgcarrasco

@llvm/issue-subscribers-backend-amdgpu

Author: Manuel Carrasco (mgcarrasco)

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 submitted test comes from fuzzing and has been generated by @ElliotBLabs. I've been helping in debugging it.

Test files:

How to reproduce:

  1. clang++ -O0 -x hip HIPProg.hip -I&lt;headers_dir&gt; -Wno-c++11-narrowing --offload-arch=gfx90a -o O0.out
  2. clang++ -O1 -x hip HIPProg.hip -I&lt;headers_dir&gt; -Wno-c++11-narrowing --offload-arch=gfx90a -o O1.out
  3. ./O0.out
  4. ./O1.out

Analysis:

The root of the divergence starts after this statement *bl |= safe_add_func_int64_t_s_s(*bg-&gt;am &lt; 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.

llvmbot avatar Mar 31 '26 14:03 llvmbot