diff options
author | Henry Jiang <h243jian@uwaterloo.ca> | 2025-03-24 09:49:31 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-03-24 09:49:31 -0400 |
commit | 9694844d7e36fd5e01011ab56b64f27b867aa72d (patch) | |
tree | f939f742ecf6c472eae2a0391777b158eb0817bd /llvm/lib/Transforms/Utils/BuildLibCalls.cpp | |
parent | ed022d93b2fbfe52b7bdee786aa5cc49fa2323c4 (diff) | |
download | llvm-9694844d7e36fd5e01011ab56b64f27b867aa72d.zip llvm-9694844d7e36fd5e01011ab56b64f27b867aa72d.tar.gz llvm-9694844d7e36fd5e01011ab56b64f27b867aa72d.tar.bz2 |
Reland "[Transforms] LoopIdiomRecognize recognize strlen and wcslen #108985" (#132572)
Reland https://github.com/llvm/llvm-project/pull/108985
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
```
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(); |