[PATCH] D60751: [NFC][InlineCost] cleanup - comments, overflow handling.

Fedor Sergeev via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sat Apr 27 03:35:55 PDT 2019


fedor.sergeev marked an inline comment as done.
fedor.sergeev added inline comments.


================
Comment at: lib/Analysis/InlineCost.cpp:247
+  /// Handle a capped 'int' increment for Cost.
+  void addCost(int64_t Inc, int64_t UpperBound = INT_MAX) {
+    Cost = std::min(UpperBound, Cost + Inc);
----------------
apilipenko wrote:
> yrouban wrote:
> > I believe that both //Inc// and //UpperBound// must be of the same type as //Cost// (i.e. //int//) but the parameters of std::max() should be extended.
> Agree. An explicit cast to a wider type is more clear.
int64_t came from cost calculations in CallAnalyzer::visitSwitchInst, which specifically uses uint64_t in many places, both for increment and upper bound.
Practically speaking, reaching INTMAX there is hardly possible since that would reqiure having, say, more than INTMAX/5 Cases in a single switch.
However I would like to avoid doing semantical changes with this refactoring.

The only check that I should add here is an assert on UpperBound being positive and not exceeding INT_MAX.
Other than that I dont see what makes int64_t unclear here.


Repository:
  rL LLVM

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

https://reviews.llvm.org/D60751





More information about the llvm-commits mailing list