This is an archive of the discontinued LLVM Phabricator instance.

[SLPVectorizer] Don't include isAssumeLikeIntrinsics in ScheduleRegionSize
ClosedPublic

Authored by uabelho on Jun 8 2023, 6:20 AM.

Details

Summary

We don't want the existence of debug instructions affect codegen so we now
ignore debug instructions and other "isAssumeLikeIntrinsics in the
"extend schedule region" search loop in
BoUpSLP::BlockScheduling::extendSchedulingRegion.

Diff Detail

Event Timeline

uabelho created this revision.Jun 8 2023, 6:20 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 8 2023, 6:20 AM
uabelho requested review of this revision.Jun 8 2023, 6:20 AM

@jmorse : I saw you did a bunch of nice debug info cleanups in https://reviews.llvm.org/D151419 but I don't think this problem is fixed there?

I stumbled upon this problem in downstream testing where debug info made us hit the ScheduleRegionSize limit thing.

What is the difference between runs results? Looks like it gets vectorized in all cases. Also, do a cleanup for metadata and attributes.

bjope added inline comments.Jun 8 2023, 6:50 AM
llvm/test/Transforms/SLPVectorizer/X86/schedule_budget.ll
8 ↗(On Diff #529575)

So this test case is kind of "broken" already on trunk?

(Looks like commit 352c46e70716061e99cae2009daddbfc78380fda changed this test in a way so that the first loads are vectorized even with a budget at 16.)

jmorse added a comment.Jun 8 2023, 7:50 AM

Many thanks for the patch, it looks good to me although I'm not very familiar with the vectorisers -- if no-one else reviews deeply then I can give it a shot later,

Would it be simpler to replace the increment lines with calls to getNextNonDebugInstruction rather than add a new predicate / set of calls -- this has the benefit of being slightly smaller, and will make cleanup easier once we've suppressed debug intrinsics entirely,

@jmorse : I saw you did a bunch of nice debug info cleanups in https://reviews.llvm.org/D151419 but I don't think this problem is fixed there?

Those are just the least contentious changes, there's more at [0], and probably a few other patches too. Although it looks like I didn't detect this particular defect at all!

[0] https://github.com/jmorse/llvm-project/commit/2d3354323ae83df2b00dc327645435fae668f94c

ABataev added inline comments.Jun 8 2023, 7:51 AM
llvm/test/Transforms/SLPVectorizer/X86/schedule_budget.ll
8 ↗(On Diff #529575)

Not broken, just changed. You'd better to add a new test with budget limits and debug info.

bjope added inline comments.Jun 8 2023, 8:16 AM
llvm/test/Transforms/SLPVectorizer/X86/schedule_budget.ll
8 ↗(On Diff #529575)

Just thinking that this comment, as well as the later comment about " ; Don't vectorize these loads.", seem to explain the expected outcome of the test. But then the CHECK:s seem to validate something else. That is confusing.

But maybe uabelho can just remove the RUN line with budget=16. One could just use budget=18 instead. As that also would show the debug-variance problem (e.g by pre-commit such a slightly modified test).

ABataev added inline comments.Jun 8 2023, 8:30 AM
llvm/test/Transforms/SLPVectorizer/X86/schedule_budget.ll
8 ↗(On Diff #529575)

The comments need to be removed in the separate patch. Or budget limit adjusted, whatever.

uabelho updated this revision to Diff 529826.Jun 8 2023, 10:27 PM

Created a new testcase instead of fiddling with the existing one.
Minor cleanup in metadata, removed dbg.value attributes.

Many thanks for the patch, it looks good to me although I'm not very familiar with the vectorisers -- if no-one else reviews deeply then I can give it a shot later,

Would it be simpler to replace the increment lines with calls to getNextNonDebugInstruction rather than add a new predicate / set of calls -- this has the benefit of being slightly smaller, and will make cleanup easier once we've suppressed debug intrinsics entirely,

I don't know. The searches use both forward and reverse iterators, I thought changing to getNextNonDebugInstruction/getPrevNonDebugInstruction would make the change larger since I guess I'd have to get rid of the reverse iterator then (?) and since I'm not familiar with this code I tried keeping the change as small as possible to not risk messing things up.

But I can try to go that route again if we prefer that.

jmorse added a comment.Jun 9 2023, 1:10 AM

But I can try to go that route again if we prefer that.

Not a strong opinion, it works just as well as it is.

ABataev added inline comments.Jun 10 2023, 5:25 AM
llvm/test/Transforms/SLPVectorizer/X86/schedule_budget_debug_info.ll
179

Try to simplify metadata, I rather doubt you need all the debug info specified here

uabelho updated this revision to Diff 530464.Jun 12 2023, 4:48 AM

Rebase and remove as much metadata as I can without getting complaints from e.g. update_test_checks.py.

uabelho marked an inline comment as done.Jun 12 2023, 4:48 AM
ABataev added inline comments.Jun 12 2023, 4:57 AM
llvm/test/Transforms/SLPVectorizer/X86/schedule_budget_debug_info.ll
1

Create a separate NFC patch with this test only.

uabelho updated this revision to Diff 530474.Jun 12 2023, 5:30 AM

Precommit testcase in https://reviews.llvm.org/D152705 so this patch shows how the testcase is improved.

ABataev added inline comments.Jun 13 2023, 7:31 AM
llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
11460

I think it worth it to extend it not only for debug intrinsics, but for all ephemeral instructions, like lifetime, assume, etc.

uabelho added inline comments.Jun 14 2023, 1:33 AM
llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
11460

I can do that, e.g. to check isAssumeLikeIntrinsic().

However, then the patch is starting to drift away from just fixing the "dbg info affects codegen" problem I was aiming at so then we start fixing/changing something else as well.

Do you still want that in the same patch?

ABataev added inline comments.Jun 14 2023, 2:45 AM
llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
11460

Yes, the change is small, you can do it here. And rename the title.

uabelho updated this revision to Diff 531250.Jun 14 2023, 3:45 AM
uabelho retitled this revision from [SLPVectorizer] Don't include debug instructions in ScheduleRegionSize to [SLPVectorizer] Don't include isAssumeLikeIntrinsics in ScheduleRegionSize.
uabelho edited the summary of this revision. (Show Details)

Ignore isAssumeLikeIntrinsic and not just debug intrinsics.

uabelho marked 2 inline comments as done.Jun 14 2023, 3:46 AM
This revision is now accepted and ready to land.Jun 14 2023, 3:55 AM
This revision was landed with ongoing or failed builds.Jun 14 2023, 4:03 AM
This revision was automatically updated to reflect the committed changes.