This is an archive of the discontinued LLVM Phabricator instance.

[SelectionDAG][RISCV] Don't unroll 0/1-type bool VSELECTs
ClosedPublic

Authored by frasercrmck on May 26 2021, 3:28 AM.

Details

Summary

This patch extends the cases in which the legalizer is able to express
VSELECT in terms of XOR/AND/OR. When dealing with a VSELECT between
boolean vector types, the mask itself is an all-ones or all-ones value
of the operand type, so a 0/1 boolean type behaves identically to a 0/-1
type.

This greatly helps RISC-V which relies on expansion for these nodes. It
also allows scalable-vector bool VSELECTs to use the default expansion,
where before it would crash in SelectionDAG::UnrollVectorOp.

Diff Detail

Event Timeline

frasercrmck created this revision.May 26 2021, 3:28 AM
frasercrmck requested review of this revision.May 26 2021, 3:28 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 26 2021, 3:28 AM
  • fix checking type of incorrect vselect operand
craig.topper added inline comments.May 26 2021, 9:41 AM
llvm/lib/CodeGen/SelectionDAG/LegalizeVectorOps.cpp
1192

I wonder if this would be better as

if (BoolContents != TargetLowering::ZeroOrNegativeOneBooleanContent &&
     !(BoolContents == TargetLowering::ZeroOrOneBooleanContent && Op1.getValueType().getVectorElementType() != MVT::i1)

That way if some new boolean contents type gets added, only the values that are known to work get through.

  • address feedback
  • rebase on top of RVV test changes
frasercrmck marked an inline comment as done.May 26 2021, 9:48 AM
frasercrmck added inline comments.
llvm/lib/CodeGen/SelectionDAG/LegalizeVectorOps.cpp
1192

Yep that's a good idea, thanks. Though the != MVT::i1 should be == unless I'm mistaken.

craig.topper added inline comments.May 26 2021, 9:49 AM
llvm/lib/CodeGen/SelectionDAG/LegalizeVectorOps.cpp
1192

You're correct. I knew when I wrote that, I was going to mess up a ! somewhere.

frasercrmck marked 2 inline comments as done.May 26 2021, 10:00 AM
frasercrmck added inline comments.
llvm/lib/CodeGen/SelectionDAG/LegalizeVectorOps.cpp
1192

Tell me about it...

This revision is now accepted and ready to land.May 26 2021, 12:04 PM
This revision was automatically updated to reflect the committed changes.
frasercrmck marked an inline comment as done.
llvm/lib/Target/RISCV/RISCVISelLowering.cpp