[PATCH] D74079: [SimplifyLibCalls] Simplify __strlen_chk

Johannes Doerfert via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sat Feb 8 11:22:44 PST 2020


jdoerfert accepted this revision.
jdoerfert added a comment.
This revision is now accepted and ready to land.

LGTM.



================
Comment at: llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp:3099
+      replaceAllUsesWith(CI, SimplifiedCI);
+
       // Use an IR Builder from SimplifiedCI if available instead of CI
----------------
george.burgess.iv wrote:
> 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.
I see (, I think). Thanks.


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

https://reviews.llvm.org/D74079





More information about the llvm-commits mailing list