This is an archive of the discontinued LLVM Phabricator instance.

[SelectionDAG] Optimize bitreverse expansion to minimize the number of mask constants.
ClosedPublic

Authored by craig.topper on Aug 25 2021, 3:32 PM.

Details

Summary

We can halve the number of mask constants by masking before shl
and after srl.

This can reduce the number of mov immediate or constant
materializations. Or reduce the number of constant pool loads
for X86 vectors.

I think we might be able to do something similar for bswap. I'll
look at it next.

Diff Detail

Event Timeline

craig.topper created this revision.Aug 25 2021, 3:32 PM
craig.topper requested review of this revision.Aug 25 2021, 3:32 PM
Herald added a project: Restricted Project. · View Herald TranscriptAug 25 2021, 3:32 PM
Herald added a subscriber: MaskRay. · View Herald Transcript
pengfei added inline comments.Aug 25 2021, 7:42 PM
llvm/test/CodeGen/X86/vector-bitreverse.ll
690–695

Seems we have 2 extra move here. Is this a regression?

pengfei added inline comments.Aug 25 2021, 7:43 PM
llvm/test/CodeGen/X86/vector-bitreverse.ll
690–695

Seems we reduce the constant load :)

craig.topper added inline comments.Aug 25 2021, 7:51 PM
llvm/test/CodeGen/X86/vector-bitreverse.ll
690–695

Right we increased the number of instructions, but decreased the number of loads.

RKSimon accepted this revision.Aug 26 2021, 9:10 AM

LGTM

This revision is now accepted and ready to land.Aug 26 2021, 9:10 AM