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

Eli Friedman via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 30 14:23:26 PDT 2019


efriedma added inline comments.


================
Comment at: lib/Transforms/Utils/SimplifyLibCalls.cpp:391
+  } else {
+    // strncmp(x,y,strlen(x|y)+1) -> strcmp(x,y)
+    Value *Call;
----------------
xbolva00 wrote:
> Maybe I should extract this matching code for "strlen(x)+ 1" to helper static function now? Or later in followup folds?
> 
It would be clearer to reorganize this.

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


================
Comment at: lib/Transforms/Utils/SimplifyLibCalls.cpp:405
+      if (!TLI->getLibFunc(*InnerCallee, Func) || !TLI->has(Func) ||
+          Func != LibFunc_strlen)
+        return nullptr;
----------------
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.


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

https://reviews.llvm.org/D64859





More information about the llvm-commits mailing list