[flang-commits] [flang] 39f6d83 - [flang] Speed up folding of LEN_TRIM()

Peter Klausler via flang-commits flang-commits at lists.llvm.org
Sat Oct 29 14:08:14 PDT 2022


Author: Peter Klausler
Date: 2022-10-29T13:26:42-07:00
New Revision: 39f6d8334522ee5baefeae49be5bf1a3d6163e9f

URL: https://github.com/llvm/llvm-project/commit/39f6d8334522ee5baefeae49be5bf1a3d6163e9f
DIFF: https://github.com/llvm/llvm-project/commit/39f6d8334522ee5baefeae49be5bf1a3d6163e9f.diff

LOG: [flang] Speed up folding of LEN_TRIM()

LEN_TRIM's folding is currently based on VERIFY(), and it is kind of
slow for the very large CHARACTER arguments that can show up in artificial
test suites.  Rewrite in terms of single-character accesses.

Differential Revision: https://reviews.llvm.org/D136901

Added: 
    

Modified: 
    flang/lib/Evaluate/character.h

Removed: 
    


################################################################################
diff  --git a/flang/lib/Evaluate/character.h b/flang/lib/Evaluate/character.h
index f5464c733445..794872605956 100644
--- a/flang/lib/Evaluate/character.h
+++ b/flang/lib/Evaluate/character.h
@@ -94,7 +94,13 @@ template <int KIND> class CharacterUtils {
   }
 
   static ConstantSubscript LEN_TRIM(const Character &str) {
-    return VERIFY(str, Character{' '}, true);
+    auto j{str.length()};
+    for (; j >= 1; --j) {
+      if (str[j - 1] != ' ') {
+        break;
+      }
+    }
+    return static_cast<ConstantSubscript>(j);
   }
 
   static Character REPEAT(const Character &str, ConstantSubscript ncopies) {


        


More information about the flang-commits mailing list