[llvm] [LoopInterchange] Fix overflow in cost calculation (PR #111807)
Sjoerd Meijer via llvm-commits
llvm-commits at lists.llvm.org
Thu Nov 7 05:54:53 PST 2024
================
@@ -338,14 +340,18 @@ CacheCostTy IndexedReference::computeRefCost(const Loop &L,
assert(RefCost && "Expecting a valid RefCost");
// Attempt to fold RefCost into a constant.
+ // CacheCostTy is a signed integer, but the tripcount value can be large
+ // and may not fit, so saturate/limit the value to the maximum signed
+ // integer value.
if (auto ConstantCost = dyn_cast<SCEVConstant>(RefCost))
- return ConstantCost->getValue()->getZExtValue();
+ return ConstantCost->getValue()->getLimitedValue(
----------------
sjoerdmeijer wrote:
Yes, this is unfortunately still needed. Helper `getZExtValue()` returns an uint64_t and checks if the value fits in this number of bits.
https://github.com/llvm/llvm-project/pull/111807
More information about the llvm-commits
mailing list