This is an archive of the discontinued LLVM Phabricator instance.

[SLPVectorizer] Debug intrinsics shouldn't affect spill cost
ClosedPublic

Authored by davide on Apr 27 2018, 10:29 AM.

Details

Summary

The SLPVectorizer doesn't skip DebugInfo instructions when computing the spill cost, although these instruction make no difference.

SLP: Spill Cost = 4.
SLP: Extract Cost = 0.
SLP: Total Cost = 2.
SLP: Found cost=2 for VF=2
SLP: Analyzing a store chain of length 2

vs

SLP: Spill Cost = 0.
SLP: Extract Cost = 0.
SLP: Total Cost = -2.
SLP: Found cost=-2 for VF=2
SLP: Decided to vectorize cost=-2

The proposed fix is to skip them.

Fixes PR37261 / rdar://problem/39794738

Diff Detail

Repository
rL LLVM

Event Timeline

davide created this revision.Apr 27 2018, 10:29 AM
davide added inline comments.Apr 27 2018, 10:34 AM
llvm/test/Transforms/SLPVectorizer/AArch64/spillcost-di.ll
3–8 ↗(On Diff #144368)

I'll fix the check lines before committing, they look like:

+; RUN: opt -S -slp-vectorizer %s -o - | FileCheck %s

vsk accepted this revision.Apr 27 2018, 10:35 AM

Lgtm, thanks! You might consider stripping out the tbaa as well.

This revision is now accepted and ready to land.Apr 27 2018, 10:35 AM
hsaito added a subscriber: hsaito.Apr 27 2018, 10:36 AM
hsaito added inline comments.
llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
2559 ↗(On Diff #144368)

If LLVM doesn't have a generic "skip for cost" utility already, I think it's time to start having one. It's very likely that this goes beyond just DbgInfoIntrinsic and functionality would be common to many optimizers. If there is one, we should use that instead.

vsk added inline comments.Apr 27 2018, 10:40 AM
llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
2559 ↗(On Diff #144368)

I think you're right. Recently an instructionsWithoutDebug() helper method was introduced in BasicBlock, which is a step in the right direction. It would be nice to use that utility here, although that might be better as a follow-up, since the change looks invasive.

fhahn added a subscriber: fhahn.Apr 27 2018, 10:47 AM
fhahn added inline comments.
llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
2559 ↗(On Diff #144368)

Yep I think having such a utility would be great. When adding instructionsWithoutDebug(), I was also prototyping a more generic skipInstructions function, which takes a range iterator and instruction types to skip and returns an iterator that skips over the ignored instructions. I can put it somewhere on phabricator again.

hsaito added inline comments.Apr 27 2018, 10:52 AM
llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
2559 ↗(On Diff #144368)

Sounds like a plan. I don't intend to slow down this patch waiting for that. Please follow up towards generic utility direction in the future.

davide added inline comments.Apr 27 2018, 10:58 AM
llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
2559 ↗(On Diff #144368)

That would be great, Florian. I think it's going to be of great use now that we're trying to squash down these debuginfo bugs.

This revision was automatically updated to reflect the committed changes.
fhahn added inline comments.Apr 30 2018, 10:29 AM
llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
2559 ↗(On Diff #144368)

Unfortunately the iterators here seem incompatible with range iterators.

But would a helper function like isFreeInstruction be useful, that returns true for instructions that won't result in any instructions in the generated code, e.g. dbg intrinsics, lifetime markers, assume. Here (and probably in plenty of more places), we should also ignore those.

hsaito added inline comments.Apr 30 2018, 10:49 AM
llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
2559 ↗(On Diff #144368)

My thinking was that your iterator would use such a helper function and it's a matter of exposing it as a utility. I think we are now on the same page.