[llvm] [LoopInterchange] Fix overflow in cost calculation (PR #111807)

Florian Hahn via llvm-commits llvm-commits at lists.llvm.org
Mon Nov 4 10:36:33 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(
----------------
fhahn wrote:

Is this still needed or sufficient to let wrapping handle by InstructionCost?

https://github.com/llvm/llvm-project/pull/111807


More information about the llvm-commits mailing list