[llvm] Fix loop cache cost to avoid cost of zero for refgroups. (PR #88915)

via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 17 12:33:30 PDT 2024


================
@@ -299,8 +299,15 @@ CacheCostTy IndexedReference::computeRefCost(const Loop &L,
     Stride = SE.getNoopOrAnyExtend(Stride, WiderType);
     TripCount = SE.getNoopOrZeroExtend(TripCount, WiderType);
     const SCEV *Numerator = SE.getMulExpr(Stride, TripCount);
-    RefCost = SE.getUDivExpr(Numerator, CacheLineSize);
-
+    ConstantInt *One =
+        ConstantInt::get(TripCount->getType()->getContext(), APInt(32, 1));
+    bool IsZero =
+        SE.isKnownPredicate(ICmpInst::ICMP_ULT, Numerator, CacheLineSize);
+    // When result is zero, round it to one because at least one cache line must
+    // be used. It does not make sense to output the result that zero cache line
+    // is used
+    RefCost =
+        IsZero ? SE.getSCEV(One) : SE.getUDivExpr(Numerator, CacheLineSize);
----------------
RouzbehPaktinat wrote:

Hi @nikic 
Thank you for your reviews. I made both changes. I used `getUDivCeilSCEV `only when refCost evaluates to zero. If I completely replace `getUDivExpr` with `getUDivCeilSCEV` many tests fail because it's now rounding all cost values not just zeros which is not purpose of this PR.

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


More information about the llvm-commits mailing list