This is an archive of the discontinued LLVM Phabricator instance.

[RISCV] Don't allow vector types to be used with inline asm 'r' constraint
ClosedPublic

Authored by craig.topper on Dec 15 2021, 10:58 AM.

Details

Summary

The 'r' constraint uses the GPR class. There is generic support
for bitcasting and extending/truncating non-integer VTs to the
required integer VT. This doesn't work for scalable vectors and
instead crashes.

To prevent this, explicitly reject vectors. Fixed vectors might
work without crashing, but it doesn't seem worthwhile to allow.

While there remove an unnecessary level of indentation in the
"vr" and "vm" constraint handling.

Diff Detail

Event Timeline

craig.topper created this revision.Dec 15 2021, 10:58 AM
craig.topper requested review of this revision.Dec 15 2021, 10:58 AM
Herald added a project: Restricted Project. · View Herald TranscriptDec 15 2021, 10:58 AM
Herald added a subscriber: MaskRay. · View Herald Transcript
jrtc27 added inline comments.Dec 15 2021, 11:01 AM
llvm/lib/Target/RISCV/RISCVISelLowering.cpp
9663
if (VT.isVector())
  break;

is a bit more extensible in that line lengths don't get stupidly long as the list grows; we exclude our own register class from r downstream like that.

I imagine fixed vectors will need to be allowed for P here, FWIW

craig.topper added inline comments.Dec 15 2021, 11:09 AM
llvm/lib/Target/RISCV/RISCVISelLowering.cpp
9665

While I'm here. This should be Zfhmin right?

jrtc27 added inline comments.Dec 15 2021, 11:11 AM
llvm/lib/Target/RISCV/RISCVISelLowering.cpp
9665

Yeah

Address @jrtc's feedback. Add FIXME for P extension.

I thought about allowing fixed vectors, but if it is larger than XLen it creates multiple registers. So needs more care.

jrtc27 accepted this revision.Dec 23 2021, 1:11 PM

Though please alter the commit message to mention that the vr/vm changes are NFC cleanup to remove an unnecessary level of indentation, or words to that effect (assuming my understanding is correct)

This revision is now accepted and ready to land.Dec 23 2021, 1:11 PM
craig.topper edited the summary of this revision. (Show Details)Dec 23 2021, 1:18 PM
jrtc27 added inline comments.Dec 23 2021, 2:01 PM
llvm/test/CodeGen/RISCV/inline-asm-invalid.ll
39

Something weird happened here

Yeah I saw it when I reapplied the patch to test before committing. I’ll fix.

This revision was landed with ongoing or failed builds.Dec 23 2021, 6:46 PM
This revision was automatically updated to reflect the committed changes.