This is an archive of the discontinued LLVM Phabricator instance.

[RISCV][CodeGen] Account for LMUL from VS2 for Vector Reduction Instructions
ClosedPublic

Authored by monkchiang on Jan 11 2023, 9:23 PM.

Details

Summary

The Reduction instruction destination register LMUL is 1. But the source
register(vs2) has different LMUL(MF8 to M8). It's beneficial to know how
many registers are working on reduction instructions.
This patch creates separate SchedWrite for each relevant LMUL that from VS2.

Diff Detail

Event Timeline

monkchiang created this revision.Jan 11 2023, 9:23 PM
Herald added a project: Restricted Project. · View Herald TranscriptJan 11 2023, 9:23 PM
monkchiang requested review of this revision.Jan 11 2023, 9:23 PM
michaelmaitland added a comment.EditedJan 12 2023, 12:16 PM

Does it make sense to change the SchedReadss and ReadAdvance to be LMUL specific for this class of instuctions?

llvm/lib/Target/RISCV/RISCVInstrInfoV.td
728–729

Other LMUL specific SchedWrites use the suffix UpperBound. Is there a difference in meaning between UpperBound and From_UpperBound?

llvm/lib/Target/RISCV/RISCVInstrInfoVPseudos.td
3303–3304

Other LMUL specific SchedWrites use the suffix MX. Is there a difference in meaning between MX and From_MX?

llvm/lib/Target/RISCV/RISCVScheduleV.td
755

VFW prefix should use LMULWriteResFW class.

Does it make sense to change the SchedReadss and ReadAdvance to be LMUL specific for this class of instuctions?

It is helpful to describe the forwarding behavior. In order to simplify the design,
I think that the description Latency and ResourceCycles are all done in WriteRes.

llvm/lib/Target/RISCV/RISCVInstrInfoV.td
728–729

The destunation LMUL of Reduction instructions is 1, I use
From_UpperBound to distinguish the source operand of reading: LMUL=MF8 to M8.
Do you suggest I use UpperBound , Read_UpperBound or something else?

llvm/lib/Target/RISCV/RISCVInstrInfoVPseudos.td
3303–3304

The use of From_MX is just to be noticed that the LMUL of the source operand is different.
But it is the same for scheduling, I personally prefer to use MX .

The suffixes From_UpperBound and From_MX come from the naming of the LMULWriteRes in the ScheduleV file. I think it makes sense to differentiate these LMULWriteRes with some sort of suffix, because they represent behavior that is different than the other LMULWriteRes definitions. I think From is a good suffix choice. Perhaps a comment above the definition of these LMULWriteRess that elaborates on the meaning of the suffix would be a helpful reference.

monkchiang updated this revision to Diff 494158.Feb 1 2023, 9:09 PM

Address Michael Maitland's comment. Thanks!

michaelmaitland requested changes to this revision.Feb 2 2023, 7:27 AM
michaelmaitland added inline comments.
llvm/lib/Target/RISCV/RISCVScheduleV.td
755

I think we still want WriteVFWRedV_From to use LMULWriteResFW class since its a floating point widening operation. After that change, it LGTM.

This revision now requires changes to proceed.Feb 2 2023, 7:27 AM

Change LMULWriteRes to LMULWriteResFWRed.

The following link shows LMUL of vfwredosum and vfwredusum are between MF4 to M8.
So I add LMULWriteResFWRed for widening floating-point Reduction.
https://github.com/riscv-non-isa/rvv-intrinsic-doc/blob/master/auto-generated/intrinsic_funcs/09_vector_reduction_functions.md#vector-widening-floating-point-reduction-functions

This revision is now accepted and ready to land.Feb 6 2023, 8:15 AM