This is an archive of the discontinued LLVM Phabricator instance.

[ADCE] Only remove debug intrinsics if non debug instructions are removed
AbandonedPublic

Authored by uabelho on Mar 1 2023, 2:31 AM.

Details

Summary

We now limit ADCE to only remove debug intrinsics if it does something else
that would invalidate cached analyses anyway.
As we've seen in
https://github.com/llvm/llvm-project/issues/58285
throwing away cached analysis info when only debug instructions are removed
can lead to different code when debug info is present or not present.

Diff Detail

Event Timeline

uabelho created this revision.Mar 1 2023, 2:31 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 1 2023, 2:31 AM
Herald added a subscriber: hiraditya. · View Herald Transcript
uabelho requested review of this revision.Mar 1 2023, 2:31 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 1 2023, 2:31 AM

(I happened to have touched this area, you'll need to rebase)

llvm/lib/Transforms/Scalar/ADCE.cpp
572

can move this into an else of the previous if statement

llvm/test/Transforms/ADCE/debug-info-intrinsic-2.ll
2

can you use update_test_checks.py?

uabelho updated this revision to Diff 501744.Mar 1 2023, 9:24 PM

Rebase and update according to comments.

uabelho marked 2 inline comments as done.Mar 1 2023, 9:24 PM

(I happened to have touched this area, you'll need to rebase)

Thanks for the suggestions. Done!

StephenTozer added inline comments.
llvm/lib/Transforms/Scalar/ADCE.cpp
576–577
uabelho updated this revision to Diff 501806.Mar 2 2023, 1:35 AM

Fix spelling mistake.

uabelho marked an inline comment as done.Mar 2 2023, 1:35 AM

Thanks!

StephenTozer accepted this revision.Mar 2 2023, 1:42 AM

LGTM - I think not deleting debug intrinsics if there would be no other codegen changes is the right call for now as a simplest viable fix for the linked issue; hopefully this doesn't result in intrinsic bloat, but if it does that can be solved separately.

This revision is now accepted and ready to land.Mar 2 2023, 1:42 AM
nikic added a subscriber: nikic.Mar 3 2023, 2:31 AM

This caused a large compile-time regressions in some cases: http://llvm-compile-time-tracker.com/compare.php?from=57833636816a13ccda53714413c532dc81e3b5ff&to=8aa9ab336889ae2eb8e4188036faeb151379ab7b&stat=instructions:u In particular tramp3d-v4 with debuginfo regressed by 15%.

So I think this is probably not the right way to fix this issue. I think what we can do instead is to mark MemorySSA as preserved if only debuginfo intrinsics have been removed. (This is safe, MSSA explicitly never tracks debuginfo intrinsics.)

This caused a large compile-time regressions in some cases: http://llvm-compile-time-tracker.com/compare.php?from=57833636816a13ccda53714413c532dc81e3b5ff&to=8aa9ab336889ae2eb8e4188036faeb151379ab7b&stat=instructions:u In particular tramp3d-v4 with debuginfo regressed by 15%.

So I think this is probably not the right way to fix this issue. I think what we can do instead is to mark MemorySSA as preserved if only debuginfo intrinsics have been removed. (This is safe, MSSA explicitly never tracks debuginfo intrinsics.)

Should I revert this for now then or do we leave it in-tree while determining what we do about it?

nikic added a comment.Mar 3 2023, 4:02 AM

I'd suggest reverting it.

uabelho reopened this revision.Mar 3 2023, 4:13 AM

Ok, reverted due to the compile-time regressions pointed out by @nikic .

This revision is now accepted and ready to land.Mar 3 2023, 4:13 AM

I think what we can do instead is to mark MemorySSA as preserved if only debuginfo intrinsics have been removed. (This is safe, MSSA explicitly never tracks debuginfo intrinsics.)

Does everyone agree this is the way forward then? If so I can put up a patch doing that on Monday.

I think what we can do instead is to mark MemorySSA as preserved if only debuginfo intrinsics have been removed. (This is safe, MSSA explicitly never tracks debuginfo intrinsics.)

Does everyone agree this is the way forward then? If so I can put up a patch doing that on Monday.

Probably worth picking up the discussion on the original bug. I think @aeubanks had speculated about this other path - it does seem more brittle (playing whack-a-mole with preserving analyses - can we say it preserves all analyses despite removing debug intrinsics? And then whack-a-mole in the opposite direction to flag certain analyses as unpreserved if they do get broken by the intrinsic removals?)/might have some other concerns.

I think what we can do instead is to mark MemorySSA as preserved if only debuginfo intrinsics have been removed. (This is safe, MSSA explicitly never tracks debuginfo intrinsics.)

Does everyone agree this is the way forward then? If so I can put up a patch doing that on Monday.

Probably worth picking up the discussion on the original bug. I think @aeubanks had speculated about this other path - it does seem more brittle (playing whack-a-mole with preserving analyses - can we say it preserves all analyses despite removing debug intrinsics? And then whack-a-mole in the opposite direction to flag certain analyses as unpreserved if they do get broken by the intrinsic removals?)/might have some other concerns.

Sure, let's continue in https://github.com/llvm/llvm-project/issues/58285