This is an archive of the discontinued LLVM Phabricator instance.

[RISCV] Use vfslide1down for build_vectors of non-constant floats
ClosedPublic

Authored by reames on May 24 2023, 9:57 AM.

Details

Summary

This adds the vfslide1down (and vfslide1up for consistency) nodes. These mostly parallel the existing vslide1down/up nodes. (See note below on instruction semantics.) We then use the vfslide1down in build_vector lowering instead of going through the stack.

The specification is more than a bit vague on the meaning of these instructions. All we're given is "The vfslide1down instruction is defined analogously, but sources its scalar argument from an f register.". The challenge comes from the fact that vslide1down has truncation and sign extension defined in terms of XLEN. This seems unlikely to be correct for a floating point op, so I'm assuming that should be FLEN on the floating point version. If true, then all legal types fall into the truncation case, and we don't have to figure out what the analogous floating point operation to sign extension is for the FLEN < SEW case.

I'll note that V doesn't have any issue here since V implies F and D. Zve64f could potentially have a problem, but I wasn't able to write a test case which got here since f64 was not a legal type and we scalarized/split before lowering the build_vector.

Diff Detail

Event Timeline

reames created this revision.May 24 2023, 9:57 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 24 2023, 9:57 AM
reames requested review of this revision.May 24 2023, 9:57 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 24 2023, 9:57 AM

There's a general note at the beginning of section 10. Vector Arithmetic Instruction Formats

For floating-point operations, the scalar can be taken from a scalar f register. If FLEN > SEW, the value in the f registers is checked for a valid NaN-boxed value, in which case the least-signicant SEW bits of the f register are used, else the canonical NaN value is used. Vector instructions where any floating-point vector operand’s EEW is not a supported floating-point type width (which includes when FLEN < SEW) are reserved.
craig.topper added inline comments.May 24 2023, 10:07 AM
llvm/lib/Target/RISCV/RISCVISelLowering.h
168

It's not an FLen scalar is it? It should be a scalar with the same element type as the vector operand.

llvm/lib/Target/RISCV/RISCVInstrInfoVVLPatterns.td
2461

I think SDTCisFP<3> can be replaced with SDTCisEltOfVec<3, 0> for a stronger guarantee.

reames updated this revision to Diff 525249.May 24 2023, 10:26 AM

Address review comments

This revision is now accepted and ready to land.May 24 2023, 10:34 AM
This revision was landed with ongoing or failed builds.May 24 2023, 10:48 AM
This revision was automatically updated to reflect the committed changes.