This is an archive of the discontinued LLVM Phabricator instance.

[InstCombine] strncmp(x,y,strlen(x|y)+1) -> strcmp(x,y)
AbandonedPublic

Authored by xbolva00 on Jul 17 2019, 4:31 AM.

Details

Summary

Removes redundant strlen call since str(n)cmp does it too.

Diff Detail

Event Timeline

xbolva00 created this revision.Jul 17 2019, 4:31 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 17 2019, 4:31 AM
xbolva00 marked an inline comment as done.Jul 17 2019, 4:34 AM
xbolva00 added inline comments.
lib/Transforms/Utils/SimplifyLibCalls.cpp
391

Maybe I should extract this matching code for "strlen(x)+ 1" to helper static function now? Or later in followup folds?

xbolva00 updated this revision to Diff 210292.Jul 17 2019, 4:44 AM

Added multi-use tests.

xbolva00 updated this revision to Diff 210412.Jul 17 2019, 2:12 PM
efriedma added inline comments.Jul 30 2019, 2:22 PM
lib/Transforms/Utils/SimplifyLibCalls.cpp
391

It would be clearer to reorganize this.

I think "Length" is uninitialized along the "else" path? Or am I missing something?

405

It's not enough to check that the Strlen is a call to strlen; you also have to prove the memory isn't modified between the strlen call and the strncmp call.

xbolva00 accepted this revision.Jul 30 2019, 2:26 PM
xbolva00 marked an inline comment as done.
xbolva00 added inline comments.
lib/Transforms/Utils/SimplifyLibCalls.cpp
405

Ah yes! I forget about it. :(

I believe such analysis is not worth to do for this pattern.

Closing..

This revision is now accepted and ready to land.Jul 30 2019, 2:26 PM
xbolva00 abandoned this revision.Jul 30 2019, 2:26 PM