[PATCH] D32839: SimplifyLibCalls: Optimize wcslen

Eli Friedman via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri May 5 13:41:57 PDT 2017


efriedma added inline comments.


================
Comment at: lib/Analysis/TargetLibraryInfo.cpp:1420
+      M.getModuleFlag("wchar_size")))
+    return cast<ConstantInt>(ShortWChar->getValue())->getZExtValue();
+  return getTargetWCharSize(Triple(M.getTargetTriple()));
----------------
We should probably have a verifier check to make sure these casts will succeed.


================
Comment at: lib/Analysis/ValueTracking.cpp:3043
+      Slice.Offset = 0;
+      Slice.Length = 1;
+      return true;
----------------
Do you need to check the type against ElementSize here?


================
Comment at: lib/Transforms/Utils/SimplifyLibCalls.cpp:458
+             I < E; ++I) {
+          if (Index.Array->getElementAsInteger(I) == 0) {
+            NullTermIdx = I;
----------------
MatzeB wrote:
> efriedma wrote:
> > Could you use an iterator which returns the elements of the ConstantDataArray, instead of using explicit indexing everywhere?
> There are no iterators defined for ConstantDataArray, did I miss something? (Defining them seems tricky to get right to support various datatypes and target/host data conversions).
No, there aren't any existing iterators.

It doesn't seem that tricky to write, though.  It could just be a wrapper around getElementAsInteger; or if you want to get fancy, you could represent it as a pointer+width pair, I guess.  (The data is just an array of integers in host byte order.)


Repository:
  rL LLVM

https://reviews.llvm.org/D32839





More information about the llvm-commits mailing list