This is an archive of the discontinued LLVM Phabricator instance.

[RISCV] Further fixes for RVV stack offset computation
ClosedPublic

Authored by frasercrmck on Apr 20 2021, 5:31 AM.

Details

Summary

This patch fixes a case missed out by D100574, in which RVV scalable
stack offset computations may require three live registers in the case
where the offset's fixed component is 12 bits or larger and has a
scalable component.

Instead of adding an additional emergency spill slot, this patch further
optimizes the scalable stack offset computation sequences to reduce
register usage.

By emitting the sequence to compute the scalable component before the
fixed component, we can free up one scratch register to be reallocated
by the sequence for the fixed component. Doing this saves one register
and thus one additional emergency spill slot.

Compare:

$x5 = LUI 1
$x1 = ADDIW killed $x5, -1896
$x1 = ADD $x2, killed $x1
$x5 = PseudoReadVLENB
$x6 = ADDI $x0, 50
$x5 = MUL killed $x5, killed $x6
$x1 = ADD killed $x1, killed $x5

versus:

$x5 = PseudoReadVLENB
$x1 = ADDI $x0, 50
$x5 = MUL killed $x5, killed $x1
$x1 = LUI 1
$x1 = ADDIW killed $x1, -1896
$x1 = ADD $x2, killed $x1
$x1 = ADD killed $x1, killed $x5

Diff Detail

Event Timeline

frasercrmck created this revision.Apr 20 2021, 5:31 AM
frasercrmck requested review of this revision.Apr 20 2021, 5:31 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 20 2021, 5:31 AM
frasercrmck added inline comments.Apr 20 2021, 5:32 AM
llvm/test/CodeGen/RISCV/rvv/emergency-slot.mir
154

I should have noticed this in the earlier patch, we were using three registers but since $x9 isn't a live-in to the successor block it wasn't requiring an emergency spill lot.

HsiangKai accepted this revision.Apr 20 2021, 10:22 AM

It makes sense to me. Thanks for optimizing the sequence further.

This revision is now accepted and ready to land.Apr 20 2021, 10:22 AM