Starting with code like this
void lib_memset( unsigned char *dest, unsigned char c, unsigned int n)
{
while(n--)
{
*dest=c;
dest++;
I encounter the same problem and if it still can help anyone this is what I did to solve it - I modify the LoopIdiomRecognize.cpp file in the llvm source code: there is a code that checks if the name of the function is memset or memcpy it cancel the optimization, so I changed it from:
StringRef Name = L->getHeader()->getParent()->getName();
if (Name == "memset" || Name == "memcpy")
to
StringRef Name = L->getHeader()->getParent()->getName();
if (Name.endswith("memset") || Name == "memcpy")