[llvm] [Transforms] LoopIdiomRecognize recognize strlen and wcslen (PR #108985)
via llvm-commits
llvm-commits at lists.llvm.org
Fri Oct 11 10:50:11 PDT 2024
================
@@ -1524,6 +1545,232 @@ static Value *matchCondition(BranchInst *BI, BasicBlock *LoopEntry,
return nullptr;
}
+/// Recognizes a strlen idiom by checking for loops that increment
+/// a char pointer and then subtract with the base pointer.
+///
+/// If detected, transforms the relevant code to a strlen function
+/// call, and returns true; otherwise, returns false.
+///
+/// The core idiom we are trying to detect is:
+/// \code
----------------
RolandF77 wrote:
I think a clearer explanation of what this function does and how it works is needed. The idiom detected is compute the end address of a string. An instance of a strlen computation that has an end address computation of the expected form will be end addr - start addr which will become strlen + start addr - start addr.
https://github.com/llvm/llvm-project/pull/108985
More information about the llvm-commits
mailing list