Refactor the strlen optimization code to work for both strlen and wcslen.
This especially helps with programs in the wild where people pass L"string"s to const std::wstring& function parameters and the wstring constructor gets inlined.
Paths
| Differential D32839
SimplifyLibCalls: Optimize wcslen ClosedPublic Authored by MatzeB on May 3 2017, 4:45 PM.
Details Summary Refactor the strlen optimization code to work for both strlen and wcslen. This especially helps with programs in the wild where people pass L"string"s to const std::wstring& function parameters and the wstring constructor gets inlined.
Diff Detail
Event Timelineefriedma added inline comments.
MatzeB added inline comments.
MatzeB marked an inline comment as done. Comment Actions
MatzeB added inline comments.
MatzeB marked 3 inline comments as done. Comment Actions
Comment Actions clang only emits wchar_size on ARM at the moment; that might need to change before this gets merged. Missing tests for 16-bit wchar_t.
MatzeB added a child revision: D32982: CodeGenModule: Always output wchar_size; check LLVM assumptions..May 8 2017, 3:39 PM Comment Actions
This revision is now accepted and ready to land.May 19 2017, 12:10 PM Comment Actions Fixing getConstantStringInfo() here caused some changes in behavior in SelectionDAG memcpy lowering. I'll put in some more fixes before committing... Closed by commit rL303461: SimplifyLibCalls: Optimize wcslen (authored by matze). ยท Explain WhyMay 19 2017, 3:50 PM This revision was automatically updated to reflect the committed changes.
Revision Contents
Diff 98005 include/llvm/Analysis/TargetLibraryInfo.h
include/llvm/Analysis/ValueTracking.h
include/llvm/IR/Constants.h
include/llvm/Transforms/Utils/SimplifyLibCalls.h
lib/Analysis/TargetLibraryInfo.cpp
lib/Analysis/ValueTracking.cpp
lib/IR/Constants.cpp
lib/Transforms/Utils/SimplifyLibCalls.cpp
test/Transforms/InstCombine/wcslen-1.ll
test/Transforms/InstCombine/wcslen-2.ll
|
We should probably have a verifier check to make sure these casts will succeed.