[PATCH] D74079: [SimplifyLibCalls] Simplify __strlen_chk

George Burgess IV via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Feb 5 13:21:43 PST 2020


george.burgess.iv marked an inline comment as done.
george.burgess.iv added inline comments.


================
Comment at: llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp:3099
+      replaceAllUsesWith(CI, SimplifiedCI);
+
       // Use an IR Builder from SimplifiedCI if available instead of CI
----------------
jdoerfert wrote:
> I don't understand this change. Why is this necessary, e.g., why is `__strlen_chk` different from functions we optimize already?
Yeah, this is a bit subtle. :/

In general, it looks like `LibCallSimplifier` depends on `Use` information being complete in quite a few places. If we don't RAUW here, `SimplifiedCI` will incorrectly be considered to have no users.

This patch cares because `__strlen_chk` may return a newly-added `call @strlen()`. `optimizeStringMemoryLibCall` checks to see if all `User`s of  `strlen(s)` just compare its result to 0. If so, `strlen(s)` gets converted into `*s`. This optimization fires unconditionally for instructions with no `User`s.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D74079/new/

https://reviews.llvm.org/D74079





More information about the llvm-commits mailing list