This is an archive of the discontinued LLVM Phabricator instance.

[AMDGPU] Fix handling of void types in isLegalAddressingMode
ClosedPublic

Authored by rampitec on Nov 23 2017, 3:23 PM.

Details

Summary

It is legal for the type passed to isLegalAddressingMode to be unsized or, more specifically, VoidTy. In this case, we must check the legality of load / stores for all legal types. Directly trying to call getTypeStoreSize is incorrect, and leads to breakage in e.g. Loop Strength Reduction. This change guards against that behaviour.

Diff Detail

Repository
rL LLVM

Event Timeline

AlexVlx created this revision.Nov 23 2017, 3:23 PM
arsenm edited edge metadata.Nov 27 2017, 10:09 AM

Needs test

rampitec added inline comments.May 15 2018, 2:10 PM
lib/Target/AMDGPU/SIISelLowering.cpp
679 ↗(On Diff #124117)

I would prefer to exit earlier than this. It is not address space specific and we hardly can do anything good on a void or opaque type.

rampitec added inline comments.May 15 2018, 2:25 PM
lib/Target/AMDGPU/SIISelLowering.cpp
679 ↗(On Diff #124117)

... but then it crashes another couple of tests. We seems to be required to process that LSR formulae.

I believe that we need to behave as is LegalAddressingMode is supposed to behave in general(see 469 in TargetTransformInfo.h):

/// Return true if the addressing mode represented by AM is legal for
/// this target, for a load/store of the specified type.
/// The type may be VoidTy, in which case only return true if the addressing
/// mode is legal for a load/store of any legal type.
/// If target returns true in LSRWithInstrQueries(), I may be valid.

When I looked at it, it was the case that VoidTy is essentially a tag type in this case. Other targets such as AArch64 also acknowledge that an unsized type may be passed through all the way to isLegalAddressingMode.

rampitec commandeered this revision.May 15 2018, 2:58 PM
rampitec updated this revision to Diff 146925.
rampitec edited reviewers, added: AlexVlx; removed: rampitec.
rampitec marked 2 inline comments as done.
rampitec retitled this revision from Fix incorrect handling of unsized / void types in SITargetLowering::isLegalAddressingMode to [AMDGPU] Fix handling of void types in isLegalAddressingMode.

Added test.

LGTM - thank you!

AlexVlx accepted this revision.May 15 2018, 3:10 PM
This revision is now accepted and ready to land.May 15 2018, 3:10 PM
This revision was automatically updated to reflect the committed changes.

Test should go in test/LoopStrengthReduce/AMDGPU and run just LSR

Test should go in test/LoopStrengthReduce/AMDGPU and run just LSR

I can move the test, but I cannot reproduce the bug with opt.

Test should go in test/LoopStrengthReduce/AMDGPU and run just LSR

I can move the test, but I cannot reproduce the bug with opt.

https://reviews.llvm.org/rL332562

Test should go in test/LoopStrengthReduce/AMDGPU and run just LSR

I can move the test, but I cannot reproduce the bug with opt.

You should only change the test if the original problem shows up. You should be able to coax it into failing with just opt though (maybe you need to run more passes before LSR on it?)

Test should go in test/LoopStrengthReduce/AMDGPU and run just LSR

I can move the test, but I cannot reproduce the bug with opt.

You should only change the test if the original problem shows up. You should be able to coax it into failing with just opt though (maybe you need to run more passes before LSR on it?)

Test is not changed, just moved. Note that many of our lsr tests there use llc to run. I was unable to make it reproducible with opt given any pass set. If one wants to run it with opt it will probably require a different test.