This is an archive of the discontinued LLVM Phabricator instance.

[coro async] Cap the alignment of spilled values (vs. allocas) at the max frame alignment
ClosedPublic

Authored by aschwaighofer on Jul 1 2021, 7:55 AM.

Details

Summary

Before this patch we would normally use the ABI alignment which can be
to high for the context alginment.

For spilled values we don't need ABI alignment, since the frame entry's
address is not escaped.

rdar://79664965

Diff Detail

Event Timeline

aschwaighofer created this revision.Jul 1 2021, 7:55 AM
aschwaighofer requested review of this revision.Jul 1 2021, 7:55 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 1 2021, 7:55 AM

Shouldn't there be a test case showing that a spilled value with high ABI alignment is placed in an appropriately-underaligned slot, and that the loads and stores to that slot have the necessary alignment? Because the alignment in this test is just coming from the alloca's explicit alignment.

The spilled value from this test comes from trying to spill %vector_spill which is a value life across a suspend point. Because it has a value it has no alignment. It is misleading that we load the value from an alloca. It could also be the result of a computation. This test case crashes before the patch because we are assigning the abi alignment for the value '%vector_spill`.

Oh my. You are right I should have verified that when we spill that value though we use the right alignment. Because we don't. :(.

%vector_spill = load <4 x double>, <4 x double>* %vector, align 16
%vector_spill.spill.addr = getelementptr inbounds %my_async_function.Frame, %my_async_function.Frame* %FramePtr, i32 0, i32 1, !dbg !6
 store <4 x double> %vector_spill, <4 x double>* %vector_spill.spill.addr, align 32, !dbg !6

The code that spills/reloads does not use the alignment we have computed for the spill slot.
Rather it just does:

Builder.CreateStore(Def, G);

Use the compute type alignment for spilled values when spilling/restoring

Minor style request, but otherwise LGTM

llvm/lib/Transforms/Coroutines/CoroFrame.cpp
1565

I would assume from the name that this is something like the alignment of the type. Maybe SpillAlignment?

Change variable name from TyAlignment to SpillAlignment

This revision was not accepted when it landed; it landed in state Needs Review.Jul 7 2021, 8:07 AM
This revision was automatically updated to reflect the committed changes.