// fold strstr(x, x) -> x.
if (CI->getOperand(1) == CI->getOperand(2))
- return CI->getOperand(1);
+ return B.CreateBitCast(CI->getOperand(1), CI->getType());
// See if either input string is a constant string.
std::string SearchStr, ToFindStr;
if (Offset == std::string::npos) // strstr("foo", "bar") -> null
return Constant::getNullValue(CI->getType());
- // strstr("abcd", "bc") -> gep((char*)"abcd", 2)
+ // strstr("abcd", "bc") -> gep((char*)"abcd", 1)
Value *Result = CastToCStr(CI->getOperand(1), B);
Result = B.CreateConstInBoundsGEP1_64(Result, Offset, "strstr");
return B.CreateBitCast(Result, CI->getType());