diff options
author | Henry Jiang <h243jian@uwaterloo.ca> | 2025-03-14 18:56:34 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-03-14 18:56:34 -0400 |
commit | bf6357f0f51eccc48b92a130afb51c0280d56180 (patch) | |
tree | 81673c84d20773f818bcfb5a09ca6ac152617303 /llvm/lib/Transforms/Utils/BuildLibCalls.cpp | |
parent | 89889149cd21bb70c9a545fc18c1bfc1467b1b04 (diff) | |
download | llvm-bf6357f0f51eccc48b92a130afb51c0280d56180.zip llvm-bf6357f0f51eccc48b92a130afb51c0280d56180.tar.gz llvm-bf6357f0f51eccc48b92a130afb51c0280d56180.tar.bz2 |
[Transforms] LoopIdiomRecognize recognize strlen and wcslen (#108985)
This PR continues the effort made in
https://discourse.llvm.org/t/rfc-strlen-loop-idiom-recognition-folding/55848
and https://reviews.llvm.org/D83392 and https://reviews.llvm.org/D88460
to extend `LoopIdiomRecognize` to find and replace loops of the form
```c
base = str;
while (*str)
++str;
```
and transforming the `strlen` loop idiom into the appropriate `strlen`
and `wcslen` library call which will give a small performance boost if
replaced.
```c
str = base + strlen(base)
len = str - base
```
---------
Co-authored-by: Michael Kruse <github@meinersbur.de>
Diffstat (limited to 'llvm/lib/Transforms/Utils/BuildLibCalls.cpp')
-rw-r--r-- | llvm/lib/Transforms/Utils/BuildLibCalls.cpp | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/llvm/lib/Transforms/Utils/BuildLibCalls.cpp b/llvm/lib/Transforms/Utils/BuildLibCalls.cpp index 2301be6..24eefc9 100644 --- a/llvm/lib/Transforms/Utils/BuildLibCalls.cpp +++ b/llvm/lib/Transforms/Utils/BuildLibCalls.cpp @@ -1582,6 +1582,15 @@ Value *llvm::emitStrLen(Value *Ptr, IRBuilderBase &B, const DataLayout &DL, return emitLibCall(LibFunc_strlen, SizeTTy, CharPtrTy, Ptr, B, TLI); } +Value *llvm::emitWcsLen(Value *Ptr, IRBuilderBase &B, const DataLayout &DL, + const TargetLibraryInfo *TLI) { + assert(Ptr && Ptr->getType()->isPointerTy() && + "Argument to wcslen intrinsic must be a pointer."); + Type *PtrTy = B.getPtrTy(); + Type *SizeTTy = getSizeTTy(B, TLI); + return emitLibCall(LibFunc_wcslen, SizeTTy, PtrTy, Ptr, B, TLI); +} + Value *llvm::emitStrDup(Value *Ptr, IRBuilderBase &B, const TargetLibraryInfo *TLI) { Type *CharPtrTy = B.getPtrTy(); |