[llvm] LV: reuse getSmallBestKnownTC in RT-check TC estimation (PR #105834)

David Sherwood via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 25 01:49:15 PDT 2024


================
@@ -1971,14 +1971,9 @@ class GeneratedRTChecks {
           // count. Assume that the outer loop executes at least twice.
           unsigned BestTripCount = 2;
 
-          // If exact trip count is known use that.
-          if (unsigned SmallTC = SE->getSmallConstantTripCount(OuterLoop))
-            BestTripCount = SmallTC;
-          else if (LoopVectorizeWithBlockFrequency) {
-            // Else use profile data if available.
-            if (auto EstimatedTC = getLoopEstimatedTripCount(OuterLoop))
-              BestTripCount = *EstimatedTC;
-          }
+          // Get the best known TC estimate.
+          if (auto EstimatedTC = getSmallBestKnownTC(*SE, OuterLoop))
----------------
david-arm wrote:

I'm not sure if this is what we want because getSmallBestKnownTC will fall back on the small constant maximum trip count if it fails to calculate the exact one. For example, the max could be 1024 but the actual runtime trip count might only be 16. That's why the code was written this way.

I like the idea of reusing code though. Perhaps you could add a new flag to `getSmallBestKnownTC` indicating whether we can use the constant max or not? You could make the default value true, and pass in false here, i.e.

```
bool getSmallBestKnownTC(ScalarEvolution *, Loop *, bool CanUseConstantMax = true) {
...
}

...
unsigned BestTripCount = 2;
if (auto EstimatedTC = getSmallBestKnownTC(*SE, OuterLoop, /* CanUseConstantMax=*/false)) {
...
```

Any thoughts @fhahn?

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


More information about the llvm-commits mailing list