[flang-commits] [PATCH] D136901: [flang] Speed up folding of LEN_TRIM()

Peter Klausler via Phabricator via flang-commits flang-commits at lists.llvm.org
Thu Oct 27 16:35:33 PDT 2022


klausler created this revision.
klausler added a reviewer: jeanPerier.
klausler added a project: Flang.
Herald added a subscriber: jdoerfert.
Herald added a project: All.
klausler requested review of this revision.

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.


https://reviews.llvm.org/D136901

Files:
  flang/lib/Evaluate/character.h


Index: flang/lib/Evaluate/character.h
===================================================================
--- flang/lib/Evaluate/character.h
+++ flang/lib/Evaluate/character.h
@@ -94,7 +94,13 @@
   }
 
   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) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D136901.471324.patch
Type: text/x-patch
Size: 560 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/flang-commits/attachments/20221027/ba93235a/attachment.bin>


More information about the flang-commits mailing list