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

AMDGPU backend: range is set incorrectly for mbcnt instructions

Open Venemo opened this issue 4 years ago • 11 comments

According to the GCN / RDNA ISA documentation, the v_mbcnt_lo and v_mbcnt_hi instructions can have a source which is added to the result. The LLVM AMDGPU backend disregards this and always sets the range of these instructions as if their upper bound was the wave size, however this is incorrect when the addition is used because it can then exceed this range.

The problematic line of code is this: https://github.com/llvm/llvm-project/blob/25af3af/llvm/lib/Target/AMDGPU/AMDGPUISelLowering.cpp#L4601

This causes false assumptions when the instruction is used with arbitrary addition, resulting in buggy code being compiled.

Venemo avatar May 19 '22 21:05 Venemo

@llvm/issue-subscribers-backend-amdgpu

llvmbot avatar May 19 '22 21:05 llvmbot

Caused by https://reviews.llvm.org/D39951

jayfoad avatar May 20 '22 07:05 jayfoad

I took a look at this - see https://reviews.llvm.org/D131478

dstutt avatar Aug 09 '22 16:08 dstutt

Fixed in https://reviews.llvm.org/D131478

dstutt avatar Aug 11 '22 12:08 dstutt

Can you say which version of LLVM will have this fix?

Venemo avatar Aug 11 '22 17:08 Venemo

(Sorry for delayed response - been on vacation)

I'm trying to get a backport to the llvm 15 release.

dstutt avatar Aug 23 '22 09:08 dstutt

If not for llvm 15, then it'll be in the next release.

dstutt avatar Aug 23 '22 09:08 dstutt

Thanks. Please let me know when you know for sure. (As a workaround we emit an extra add instruction now, but I'd like to remove that workaround for the first LLVM version which doesn't need it.)

Venemo avatar Aug 23 '22 11:08 Venemo

The change should be in 15.0.1 See https://github.com/llvm/llvm-project-release-prs/pull/124 and https://github.com/llvm/llvm-project/issues/57295

dstutt avatar Sep 07 '22 08:09 dstutt

Ouch. Sad to see it didn't make it into 15.0.0 :(

Venemo avatar Sep 07 '22 10:09 Venemo

Thanks for the fix and thanks for letting me know it will be usable in 15.0.1 at least.

Venemo avatar Sep 07 '22 10:09 Venemo