[llvm] [LoopInterchange] Fix overflow in cost calculation (PR #111807)
Sjoerd Meijer via llvm-commits
llvm-commits at lists.llvm.org
Thu Oct 10 04:08:32 PDT 2024
================
@@ -712,7 +717,12 @@ CacheCost::computeLoopCacheCost(const Loop &L,
CacheCostTy LoopCost = 0;
for (const ReferenceGroupTy &RG : RefGroups) {
CacheCostTy RefGroupCost = computeRefGroupCacheCost(RG, L);
- LoopCost += RefGroupCost * TripCountsProduct;
+
+ // Saturate the cost to INT MAX if the value can overflow.
+ if (RefGroupCost > (std::numeric_limits<int64_t>::max() / TripCountsProduct))
+ LoopCost = std::numeric_limits<int64_t>::max();
+ else
+ LoopCost += RefGroupCost * TripCountsProduct;
----------------
sjoerdmeijer wrote:
It didn't improve readability, in my opinion, so have left it like this.
https://github.com/llvm/llvm-project/pull/111807
More information about the llvm-commits
mailing list