@@ -160,7 +160,7 @@ Value *LibCallSimplifier::optimizeStrCat(CallInst *CI, IRBuilder<> &B) {
160
160
Value *Src = CI->getArgOperand (1 );
161
161
162
162
// See if we can get the length of the input string.
163
- uint64_t Len = GetStringLength (Src);
163
+ uint64_t Len = GetStringLength (Src, TLI );
164
164
if (Len == 0 )
165
165
return nullptr ;
166
166
--Len; // Unbias length.
@@ -205,7 +205,7 @@ Value *LibCallSimplifier::optimizeStrNCat(CallInst *CI, IRBuilder<> &B) {
205
205
return nullptr ;
206
206
207
207
// See if we can get the length of the input string.
208
- uint64_t SrcLen = GetStringLength (Src);
208
+ uint64_t SrcLen = GetStringLength (Src, TLI );
209
209
if (SrcLen == 0 )
210
210
return nullptr ;
211
211
--SrcLen; // Unbias length.
@@ -234,7 +234,7 @@ Value *LibCallSimplifier::optimizeStrChr(CallInst *CI, IRBuilder<> &B) {
234
234
// of the input string and turn this into memchr.
235
235
ConstantInt *CharC = dyn_cast<ConstantInt>(CI->getArgOperand (1 ));
236
236
if (!CharC) {
237
- uint64_t Len = GetStringLength (SrcStr);
237
+ uint64_t Len = GetStringLength (SrcStr, TLI );
238
238
if (Len == 0 || !FT->getParamType (1 )->isIntegerTy (32 )) // memchr needs i32.
239
239
return nullptr ;
240
240
@@ -313,8 +313,8 @@ Value *LibCallSimplifier::optimizeStrCmp(CallInst *CI, IRBuilder<> &B) {
313
313
return B.CreateZExt (B.CreateLoad (Str1P, " strcmpload" ), CI->getType ());
314
314
315
315
// strcmp(P, "x") -> memcmp(P, "x", 2)
316
- uint64_t Len1 = GetStringLength (Str1P);
317
- uint64_t Len2 = GetStringLength (Str2P);
316
+ uint64_t Len1 = GetStringLength (Str1P, TLI );
317
+ uint64_t Len2 = GetStringLength (Str2P, TLI );
318
318
if (Len1 && Len2) {
319
319
return emitMemCmp (Str1P, Str2P,
320
320
ConstantInt::get (DL.getIntPtrType (CI->getContext ()),
@@ -370,7 +370,7 @@ Value *LibCallSimplifier::optimizeStrCpy(CallInst *CI, IRBuilder<> &B) {
370
370
return Src;
371
371
372
372
// See if we can get the length of the input string.
373
- uint64_t Len = GetStringLength (Src);
373
+ uint64_t Len = GetStringLength (Src, TLI );
374
374
if (Len == 0 )
375
375
return nullptr ;
376
376
@@ -390,7 +390,7 @@ Value *LibCallSimplifier::optimizeStpCpy(CallInst *CI, IRBuilder<> &B) {
390
390
}
391
391
392
392
// See if we can get the length of the input string.
393
- uint64_t Len = GetStringLength (Src);
393
+ uint64_t Len = GetStringLength (Src, TLI );
394
394
if (Len == 0 )
395
395
return nullptr ;
396
396
@@ -412,7 +412,7 @@ Value *LibCallSimplifier::optimizeStrNCpy(CallInst *CI, IRBuilder<> &B) {
412
412
Value *LenOp = CI->getArgOperand (2 );
413
413
414
414
// See if we can get the length of the input string.
415
- uint64_t SrcLen = GetStringLength (Src);
415
+ uint64_t SrcLen = GetStringLength (Src, TLI );
416
416
if (SrcLen == 0 )
417
417
return nullptr ;
418
418
--SrcLen;
@@ -448,7 +448,7 @@ Value *LibCallSimplifier::optimizeStringLength(CallInst *CI, IRBuilder<> &B,
448
448
Value *Src = CI->getArgOperand (0 );
449
449
450
450
// Constant folding: strlen("xyz") -> 3
451
- if (uint64_t Len = GetStringLength (Src, CharSize))
451
+ if (uint64_t Len = GetStringLength (Src, TLI, CharSize))
452
452
return ConstantInt::get (CI->getType (), Len - 1 );
453
453
454
454
// If s is a constant pointer pointing to a string literal, we can fold
@@ -512,8 +512,8 @@ Value *LibCallSimplifier::optimizeStringLength(CallInst *CI, IRBuilder<> &B,
512
512
513
513
// strlen(x?"foo":"bars") --> x ? 3 : 4
514
514
if (SelectInst *SI = dyn_cast<SelectInst>(Src)) {
515
- uint64_t LenTrue = GetStringLength (SI->getTrueValue (), CharSize);
516
- uint64_t LenFalse = GetStringLength (SI->getFalseValue (), CharSize);
515
+ uint64_t LenTrue = GetStringLength (SI->getTrueValue (), TLI, CharSize);
516
+ uint64_t LenFalse = GetStringLength (SI->getFalseValue (), TLI, CharSize);
517
517
if (LenTrue && LenFalse) {
518
518
ORE.emit ([&]() {
519
519
return OptimizationRemark (" instcombine" , " simplify-libcalls" , CI)
@@ -2142,7 +2142,7 @@ Value *LibCallSimplifier::optimizeFPuts(CallInst *CI, IRBuilder<> &B) {
2142
2142
}
2143
2143
2144
2144
// fputs(s,F) --> fwrite(s,1,strlen(s),F)
2145
- uint64_t Len = GetStringLength (CI->getArgOperand (0 ));
2145
+ uint64_t Len = GetStringLength (CI->getArgOperand (0 ), TLI );
2146
2146
if (!Len)
2147
2147
return nullptr ;
2148
2148
@@ -2565,7 +2565,7 @@ bool FortifiedLibCallSimplifier::isFortifiedCallFoldable(CallInst *CI,
2565
2565
if (OnlyLowerUnknownSize)
2566
2566
return false ;
2567
2567
if (isString) {
2568
- uint64_t Len = GetStringLength (CI->getArgOperand (SizeOp));
2568
+ uint64_t Len = GetStringLength (CI->getArgOperand (SizeOp), TLI );
2569
2569
// If the length is 0 we don't know how long it is and so we can't
2570
2570
// remove the check.
2571
2571
if (Len == 0 )
@@ -2637,7 +2637,7 @@ Value *FortifiedLibCallSimplifier::optimizeStrpCpyChk(CallInst *CI,
2637
2637
return nullptr ;
2638
2638
2639
2639
// Maybe we can stil fold __st[rp]cpy_chk to __memcpy_chk.
2640
- uint64_t Len = GetStringLength (Src);
2640
+ uint64_t Len = GetStringLength (Src, TLI );
2641
2641
if (Len == 0 )
2642
2642
return nullptr ;
2643
2643
@@ -2716,4 +2716,4 @@ Value *FortifiedLibCallSimplifier::optimizeCall(CallInst *CI) {
2716
2716
2717
2717
FortifiedLibCallSimplifier::FortifiedLibCallSimplifier (
2718
2718
const TargetLibraryInfo *TLI, bool OnlyLowerUnknownSize)
2719
- : TLI(TLI), OnlyLowerUnknownSize(OnlyLowerUnknownSize) {}
2719
+ : TLI(TLI), OnlyLowerUnknownSize(OnlyLowerUnknownSize) {}
0 commit comments