This is an archive of the discontinued LLVM Phabricator instance.

[LICM] Sunk instructions with invalid source location.
ClosedPublic

Authored by CarlosAlbertoEnciso on Jun 12 2023, 2:41 AM.

Details

Summary

Building the given test case with 'clang -O2 -g' the call to
getInOrder is sunk out of the loop by LICM, but the source
location is not dropped.

Diff Detail

Event Timeline

CarlosAlbertoEnciso requested review of this revision.Jun 12 2023, 2:41 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 12 2023, 2:41 AM
aprantl accepted this revision.Jun 12 2023, 7:30 AM
aprantl added a subscriber: aprantl.
aprantl added inline comments.
llvm/lib/Transforms/Scalar/LICM.cpp
1715

Can you add a comment here explaining that we do this because we sink the instruction out of the BB?

This revision is now accepted and ready to land.Jun 12 2023, 7:30 AM

I think we can greatly simplify the test to make it easier for readers to understand what's going on. I left some inline comments, and the test itself could start along these lines:

; CHECK-LABEL: for.end:
; CHECK: tail call noundef i32 @foo0({{.*}}), !dbg ![[DBG:[0-9]+]]
; CHECK-DAG: ![[DBG]] = !DILocation(line: 0, scope: ![[SCOPE:[0-9]+]]
; CHECK-DAG: ![[SCOPE]] = distinct !DISubprogram(name: "bounce",

define noundef i32 @foo0(i32 noundef %Idx) #0 !dbg !9 {
  ret i32 2, !dbg !14
}
define noundef i32 @foo1(i32 noundef %Idx) #0 !dbg !15 {
  ret i32 4, !dbg !16
}

define i32 @foo2() !dbg !17 {
entry:
  br label %for.body, !dbg !20

... rest of the test here ...
llvm/test/Transforms/LICM/sink-instruction-invalid-location.ll
31

We shouldn't hardcode the name of SSA values, these are not guaranteed to be preserved by opt.

I believe the same apply for the names of BBs (which are also SSA values)

36

I believe this variable is not used anywhere?

40

If I understand correctly, the contents of this function are not needed by the test and could be replaced by a ret i32 2

Note this will also make the other GV unused.

I think we can greatly simplify the test to make it easier for readers to understand what's going on. I left some inline comments, and the test itself could start along these lines:

; CHECK-LABEL: for.end:
; CHECK: tail call noundef i32 @foo0({{.*}}), !dbg ![[DBG:[0-9]+]]
; CHECK-DAG: ![[DBG]] = !DILocation(line: 0, scope: ![[SCOPE:[0-9]+]]
; CHECK-DAG: ![[SCOPE]] = distinct !DISubprogram(name: "bounce",

define noundef i32 @foo0(i32 noundef %Idx) #0 !dbg !9 {
  ret i32 2, !dbg !14
}
define noundef i32 @foo1(i32 noundef %Idx) #0 !dbg !15 {
  ret i32 4, !dbg !16
}

define i32 @foo2() !dbg !17 {
entry:
  br label %for.body, !dbg !20

... rest of the test here ...

Thanks very much for outlining a simplified test and the inline comments.

llvm/test/Transforms/LICM/sink-instruction-invalid-location.ll
31

Removed the hardcoded SSA and BBs names.

36

Good point. Removed.

Uploaded new patch to address feedback from @aprantl and @fdeazeve.

@aprantl and @fdeazeve, thanks very much for your valuable feedback.

llvm/lib/Transforms/Scalar/LICM.cpp
1715

Added a comment.

llvm/test/Transforms/LICM/sink-instruction-invalid-location.ll
40

You are correct. Replaced by ret i32 2.