This is an archive of the discontinued LLVM Phabricator instance.

[AMDGPU] Handle SMRD signed offset immediate
ClosedPublic

Authored by kerbowa on Mar 30 2020, 12:26 PM.

Details

Summary

This fixes a few issues related to SMRD offsets. On gfx9 and gfx10 we have a
signed byte offset immediate, however we can overflow into a negative since we
treat it as unsigned.

Also, the SMRD SOFFSET sgpr is an unsigned offset on all subtargets. We
sometimes tried to use negative values here.

Third, S_BUFFER instructions should never use a signed offset immediate.

Diff Detail

Event Timeline

kerbowa created this revision.Mar 30 2020, 12:26 PM
Herald added a project: Restricted Project. · View Herald TranscriptMar 30 2020, 12:26 PM

Please follow lint recommendations on formatting.

llvm/lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.cpp
1275–1281

Should we instead pass here Subtarget and distinguish if it has needed mode right in this function?

arsenm added inline comments.Mar 30 2020, 3:19 PM
llvm/lib/Target/AMDGPU/AMDGPUISelDAGToDAG.cpp
1788

Should this just rely on getSMRDEncodedSignedOffset failing based on the subtarget?

kerbowa added inline comments.Mar 30 2020, 3:45 PM
llvm/lib/Target/AMDGPU/AMDGPUISelDAGToDAG.cpp
1788

Sure, I'm just following what's done for the LiteralOffset below but that could be improved in the same way.

llvm/lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.cpp
1275–1281

In that case we would also need to pass something to determine whether it's for S_BUFF since there is no signed offset there.

rampitec added inline comments.Mar 30 2020, 3:53 PM
llvm/lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.cpp
1275–1281

Ah, right.

kerbowa updated this revision to Diff 254107.Apr 1 2020, 1:30 AM

Address comments.

arsenm added inline comments.Apr 1 2020, 9:44 AM
llvm/lib/Target/AMDGPU/AMDGPUISelDAGToDAG.cpp
1788–1789

Typo amd

1798–1805

The GlobalISel patch seems to be missing this part?

llvm/lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.h
650

Ugh, is this really different between the buffer and non-buffer forms?

kerbowa added inline comments.Apr 1 2020, 10:13 AM
llvm/lib/Target/AMDGPU/AMDGPUISelDAGToDAG.cpp
1798–1805

I think it's handled here?

AMDGPUInstructionSelector.cpp:2876
if (!GEPInfo.Imm || GEPInfo.Imm < 0 || !isUInt<32>(GEPInfo.Imm))

llvm/lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.h
650

Apparently, yes. An alternative would be to disallow negative offsets entirely.

arsenm added inline comments.Apr 1 2020, 11:52 AM
llvm/lib/Target/AMDGPU/AMDGPUISelDAGToDAG.cpp
1798–1805

OK, the use of SignBitIsZero is confusing when it's a known constant. This should also directly check the immediate value

kerbowa updated this revision to Diff 254628.Apr 2 2020, 2:55 PM

Directly check the immediate value.

kerbowa marked 2 inline comments as done.Apr 2 2020, 2:57 PM
arsenm accepted this revision.Apr 2 2020, 3:48 PM

LGTM, but would like the same comments copied into the GlobalISel part

llvm/lib/Target/AMDGPU/AMDGPUInstructionSelector.cpp
2876–2877

Should copy the comment here about the unsigned distinction for the immediate

This revision is now accepted and ready to land.Apr 2 2020, 3:48 PM
This revision was automatically updated to reflect the committed changes.