@@ -212,7 +212,7 @@ Value *LibCallSimplifier::optimizeStrCat(CallInst *CI, IRBuilderBase &B) {
212
212
annotateNonNullNoUndefBasedOnAccess (CI, {0 , 1 });
213
213
214
214
// See if we can get the length of the input string.
215
- uint64_t Len = GetStringLength (Src);
215
+ uint64_t Len = GetStringLength (Src, TLI );
216
216
if (Len)
217
217
annotateDereferenceableBytes (CI, 1 , Len);
218
218
else
@@ -269,7 +269,7 @@ Value *LibCallSimplifier::optimizeStrNCat(CallInst *CI, IRBuilderBase &B) {
269
269
}
270
270
271
271
// See if we can get the length of the input string.
272
- uint64_t SrcLen = GetStringLength (Src);
272
+ uint64_t SrcLen = GetStringLength (Src, TLI );
273
273
if (SrcLen) {
274
274
annotateDereferenceableBytes (CI, 1 , SrcLen);
275
275
--SrcLen; // Unbias length.
@@ -300,7 +300,7 @@ Value *LibCallSimplifier::optimizeStrChr(CallInst *CI, IRBuilderBase &B) {
300
300
// of the input string and turn this into memchr.
301
301
ConstantInt *CharC = dyn_cast<ConstantInt>(CI->getArgOperand (1 ));
302
302
if (!CharC) {
303
- uint64_t Len = GetStringLength (SrcStr);
303
+ uint64_t Len = GetStringLength (SrcStr, TLI );
304
304
if (Len)
305
305
annotateDereferenceableBytes (CI, 0 , Len);
306
306
else
@@ -387,10 +387,10 @@ Value *LibCallSimplifier::optimizeStrCmp(CallInst *CI, IRBuilderBase &B) {
387
387
CI->getType ());
388
388
389
389
// strcmp(P, "x") -> memcmp(P, "x", 2)
390
- uint64_t Len1 = GetStringLength (Str1P);
390
+ uint64_t Len1 = GetStringLength (Str1P, TLI );
391
391
if (Len1)
392
392
annotateDereferenceableBytes (CI, 0 , Len1);
393
- uint64_t Len2 = GetStringLength (Str2P);
393
+ uint64_t Len2 = GetStringLength (Str2P, TLI );
394
394
if (Len2)
395
395
annotateDereferenceableBytes (CI, 1 , Len2);
396
396
@@ -464,10 +464,10 @@ Value *LibCallSimplifier::optimizeStrNCmp(CallInst *CI, IRBuilderBase &B) {
464
464
return B.CreateZExt (B.CreateLoad (B.getInt8Ty (), Str1P, " strcmpload" ),
465
465
CI->getType ());
466
466
467
- uint64_t Len1 = GetStringLength (Str1P);
467
+ uint64_t Len1 = GetStringLength (Str1P, TLI );
468
468
if (Len1)
469
469
annotateDereferenceableBytes (CI, 0 , Len1);
470
- uint64_t Len2 = GetStringLength (Str2P);
470
+ uint64_t Len2 = GetStringLength (Str2P, TLI );
471
471
if (Len2)
472
472
annotateDereferenceableBytes (CI, 1 , Len2);
473
473
@@ -496,7 +496,7 @@ Value *LibCallSimplifier::optimizeStrNCmp(CallInst *CI, IRBuilderBase &B) {
496
496
Value *LibCallSimplifier::optimizeStrNDup (CallInst *CI, IRBuilderBase &B) {
497
497
Value *Src = CI->getArgOperand (0 );
498
498
ConstantInt *Size = dyn_cast<ConstantInt>(CI->getArgOperand (1 ));
499
- uint64_t SrcLen = GetStringLength (Src);
499
+ uint64_t SrcLen = GetStringLength (Src, TLI );
500
500
if (SrcLen && Size) {
501
501
annotateDereferenceableBytes (CI, 0 , SrcLen);
502
502
if (SrcLen <= Size->getZExtValue () + 1 )
@@ -513,7 +513,7 @@ Value *LibCallSimplifier::optimizeStrCpy(CallInst *CI, IRBuilderBase &B) {
513
513
514
514
annotateNonNullNoUndefBasedOnAccess (CI, {0 , 1 });
515
515
// See if we can get the length of the input string.
516
- uint64_t Len = GetStringLength (Src);
516
+ uint64_t Len = GetStringLength (Src, TLI );
517
517
if (Len)
518
518
annotateDereferenceableBytes (CI, 1 , Len);
519
519
else
@@ -544,7 +544,7 @@ Value *LibCallSimplifier::optimizeStpCpy(CallInst *CI, IRBuilderBase &B) {
544
544
}
545
545
546
546
// See if we can get the length of the input string.
547
- uint64_t Len = GetStringLength (Src);
547
+ uint64_t Len = GetStringLength (Src, TLI );
548
548
if (Len)
549
549
annotateDereferenceableBytes (CI, 1 , Len);
550
550
else
@@ -584,7 +584,7 @@ Value *LibCallSimplifier::optimizeStrNCpy(CallInst *CI, IRBuilderBase &B) {
584
584
return Dst;
585
585
586
586
// See if we can get the length of the input string.
587
- uint64_t SrcLen = GetStringLength (Src);
587
+ uint64_t SrcLen = GetStringLength (Src, TLI );
588
588
if (SrcLen) {
589
589
annotateDereferenceableBytes (CI, 1 , SrcLen);
590
590
--SrcLen; // Unbias length.
@@ -633,7 +633,7 @@ Value *LibCallSimplifier::optimizeStringLength(CallInst *CI, IRBuilderBase &B,
633
633
Value *Src = CI->getArgOperand (0 );
634
634
635
635
// Constant folding: strlen("xyz") -> 3
636
- if (uint64_t Len = GetStringLength (Src, CharSize))
636
+ if (uint64_t Len = GetStringLength (Src, TLI, CharSize))
637
637
return ConstantInt::get (CI->getType (), Len - 1 );
638
638
639
639
// If s is a constant pointer pointing to a string literal, we can fold
@@ -688,8 +688,8 @@ Value *LibCallSimplifier::optimizeStringLength(CallInst *CI, IRBuilderBase &B,
688
688
689
689
// strlen(x?"foo":"bars") --> x ? 3 : 4
690
690
if (SelectInst *SI = dyn_cast<SelectInst>(Src)) {
691
- uint64_t LenTrue = GetStringLength (SI->getTrueValue (), CharSize);
692
- uint64_t LenFalse = GetStringLength (SI->getFalseValue (), CharSize);
691
+ uint64_t LenTrue = GetStringLength (SI->getTrueValue (), TLI, CharSize);
692
+ uint64_t LenFalse = GetStringLength (SI->getFalseValue (), TLI, CharSize);
693
693
if (LenTrue && LenFalse) {
694
694
ORE.emit ([&]() {
695
695
return OptimizationRemark (" instcombine" , " simplify-libcalls" , CI)
@@ -2511,7 +2511,7 @@ Value *LibCallSimplifier::optimizeSPrintFString(CallInst *CI,
2511
2511
// sprintf(dest, "%s", str) -> strcpy(dest, str)
2512
2512
return copyFlags (*CI, emitStrCpy (Dest, CI->getArgOperand (2 ), B, TLI));
2513
2513
2514
- uint64_t SrcLen = GetStringLength (CI->getArgOperand (2 ));
2514
+ uint64_t SrcLen = GetStringLength (CI->getArgOperand (2 ), TLI );
2515
2515
if (SrcLen) {
2516
2516
B.CreateMemCpy (
2517
2517
Dest, Align (1 ), CI->getArgOperand (2 ), Align (1 ),
@@ -2803,7 +2803,7 @@ Value *LibCallSimplifier::optimizeFPuts(CallInst *CI, IRBuilderBase &B) {
2803
2803
return nullptr ;
2804
2804
2805
2805
// fputs(s,F) --> fwrite(s,strlen(s),1,F)
2806
- uint64_t Len = GetStringLength (CI->getArgOperand (0 ));
2806
+ uint64_t Len = GetStringLength (CI->getArgOperand (0 ), TLI );
2807
2807
if (!Len)
2808
2808
return nullptr ;
2809
2809
@@ -3247,7 +3247,7 @@ FortifiedLibCallSimplifier::isFortifiedCallFoldable(CallInst *CI,
3247
3247
if (OnlyLowerUnknownSize)
3248
3248
return false ;
3249
3249
if (StrOp) {
3250
- uint64_t Len = GetStringLength (CI->getArgOperand (*StrOp));
3250
+ uint64_t Len = GetStringLength (CI->getArgOperand (*StrOp), TLI );
3251
3251
// If the length is 0 we don't know how long it is and so we can't
3252
3252
// remove the check.
3253
3253
if (Len)
@@ -3351,7 +3351,7 @@ Value *FortifiedLibCallSimplifier::optimizeStrpCpyChk(CallInst *CI,
3351
3351
return nullptr ;
3352
3352
3353
3353
// Maybe we can stil fold __st[rp]cpy_chk to __memcpy_chk.
3354
- uint64_t Len = GetStringLength (Src);
3354
+ uint64_t Len = GetStringLength (Src, TLI );
3355
3355
if (Len)
3356
3356
annotateDereferenceableBytes (CI, 1 , Len);
3357
3357
else
0 commit comments