This is an archive of the discontinued LLVM Phabricator instance.

[RISCV] Add basic code modeling for fixed length vector reduction.
ClosedPublic

Authored by fakepaper56 on Mar 11 2022, 12:53 AM.

Diff Detail

Event Timeline

fakepaper56 created this revision.Mar 11 2022, 12:53 AM
fakepaper56 requested review of this revision.Mar 11 2022, 12:53 AM
craig.topper added inline comments.Mar 11 2022, 9:36 AM
llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp
228

vecotr->vector

229

i64/f64 aren't always legal types either. Need to check ELEN

234

You should probably call getTypeLegalizationCost first. If the type is really wide, we'll emit multiple reduction instructions. It will also esnure VL is a power 2. Otherwise you probably need to use Log2_32_Ceil(VL).

250

vecotr->vector

Add the summary.

fakepaper56 updated this revision to Diff 414779.EditedMar 11 2022, 5:34 PM

The update uses getMaxELENForFixedLengthVectors to check ELEN and replace Log2_32 by Log2_32_Ceil.

I think getTypeLegalizationCost is imprecise for RVV fixed length vector. Take v4i8 as an example, getTypeLegalizationCost thinks v4i8 should split to 4 v1i8 since v4i8 is not legal type. But v4i8 is expanded to extract_subvector of a nxv1i8.

I think getTypeLegalizationCost is imprecise for RVV fixed length vector. Take v4i8 as an example, getTypeLegalizationCost thinks v4i8 should split to 4 v1i8 since v4i8 is not legal type. But v4i8 is expanded to extract_subvector of a nxv1i8.

I think that's because you didn't pass -riscv-v-vector-bits-min in the test. Fixed vectors are scalarized without that. That also means the cost model needs to check ST->useRVVForFixedLengthVectors().

fakepaper56 updated this revision to Diff 414797.EditedMar 11 2022, 8:49 PM

The update add getTypeLegalizationCost to support split vector cases. And use getTypeLegalizationCost to make sure the fixed vector type is legal.

This revision is now accepted and ready to land.Mar 12 2022, 5:02 PM
This revision was landed with ongoing or failed builds.Mar 13 2022, 8:04 PM
This revision was automatically updated to reflect the committed changes.
fakepaper56 marked 3 inline comments as done.