forked from OSchip/llvm-project
[SimplifyLibCalls] Fix comments about fputs, memchr, and s[n]printf. NFC
llvm-svn: 355905
This commit is contained in:
parent
1e249caaec
commit
f260967055
|
@ -776,7 +776,8 @@ Value *LibCallSimplifier::optimizeMemChr(CallInst *CI, IRBuilder<> &B) {
|
|||
// It would be really nice to reuse switch lowering here but we can't change
|
||||
// the CFG at this point.
|
||||
//
|
||||
// memchr("\r\n", C, 2) != nullptr -> (C & ((1 << '\r') | (1 << '\n'))) != 0
|
||||
// memchr("\r\n", C, 2) != nullptr -> (1 << C & ((1 << '\r') | (1 << '\n')))
|
||||
// != 0
|
||||
// after bounds check.
|
||||
if (!CharC && !Str.empty() && isOnlyUsedInZeroEqualityComparison(CI)) {
|
||||
unsigned char Max =
|
||||
|
@ -921,7 +922,7 @@ Value *LibCallSimplifier::optimizeMemCmp(CallInst *CI, IRBuilder<> &B) {
|
|||
|
||||
// memcmp(x, y, Len) == 0 -> bcmp(x, y, Len) == 0
|
||||
// `bcmp` can be more efficient than memcmp because it only has to know that
|
||||
// there is a difference, not where is is.
|
||||
// there is a difference, not where it is.
|
||||
if (isOnlyUsedInZeroEqualityComparison(CI) && TLI->has(LibFunc_bcmp)) {
|
||||
return emitBCmp(LHS, RHS, Size, B, DL, TLI);
|
||||
}
|
||||
|
@ -2094,7 +2095,8 @@ Value *LibCallSimplifier::optimizeSPrintFString(CallInst *CI, IRBuilder<> &B) {
|
|||
}
|
||||
|
||||
if (FormatStr[1] == 's') {
|
||||
// sprintf(dest, "%s", str) -> llvm.memcpy(dest, str, strlen(str)+1, 1)
|
||||
// sprintf(dest, "%s", str) -> llvm.memcpy(align 1 dest, align 1 str,
|
||||
// strlen(str)+1)
|
||||
if (!CI->getArgOperand(2)->getType()->isPointerTy())
|
||||
return nullptr;
|
||||
|
||||
|
@ -2157,7 +2159,7 @@ Value *LibCallSimplifier::optimizeSnPrintFString(CallInst *CI, IRBuilder<> &B) {
|
|||
else if (N < FormatStr.size() + 1)
|
||||
return nullptr;
|
||||
|
||||
// sprintf(str, size, fmt) -> llvm.memcpy(align 1 str, align 1 fmt,
|
||||
// snprintf(dst, size, fmt) -> llvm.memcpy(align 1 dst, align 1 fmt,
|
||||
// strlen(fmt)+1)
|
||||
B.CreateMemCpy(
|
||||
CI->getArgOperand(0), 1, CI->getArgOperand(2), 1,
|
||||
|
@ -2338,7 +2340,7 @@ Value *LibCallSimplifier::optimizeFPuts(CallInst *CI, IRBuilder<> &B) {
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
// fputs(s,F) --> fwrite(s,1,strlen(s),F)
|
||||
// fputs(s,F) --> fwrite(s,strlen(s),1,F)
|
||||
uint64_t Len = GetStringLength(CI->getArgOperand(0));
|
||||
if (!Len)
|
||||
return nullptr;
|
||||
|
|
|
@ -12,7 +12,7 @@ target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f3
|
|||
|
||||
declare i32 @fputs(i8*, %FILE*)
|
||||
|
||||
; Check fputs(str, fp) --> fwrite(str, 1, strlen(s), fp).
|
||||
; Check fputs(str, fp) --> fwrite(str, strlen(s), 1, fp).
|
||||
|
||||
define void @test_simplify1(%FILE* %fp) {
|
||||
; CHECK-LABEL: @test_simplify1(
|
||||
|
|
Loading…
Reference in New Issue