[PATCH] D50233: [InstCombine] Transform str(n)cmp to memcmp

Dávid Bolvanský via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 3 14:22:30 PDT 2018


xbolva00 added inline comments.


================
Comment at: lib/Transforms/Utils/SimplifyLibCalls.cpp:155
+  if (!isOnlyUsedInZeroEqualityComparison(CI))
+    return false;
+
----------------
xbolva00 wrote:
> efriedma wrote:
> > xbolva00 wrote:
> > > efriedma wrote:
> > > > xbolva00 wrote:
> > > > > efriedma wrote:
> > > > > > Not sure why this check is relevant; memcmp should return the same value as strcmp.
> > > > > \0 in the middle of string?
> > > > > https://stackoverflow.com/questions/13095513/what-is-the-difference-between-memcmp-strcmp-and-strncmp-in-c
> > > > > 
> > > > > I think the check is probably right here..
> > > > I'm not sure what you mean... as far as I can tell, strcmp and memcmp should return the same result even if the non-constant string has an embedded null.  Can you give an example?  (I'm interpreting "same" here loosely to mean the same zero-ness and same sign bit.)
> > > Yeah, sign bit is same, but values are not. So need to check only if it is only used in condition
> > The C standard doesn't specify a specific return value; we don't have to return exactly the same value libc strcmp would return anyway, I think?  Haven't really thought through the implications of that.  It's okay to leave it for now.
> Oh no. strcmp(...) < -10 could be true, but memcmp(...) < - 10 is false.
But if rhs is zero, yes, we can lift that restriction for ne/eq only.


https://reviews.llvm.org/D50233





More information about the llvm-commits mailing list