This is an archive of the discontinued LLVM Phabricator instance.

[Loop Vectorize] Block Probability for Predicated Blocks
Needs ReviewPublic

Authored by DIVYA on Jul 31 2017, 2:59 PM.

Details

Summary

LoopVectorize Pass uses reciprocal of block probability as 2 for all predicated blocks.Here, we have used BlockFrequencyInfo to get the block probabilities

Worked in collaboration with Aditya Kumar

Diff Detail

Event Timeline

DIVYA created this revision.Jul 31 2017, 2:59 PM
fhahn added a subscriber: fhahn.Aug 1 2017, 4:52 AM

I'm just curious, did you run any benchmarks with this change? I think it's quite clear that using the block frequencies is a good idea, but it would be awesome to know if/by how much it improves things :)

Also, is it worth adding a dedicated test case making sure the frequencies are used by the cost model as expected?

lib/Transforms/Vectorize/LoopVectorize.cpp
343

It looks like this commit fixes this TODO, remove the TODO?

346

Any reasons for the name change?

Also, given that this function takes BFI and the headerBB as arguments I think making it a member function of LoopVectorizationCostModel would make it easier to use (both BFI and HeaderBB should be available as member variables there)

349

At least the outermost brackets can be omitted here I think

inouehrs added inline comments.
lib/Transforms/Vectorize/LoopVectorize.cpp
350

Don't you need to handle the case of zero frequency (e.g. if BFI is not available) to avoid divide-by-zero?

DIVYA updated this revision to Diff 109182.EditedAug 1 2017, 12:31 PM
  • Added getReciprocalPredBlockProb() as a member function of LoopVectorizationCostModel class
  • Added a testcase
DIVYA marked 3 inline comments as done.Aug 1 2017, 12:51 PM
DIVYA marked an inline comment as done.Aug 1 2017, 1:02 PM
fhahn added inline comments.Aug 2 2017, 7:07 AM
lib/Transforms/Vectorize/LoopVectorize.cpp
2016

I think this could be const? and BB could also be const?

Is BFI guaranteed to be non-NULL?

DIVYA updated this revision to Diff 109801.Aug 4 2017, 12:35 PM
DIVYA marked an inline comment as done.
mssimpso added inline comments.
lib/Transforms/Vectorize/LoopVectorize.cpp
2020–2021

I too am curious if you saw any performance improvements with this change. Can you share any data?

If the goal is to be more precise, it probably makes sense for this function to return a float for block probability and not an unsigned for the reciprocal. I think nearly all the users of this function use it as the denominator of a division. So with the added division here and the ones that follow, we're losing precision. I'm not sure this is any better than always returning 2.

test/Transforms/LoopVectorize/AArch64/aarch64-predication.ll
25

FWIW, the current patch breaks this test. For it to be testing what it's intended to test, the add should be scalarized.

DIVYA updated this revision to Diff 111574.Aug 17 2017, 3:27 PM
This comment was removed by DIVYA.
DIVYA updated this revision to Diff 111576.Aug 17 2017, 3:50 PM