[PATCH] D62110: [LV] prevent potential divide by zero. NFC

Nick Desaulniers via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue May 21 16:31:08 PDT 2019


nickdesaulniers added a comment.

In D62110#1508064 <https://reviews.llvm.org/D62110#1508064>, @rengolin wrote:

> Can expectedCost ever return zero?


`LoopVectorizationCostModel::expectedCost` default initializes its return value, an instance of `LoopVectorizationCostModel::VectorizationCostTy` declared as:

  using VectorizationCostTy = std::pair<unsigned, bool>;

so looks like it's possible.

Regardless, the runtime is going to be dominated by the division, not the check against zero, so why not just always pay the cost?  Especially if it reduces a warning from scan-build?

(I have the same opinion about pointers; "should I check this pointer isn't `nullptr` before dereferencing it? yeah, probably (short of it already have been checked and not updated since)." Skipping such a check doesn't add much value unless you have really hot code and strong guarantees (at which point, I'd prefer stronger guarantees from the type system).


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D62110/new/

https://reviews.llvm.org/D62110





More information about the llvm-commits mailing list