This is an archive of the discontinued LLVM Phabricator instance.

[RISCV] Pattern-match more vector-splatted constants
ClosedPublic

Authored by frasercrmck on Dec 27 2020, 6:45 AM.

Details

Summary

This patch extends the pattern-matching capability of vector-splatted
constants. When illegally-typed constants are legalized they are
canonically sign-extended to XLenVT. This preserves the sign and allows
us to match simm5. If they were zero-extended for whatever reason we'd
lose that ability: e.g. (i8 -1) -> (XLenVT 255) would not be matched
under the current logic.

To address this we first manually sign-extend the splatted constant from
the vector element type to int64_t. This preserves the semantics while
removing any implicitly-truncated bits.

The corresponding logic for uimm5 was not updated, the rationale being
that neither sign- nor zero-extending a legal uimm5 immediate should
change that (unless we expect actual "garbage" upper bits).

Diff Detail

Event Timeline

frasercrmck created this revision.Dec 27 2020, 6:45 AM
frasercrmck requested review of this revision.Dec 27 2020, 6:45 AM
Herald added a project: Restricted Project. · View Herald TranscriptDec 27 2020, 6:45 AM
craig.topper added inline comments.Dec 27 2020, 11:33 AM
llvm/lib/Target/RISCV/RISCVISelDAGToDAG.cpp
463

Can we use SignExtend64 from MathExtras.h here?

  • use math helper
frasercrmck marked an inline comment as done.Dec 27 2020, 11:54 AM
frasercrmck added inline comments.
llvm/lib/Target/RISCV/RISCVISelDAGToDAG.cpp
463

Yes, thanks. For some reason I thought there was only the templated one.

craig.topper accepted this revision.Dec 27 2020, 8:36 PM

LGTM with that one comment.

llvm/lib/Target/RISCV/RISCVISelDAGToDAG.cpp
463

EltVT is already a scalar right? So we should just need getSizeInBits().

This revision is now accepted and ready to land.Dec 27 2020, 8:36 PM
This revision was automatically updated to reflect the committed changes.
frasercrmck marked an inline comment as done.