Page MenuHomePhabricator

[LV] Fix for PR36311, vectorizer's isUniform() abuse triggers assert in SCEV
ClosedPublic

Authored by hsaito on Feb 20 2018, 4:35 PM.

Details

Summary

See more detailed analysis in https://bugs.llvm.org/show_bug.cgi?id=36311.

isUniform() information is recomputed after LV started transforming the underlying IR and that triggered an assert in SCEV.

From vectorizer's architectural perspective, such information, while still useful in vector code gen, should not be recomputed after the start of transforming the LLVM IR. Instead, we should collect and cache such information during the analysis phase of LV and use the cached info during code gen.

From the symptom perspective, this assert as it stands right now is not very useful. Legality already rejected loops that would trigger the assert. As such, commenting out the assert is NFC from vectorizer's functionality perspective. On top of that, just above the assertion, we check for unit-strided load/store or
gather scatter. Addresses can't be uniform below that check.

From vectorization theory point of view, we don't have to reject all cases of stores to uniform addresses. Eventually, we should support safe/profitable cases.

This patch resolves the issue by removing the useless assertion that is invoking LAA's isUniform() that requires up-to-date DomTree ---- once vector code gen starts modifying CFG, we don't have an up-to-date DomTree.

Diff Detail

Event Timeline

hsaito created this revision.Feb 20 2018, 4:35 PM

Is it worthwhile to add a regression test that would trigger the assertion?

hsaito added a comment.EditedFeb 20 2018, 5:14 PM

Is it worthwhile to add a regression test that would trigger the assertion?

Looks like I can just clean up the test cases attached to Bugzilla. Will take care of it later today.

Ayal resigned from this revision.Feb 21 2018, 3:25 AM
hsaito updated this revision to Diff 135315.Feb 21 2018, 12:51 PM

Added the test that triggered the PR36311 assertion.

LGTM, however I am not the right person to approve patches to the LoopVectorizer.

SGTM, the same disclaimer :) I'm not a very good at LoopVectorizer :)

mkazantsev added inline comments.Feb 25 2018, 8:28 PM
test/Transforms/LoopVectorize/pr36311.ll
11 ↗(On Diff #135315)

Could you please rename this one into @test() and add a comment what does it check?

LGTM with comments addressed the same disclaimer: I'm not the right person to approve patches in LV.

lib/Transforms/Vectorize/LoopVectorize.cpp
3051–3057

I'd rather prefer FIXME here.

hsaito added inline comments.Feb 27 2018, 10:49 AM
test/Transforms/LoopVectorize/pr36311.ll
11 ↗(On Diff #135315)

How about a comment like this?

; This is a test case that let's vectorizer's code gen to modify CFG and get DomTree out of date,
; such that an assert from SCEV would trigger if reanalysis of SCEV happens subsequently.
; Once vector code gen starts, vectorizer should not invoke recomputation of Analysis.

rengolin requested changes to this revision.Feb 27 2018, 2:04 PM

Please attach this quick fix to the bug itself, so that people can use it while we fix the problem in the right place. We normally don't comment out code in LLVM, as that tends to leave code in comments all over the place.

This revision now requires changes to proceed.Feb 27 2018, 2:04 PM

Please attach this quick fix to the bug itself, so that people can use it while we fix the problem in the right place. We normally don't comment out code in LLVM, as that tends to leave code in comments all over the place.

Fair enough. Done attaching to the bug. We should then just get rid of this useless assert and be done with it. Just above, we have the following assertion, checking for unit-stride or gather/scatter.
Why bother check again for non-uniform address?, and this is on top of Legal already rejecting store to uniform address already.

// Either Ptr feeds a vector load/store, or a vector GEP should feed a vector  
// gather/scatter. Otherwise Decision should have been to Scalarize.           
assert((ConsecutiveStride || CreateGatherScatter) && 
       "The instruction should be scalarized");

Also thought about creating a isUniform() functionality that can be invoked during vector code gen. Bulk of functionality should be already covered by
CostModel::isUniformAfterVectorization() ---- but calling such a thing after checking for the "ConsecutiveStride or GatherScatter" is rather odd.
I'm planning to do another architectural clean up, but using this bug as an excuse to do that would be a poor reasoning.

hsaito updated this revision to Diff 136231.Feb 27 2018, 11:05 PM
hsaito retitled this revision from [LV] Quick workaround for PR36311, vectorizer's isUniform() abuse triggers assert in SCEV to [LV] Fix for PR36311, vectorizer's isUniform() abuse triggers assert in SCEV.
hsaito edited the summary of this revision. (Show Details)
hsaito added inline comments.Feb 27 2018, 11:10 PM
lib/Transforms/Vectorize/LoopVectorize.cpp
3051–3057

Changed the comment such that it is actually a TODO for how one can enable store to uniform addr.

Fair enough, I can't see what case this is trying to cover anyway. I'm happy with the line going out without a big comment, commit message is usually ok.

Sorry it took so long, I'm swapping a bit in the past few weeks.

lib/Transforms/Vectorize/LoopVectorize.cpp
3051–3057

This TODO is confusing. I'm not sure what's the thing we want to do in the future...

Maybe adding that big description on the commit message and a short message for the exact thing we want to implement here, for example, "detect cases where..."

hsaito added a comment.Mar 7 2018, 5:17 PM

Fair enough, I can't see what case this is trying to cover anyway. I'm happy with the line going out without a big comment, commit message is usually ok.

Sorry it took so long, I'm swapping a bit in the past few weeks.

I'll then remove the TODO comment and update the commit message.

hsaito updated this revision to Diff 137529.Mar 7 2018, 6:15 PM
hsaito edited the summary of this revision. (Show Details)
hsaito edited the summary of this revision. (Show Details)
rengolin accepted this revision.Mar 8 2018, 4:04 AM

LGTM, thanks!

This revision is now accepted and ready to land.Mar 8 2018, 4:04 AM
hsaito added a comment.Mar 8 2018, 9:56 AM

Great. Like my other patches, I don't have a commit privilege. Please commit this for me.

Thanks,
Hideki

rengolin closed this revision.Mar 9 2018, 2:34 AM

r327109