This is an archive of the discontinued LLVM Phabricator instance.

[LV] Do not vectorize loops with a low dynamic tripcount, as determined by profile information
Needs ReviewPublic

Authored by mkuper on Nov 18 2016, 3:02 PM.

Details

Summary

This is somewhat limited at this point - there are two known sources of inaccuracy:

  1. We still don't have a code duplication factor, so, for sampling-based FDO, we'll get the wrong trip count if the loop was vectorized in the sampled binary.
  2. Loops that are dynamically dead in the profile will still be vectorized, since getLoopEstimatedTripCount() still can't distinguish "loop was never entered" from "no information".

Both of these will need to be fixed on the "estimate trip count" side.
Dehao, David, do you think it's worth waiting with this until we have the duplication factors?

Diff Detail

Event Timeline

mkuper updated this revision to Diff 78587.Nov 18 2016, 3:02 PM
mkuper retitled this revision from to [LV] Do not vectorize loops with a low dynamic tripcount, as determined by profile information.
mkuper updated this object.
mkuper added reviewers: mssimpso, gilr, danielcdh, davidxl.
mkuper added a subscriber: llvm-commits.
anemet added a subscriber: anemet.Nov 18 2016, 4:16 PM
anemet added inline comments.
lib/Transforms/Vectorize/LoopVectorize.cpp
7203–7206

While you're here, can you please improve this message to actually mention low-trip count?

test/Transforms/LoopVectorize/X86/runtime-trip-count.ll
3

We usually try to formulate these tests without relying on asserts so that we get coverage with a no-assert build as well.

mkuper added inline comments.Nov 18 2016, 4:32 PM
lib/Transforms/Vectorize/LoopVectorize.cpp
7203–7206

Sure.

test/Transforms/LoopVectorize/X86/runtime-trip-count.ll
3

I realize that, but from a testing perspective, I actually want to verify the reason it didn't get vectorized, not only that it's not vectorized.
Do you think it would be better to duplicate the test and have an asserts and a non-asserts version? Do you know if "UNSUPPORTED: asserts" works?

(Is there a way to require asserts only for a specific run line, as opposed to the whole test? That would solve the problem.)

anemet added inline comments.Nov 18 2016, 4:42 PM
lib/Transforms/Vectorize/LoopVectorize.cpp
7203–7206

Thanks.

test/Transforms/LoopVectorize/X86/runtime-trip-count.ll
3

I'd say just use opt remarks then (-pass-remarks-missed=loop-vectorize). In the opt output, you won't have the function name (only the source line but that required debug info). If you want the function name, you could generate the YAML output which has everything including the function name.

mkuper added inline comments.Nov 18 2016, 4:45 PM
test/Transforms/LoopVectorize/X86/runtime-trip-count.ll
3

Ok, I guess opt remarks is a reasonable solution. I don't actually need the function name, since I only care about seeing a remark for the low case.

mkuper updated this revision to Diff 78607.Nov 18 2016, 5:12 PM

Updated per Adam's comments.

This is fine with me now. I let the others comment on your initial question.

mssimpso edited edge metadata.Nov 28 2016, 11:52 AM

Does the test need to be target-specific? Otherwise, this looks good to me as well.

No, I think I can move the test out, thanks Matt!

davidxl added inline comments.Feb 1 2017, 9:50 AM
lib/Transforms/Vectorize/LoopVectorize.cpp
7182

This looks like a reusable/common utility function (combine static count and profile count). Probably extract it out?