[PATCH] D18230: [SimplifyLibCalls] Simplify strlen to a subtraction for certain cases
Li Huang via llvm-commits
llvm-commits at lists.llvm.org
Wed Mar 16 15:02:18 PDT 2016
lihuang created this revision.
lihuang added reviewers: spatel, DavidKreitzer.
lihuang added a subscriber: llvm-commits.
This patch implements this optimization:
strlen(s + x) --> strlen(s) - x,
where s is a pointer to a string literal, and x is an integer variable. Note that strlen(s) is a constant which is known at compile time. This optimization is legal when one of the following is true:
A. x is known to be within the range [0, strlen(s)]
B. The string literal is null-terminated and has only one null terminator "\0" at its end, and (s + x) is proved to be an out-of-bound pointer when x < 0 or x > strlen(s).
Case A is straightforward. For case B, it's legal to do this optimization because strlen will have undefined behavior when (s + x) is out of bound.
-------------- next part --------------
A non-text attachment was scrubbed...
Size: 5432 bytes
Desc: not available
More information about the llvm-commits