This is an archive of the discontinued LLVM Phabricator instance.

[RISCV] Lower splats of non-constant i1s as SETCCs
ClosedPublic

Authored by frasercrmck on Apr 28 2021, 8:23 AM.

Details

Summary

This patch adds support for splatting i1 types to fixed-length or
scalable vector types. It does so by lowering the operation to a SETCC
of the equivalent i8 type.

Diff Detail

Event Timeline

frasercrmck created this revision.Apr 28 2021, 8:23 AM
frasercrmck requested review of this revision.Apr 28 2021, 8:23 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 28 2021, 8:23 AM
frasercrmck added inline comments.Apr 28 2021, 8:26 AM
llvm/test/CodeGen/RISCV/rvv/vsplats-i1.ll
167

I was wondering if vmv.v.i v26, 0 ; vmsne.vx v0, v26, a0 would be faster. Any insights there?

craig.topper added inline comments.Apr 28 2021, 10:06 AM
llvm/lib/Target/RISCV/RISCVISelLowering.cpp
1365

Don't we need to mask out all but bit 0 of Splat? I don't think those bits are defined.

frasercrmck added inline comments.Apr 29 2021, 1:38 AM
llvm/lib/Target/RISCV/RISCVISelLowering.cpp
1365

Yeah I think you're right. I was going by the "zero or one" boolean contents contract which I thought covered us when the i1s were widened to XLEN but, thinking about it, that probably doesn't cover the operands of BUILD_VECTOR or SPLAT_VECTOR. Right?

craig.topper added inline comments.Apr 29 2021, 7:57 AM
llvm/lib/Target/RISCV/RISCVISelLowering.cpp
1365

It applies to the output of SETCC or the expectations of SELECT. But the i1 could have been produced by a TRUNCATE for example in which case it wouldn't have to respect boolean contents.

DAG combine should be able to delete the AND if the input came from SETCC, though X86 detects that case directly in lowering. See LowerBUILD_VECTORvXi1 right around the FIXME comment in that function.

frasercrmck added inline comments.Apr 29 2021, 7:59 AM
llvm/lib/Target/RISCV/RISCVISelLowering.cpp
1365

Yeah, makes sense. I was hoping to hear something like that. I added a couple of tests such as i1 zeroext and where the i1 comes from an icmp and I verified that those are correctly optimized. You should be able to see those further down somewhere.

craig.topper added inline comments.Apr 30 2021, 3:56 PM
llvm/lib/Target/RISCV/RISCVISelLowering.cpp
1365

Your last comment make it sound like you uploaded another patch, but I only see one patch in the history.

frasercrmck marked an inline comment as done.
  • rebase
  • add explicit truncation of splatted value down to one bit
llvm/lib/Target/RISCV/RISCVISelLowering.cpp
1365

Oh dear yeah I forgot to upload the latest diff. Thanks!

This revision is now accepted and ready to land.May 3 2021, 10:10 AM
This revision was automatically updated to reflect the committed changes.