This is an archive of the discontinued LLVM Phabricator instance.

[Assignment Tracking][SROA] Fix fragment when slice size equals variable size
ClosedPublic

Authored by Orlando on Apr 6 2023, 3:40 AM.

Details

Summary

Correctly handle the case of splitting an alloca which backs contiguous distinct variables, where a slice's size equals the size of a backed variable.

We need to ensure that we don't generate fragments expressions with fragments of the same size as the variable as this is a verifier error.

Prior to this patch a fragment expression would be created in this situation. e.g. splitting an alloca i64 with two adjacent 32-bit variables into two 32-bit allocas, the new dbg.assign expressions would contain (DW_OP_LLVM_fragment, 0, 32) and (DW_OP_LLVM_fragment, 32, 32) even though those fragments cover each variable entirely.

Diff Detail

Event Timeline

Orlando created this revision.Apr 6 2023, 3:40 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 6 2023, 3:40 AM
Herald added a subscriber: hiraditya. · View Herald Transcript
Orlando requested review of this revision.Apr 6 2023, 3:40 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 6 2023, 3:40 AM
jmorse accepted this revision.Apr 6 2023, 5:32 AM

I've got some quibbles about the code layout and wording, but otherwise this LGTM.

llvm/lib/Transforms/Scalar/SROA.cpp
153–160

I feel this could be more terse, something like "If this slice extracts the entirety of an independent variable from a larger alloca, do not produce a fragment expression, as the variable is not fragmented". IMO it's better to be terse than to give too much detail, YMMV.

262–267

IMO: using if UseNoFrag ...else if Skip... would allow UseNoFrag and Skip to be handled up front, leaving UseFrag as the only onwards path which avoids indenting the rest of the block below. We can rely on optimisations to make this just as fast as a switch, IMO.

llvm/test/DebugInfo/Generic/assignment-tracking/sroa/var-sized-fragment.ll
7
21

Does the upper 32 bits not get a dbg.value(poison) at least? Best to test for that not having an expression if it does get generated, as that's the purpose of this test.

This revision is now accepted and ready to land.Apr 6 2023, 5:32 AM
Orlando updated this revision to Diff 511385.Apr 6 2023, 6:01 AM
Orlando marked 3 inline comments as done.

+ Address some comments and leave some inline replies

llvm/lib/Transforms/Scalar/SROA.cpp
153–160

SGTM

262–267

Both UseNoFrag and UseFrag need to reach code outside the outer if (f (IsSplit)), but we only want the fragment-making code to occur when we UseFrag. I've restructured it to avoid a new additional layer of indentation - are you happy with this?

llvm/test/DebugInfo/Generic/assignment-tracking/sroa/var-sized-fragment.ll
21

Unfortunately the upper 32 bits (which are tracked with a dbg.declare) get incorrect debug-info. See https://github.com/llvm/llvm-project/issues/61981. This issue is independent of assignment tracking.

Orlando updated this revision to Diff 511394.Apr 6 2023, 6:19 AM

Fix typo and undo formatting change that was previously required due to additional indentation.

jmorse added inline comments.Apr 6 2023, 7:10 AM
llvm/lib/Transforms/Scalar/SROA.cpp
262–267

SGTM, it was only the extra indentation that bothered me.

llvm/test/DebugInfo/Generic/assignment-tracking/sroa/var-sized-fragment.ll
21

Unfortunately the upper 32 bits (which are tracked with a dbg.declare) get incorrect debug-info. See https://github.com/llvm/llvm-project/issues/61981. This issue is independent of assignment tracking.

Sure, but the fragment information for that is orthogonal surely, we can test for the wrong location but right fragment information, with a "FIXME" saying the location is wrong and a link to the bug? That'll be updated when the bug is fixed, and means we still achieve coverage of the upper bits of this alloca that's being split up either way.

Orlando updated this revision to Diff 511406.Apr 6 2023, 7:22 AM
Orlando marked 3 inline comments as done.

+ Check debug intrinsic for upper bits (variable b) in the test doesn't get a fragment expression

llvm/test/DebugInfo/Generic/assignment-tracking/sroa/var-sized-fragment.ll
21

SGTM, how does this look?

Orlando updated this revision to Diff 511408.Apr 6 2023, 7:24 AM

+ Update comment in the test.

jmorse accepted this revision.Apr 6 2023, 7:24 AM

LGTM

This revision was landed with ongoing or failed builds.Apr 6 2023, 7:34 AM
This revision was automatically updated to reflect the committed changes.