[llvm] [NFC][LoopVectorize] Cache result of requiresScalarEpilogue (PR #108981)

Graham Hunter via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 17 07:55:51 PDT 2024


================
@@ -1388,32 +1388,42 @@ class LoopVectorizationCostModel {
 
   /// Returns true if we're required to use a scalar epilogue for at least
   /// the final iteration of the original loop.
-  bool requiresScalarEpilogue(bool IsVectorizing) const {
-    if (!isScalarEpilogueAllowed()) {
+  bool requiresScalarEpilogue(bool IsVectorizing) {
+    std::optional<bool> &CachedResult = RequiresScalarEpilogue[IsVectorizing];
+    if (CachedResult)
+      return *CachedResult;
+
+    auto NeedsScalarEpilogue = [&](bool IsVectorizing) -> bool {
----------------
huntergr-arm wrote:

I don't think the closure is necessary here. You could initialize Res to false here, then if `isScalarEpilogueAllowed()` evaluate the other conditions and set Res to true instead of returning true.

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


More information about the llvm-commits mailing list