This is an archive of the discontinued LLVM Phabricator instance.

[RISCV] Custom lower ISD::VSCALE.
ClosedPublic

Authored by craig.topper on Jan 7 2021, 11:24 AM.

Details

Summary

This patch custom lowers ISD::VSCALE into a csrr vlenb followed
by a shift right by 3 followed by a multiply by the scale amount.

I've added computeKnownBits support to indicate that the csrr vlenb
always produces 3 trailng bits of 0s so the shift right is "exact".
This allows the shift and multiply sequence to be nicely optimized
into a single shift or removed completely when the scale amount is
a power of 2.

The non power of 2 case multiplying by 24 is still producing
suboptimal code. We could remove the right shift and use a
multiply by 3. Hopefully we can improve DAG combine to fix that
since it's not unique to this sequence.

This replaces D94144.

Diff Detail

Event Timeline

craig.topper created this revision.Jan 7 2021, 11:24 AM
craig.topper requested review of this revision.Jan 7 2021, 11:24 AM
Herald added a project: Restricted Project. · View Herald TranscriptJan 7 2021, 11:24 AM
Herald added a subscriber: MaskRay. · View Herald Transcript
craig.topper edited the summary of this revision. (Show Details)Jan 7 2021, 11:25 AM
HsiangKai added inline comments.Jan 13 2021, 7:18 AM
llvm/lib/Target/RISCV/RISCVISelLowering.cpp
697

I think we need add comments to explain why we need to shift right 3 bits.

1901

In V specification v1.0, VLEN=128 at least. We could assume VLENB is at least 16 bytes.

-Add comments about why we shift by 3.
-Add FIXMEs for the 1.0 change to VLEN>=128.

-Remove a FIXME. Just because the minimum VLEN might be defined as 128 doesn't mean we need to change our type mappings.
-Reword the description of why we divide by 8 to not talk about VLEN.

This revision is now accepted and ready to land.Jan 13 2021, 5:05 PM
This revision was landed with ongoing or failed builds.Jan 13 2021, 5:33 PM
This revision was automatically updated to reflect the committed changes.