This is an archive of the discontinued LLVM Phabricator instance.

[DebugInfo] Update loop metadata for inlined loops
ClosedPublic

Authored by Orlando on May 15 2019, 1:37 AM.

Details

Summary

Currently, when a loop is cloned while inlining function (A) into function (B) the loop metadata is copied and then not modified at all. The loop metadata can encode the loop's start and end DILocations. Therefore, the new inlined loop in function (B) may have loop metadata which shows start and end locations residing in function (A).

This patch ensures loop metadata is updated while inlining so that the start and end DILocations are given the "inlinedAt" operand. I've also added a regression test for this.

This fix is required for D60831 because that patch uses loop metadata to determine the DILocation for the branches of new loop preheaders.

Diff Detail

Event Timeline

Orlando created this revision.May 15 2019, 1:37 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 15 2019, 1:37 AM

Seems reasonable, nitpicks inside.

llvm/lib/Transforms/Utils/InlineFunction.cpp
1378

what can this be except an MDNode?

1380

what can this be except a DILocation?

1381

this is reusing the same code used for inlining instructions — looks good

1388

referential

1426–1427

this is just factored out — LGTM

1440

this is weird, why no move the loop metadata update *above* the DILocation update?

Orlando marked an inline comment as done.May 15 2019, 9:18 AM
Orlando added inline comments.
llvm/lib/Transforms/Utils/InlineFunction.cpp
1380

It can be some other loop metadata.

The test inlined-loop-metadata.ll provides an example:

...
br i1 %13, label %middle.block, label %vector.body, !llvm.loop !15
...
!10 = !DILocation(line: 4, scope: !8)
!15 = distinct !{!15, !10, !16, !17}
!16 = !DILocation(line: 6, scope: !8)
!17 = !{!"llvm.loop.isvectorized", i32 1}
Orlando updated this revision to Diff 199767.May 16 2019, 2:27 AM

Address suggestions and add some const correctness.

Orlando marked 3 inline comments as done.May 16 2019, 2:33 AM
Orlando added inline comments.
llvm/lib/Transforms/Utils/InlineFunction.cpp
1440

Ah, that was left over from some experimental code. I've fixed this now.

aprantl accepted this revision.May 16 2019, 3:03 PM
This revision is now accepted and ready to land.May 16 2019, 3:03 PM
This revision was automatically updated to reflect the committed changes.
Orlando marked an inline comment as done.May 20 2019, 4:31 AM

Reverted with commit 95805bc425b because armv8 build bots are failing.