This is an archive of the discontinued LLVM Phabricator instance.

[SimplifyLibCalls] Simplify __strlen_chk
ClosedPublic

Authored by george.burgess.iv on Feb 5 2020, 11:09 AM.

Details

Summary

Bionic has had __strlen_chk for quite a while; its goal is to catch overflows of unterminated strings.

This CL allows LLVM to optimize that to strlen where appropriate.

Diff Detail

Event Timeline

jdoerfert added inline comments.Feb 5 2020, 12:45 PM
llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
3099

I don't understand this change. Why is this necessary, e.g., why is __strlen_chk different from functions we optimize already?

george.burgess.iv marked an inline comment as done.Feb 5 2020, 1:21 PM
george.burgess.iv added inline comments.
llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
3099

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 Users 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 Users.

jdoerfert accepted this revision.Feb 8 2020, 11:19 AM

LGTM.

llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
3099

I see (, I think). Thanks.

This revision is now accepted and ready to land.Feb 8 2020, 11:19 AM

Thanks for the review!

This revision was automatically updated to reflect the committed changes.