This is an archive of the discontinued LLVM Phabricator instance.

[AMDGPU] Fix crash with 160-bit p7's by manually defining getPointerTy
ClosedPublic

Authored by krzysz00 on May 5 2023, 3:14 PM.

Details

Summary

While pointers in address space 7 (128 bit rsrc + 32 bit offset)
should be rewritten out of the code before IR translation on AMDGPU,
higher-level analyses may still call MVT getPointerTy() and the like
on the target machine. Currently, since there is no MVT::i160, this
operation ends up causing crashes.

The changes to the data layout that caused such crashes were D149776.

This patch causes getPointerTy() to return the type MVT::v5i32
and getPointerMemTy() to be MVT::v8i32. These are accurate types,
but mean that we can't use vectors of address space 7 pointers during
codegen. This is mostly OK, since vectors of buffers aren't supported
in LPC anyway, but it's a noticable limitation.

Potential alternative solutions include adjusting getPointerTy() to return
an EVT or adding MVT::i160 and MVT::i256, both of which are rather
disruptive to the rest of the compiler.

Diff Detail

Event Timeline

krzysz00 created this revision.May 5 2023, 3:14 PM
Herald added a project: Restricted Project. · View Herald TranscriptMay 5 2023, 3:14 PM
krzysz00 requested review of this revision.May 5 2023, 3:14 PM
Herald added a project: Restricted Project. · View Herald TranscriptMay 5 2023, 3:14 PM
arsenm added a comment.May 6 2023, 1:10 AM

Can you just use v5i32

llvm/test/Transforms/IndVarSimplify/AMDGPU/addrspace-7-doesnt-crash.ll
26

Better to have a test with a non foldable branch

krzysz00 updated this revision to Diff 520400.May 8 2023, 8:45 AM
krzysz00 edited the summary of this revision. (Show Details)

Move to MVT::v5i32, sacrificing the ability to handle vectors of p7 in codegen but being more correct otherwise.

The problem with using v5i32 as the MVT is that you get an inevitable crash when you getValueType() on a vector of p7's per https://github.com/llvm/llvm-project/blob/main/llvm/include/llvm/CodeGen/TargetLowering.h#L1520

Which ... having looked, could well be fine

It also would not be difficult to just define i160. It should be easier than ever now that MVT is generated

@arsenm Given that, from what I can tell, MVT is the type for "things some architecture somewhere needed for codegen", I was somewhat concerned that adding MVT::i160 might break legalization or something.

But I would prefer to go that route if it's something you think everyone'll be OK with

arsenm added a comment.May 9 2023, 9:34 AM

@arsenm Given that, from what I can tell, MVT is the type for "things some architecture somewhere needed for codegen", I was somewhat concerned that adding MVT::i160 might break legalization or something.

I doubt it will break anything. Most everything looks for next-power-of-2 and wouldn't see it

I went looking and ran into, for example, TargetLoweringBase::computeRegisterProperties, which assumes the MVT integers all double in size.

krzysz00 added a comment.EditedMay 9 2023, 10:34 AM

We could probably special-case around it, but ... for temporarily un-breaking higher-level analyses that end up looking at TargetTransformInfo, we can probably either go for the vector type or lie.

... though, we could also hack in support for 2x5xi32 -> 10xi32 type transformations.

piotr added a subscriber: piotr.May 10 2023, 3:57 AM

Ping to land this because there's active breakage? @foad @arsenm

arichardson added inline comments.May 11 2023, 9:05 AM
llvm/lib/Target/AMDGPU/SIISelLowering.cpp
982

Comment needs updating for the v5 change

krzysz00 updated this revision to Diff 521349.May 11 2023, 9:38 AM

Update comment fon the new approach

Confirmed that this fixes the issues we were observing.

foad accepted this revision.May 12 2023, 2:22 AM

Ping to land this because there's active breakage? @foad @arsenm

Yes please land this.

llvm/lib/Target/AMDGPU/SIISelLowering.cpp
990

Nit: why do you need the getPointerSizeInBits test?

This revision is now accepted and ready to land.May 12 2023, 2:22 AM
foad added inline comments.May 12 2023, 2:23 AM
llvm/test/CodeGen/AMDGPU/GlobalISel/irtranslator-non-integral-address-spaces-vectors.ll
4

Nit: you're not actually checking anything.

krzysz00 updated this revision to Diff 521671.May 12 2023, 8:57 AM
krzysz00 marked an inline comment as done.

Update checks, coments, remase

This revision was landed with ongoing or failed builds.May 12 2023, 8:58 AM
This revision was automatically updated to reflect the committed changes.
foad added inline comments.May 12 2023, 9:36 AM
llvm/lib/Target/AMDGPU/SIISelLowering.cpp
990

I mean why do you need it at all? Don't we know statically that the size of BUFFER_FAT_POINTER is 160 bits?

krzysz00 added inline comments.May 12 2023, 9:49 AM
llvm/lib/Target/AMDGPU/SIISelLowering.cpp
990

Paranoia around making sure this isn't an old data layout or the like. I might even want to make the check more precise.

990

I was concerned that, for example, auto-upgrade might not fire or that you'd otherwise end up in a position where p7 doesn't have its usual definition and so thought to go ahead and check.

I went looking and ran into, for example, TargetLoweringBase::computeRegisterProperties, which assumes the MVT integers all double in size.

Just add it and see it anything breaks

llvm/lib/Target/AMDGPU/SIISelLowering.cpp
990

Just drop it, there's no reason to try defending against that here

dyung added a subscriber: dyung.May 12 2023, 7:06 PM

Just a heads up that we noticed in our internal testing that llvm/test/CodeGen/AMDGPU/GlobalISel/irtranslator-non-integral-address-spaces-vectors.ll failed in a release build without assertions because it is looking for a crash that is caused by an assertion failure. I've added that requirement to the test in 97b73e3.