Skip to content

Commit 2ac6b26

Browse files
committed
[llvm][Transforms][Utils] Remove no-op ptr-to-ptr bitcasts (NFC)
Opaque ptr cleanup effort (NFC).
1 parent a0a41d1 commit 2ac6b26

File tree

2 files changed

+7
-12
lines changed

2 files changed

+7
-12
lines changed

llvm/lib/Transforms/Utils/InlineFunction.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1951,8 +1951,7 @@ inlineRetainOrClaimRVCalls(CallBase &CB, objcarc::ARCInstKind RVCallKind,
19511951
Builder.SetInsertPoint(II);
19521952
Function *IFn =
19531953
Intrinsic::getDeclaration(Mod, Intrinsic::objc_release);
1954-
Value *BC = Builder.CreateBitCast(RetOpnd, IFn->getArg(0)->getType());
1955-
Builder.CreateCall(IFn, BC, "");
1954+
Builder.CreateCall(IFn, RetOpnd, "");
19561955
}
19571956
II->eraseFromParent();
19581957
InsertRetainCall = false;
@@ -1987,8 +1986,7 @@ inlineRetainOrClaimRVCalls(CallBase &CB, objcarc::ARCInstKind RVCallKind,
19871986
// to objc_retain.
19881987
Builder.SetInsertPoint(RI);
19891988
Function *IFn = Intrinsic::getDeclaration(Mod, Intrinsic::objc_retain);
1990-
Value *BC = Builder.CreateBitCast(RetOpnd, IFn->getArg(0)->getType());
1991-
Builder.CreateCall(IFn, BC, "");
1989+
Builder.CreateCall(IFn, RetOpnd, "");
19921990
}
19931991
}
19941992
}

llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1148,7 +1148,7 @@ Value *LibCallSimplifier::optimizeStrCSpn(CallInst *CI, IRBuilderBase &B) {
11481148
Value *LibCallSimplifier::optimizeStrStr(CallInst *CI, IRBuilderBase &B) {
11491149
// fold strstr(x, x) -> x.
11501150
if (CI->getArgOperand(0) == CI->getArgOperand(1))
1151-
return B.CreateBitCast(CI->getArgOperand(0), CI->getType());
1151+
return CI->getArgOperand(0);
11521152

11531153
// fold strstr(a, b) == a -> strncmp(a, b, strlen(b)) == 0
11541154
if (isOnlyUsedInEqualityComparison(CI, CI->getArgOperand(0))) {
@@ -1176,7 +1176,7 @@ Value *LibCallSimplifier::optimizeStrStr(CallInst *CI, IRBuilderBase &B) {
11761176

11771177
// fold strstr(x, "") -> x.
11781178
if (HasStr2 && ToFindStr.empty())
1179-
return B.CreateBitCast(CI->getArgOperand(0), CI->getType());
1179+
return CI->getArgOperand(0);
11801180

11811181
// If both strings are known, constant fold it.
11821182
if (HasStr1 && HasStr2) {
@@ -1186,16 +1186,13 @@ Value *LibCallSimplifier::optimizeStrStr(CallInst *CI, IRBuilderBase &B) {
11861186
return Constant::getNullValue(CI->getType());
11871187

11881188
// strstr("abcd", "bc") -> gep((char*)"abcd", 1)
1189-
Value *Result = CI->getArgOperand(0);
1190-
Result =
1191-
B.CreateConstInBoundsGEP1_64(B.getInt8Ty(), Result, Offset, "strstr");
1192-
return B.CreateBitCast(Result, CI->getType());
1189+
return B.CreateConstInBoundsGEP1_64(B.getInt8Ty(), CI->getArgOperand(0),
1190+
Offset, "strstr");
11931191
}
11941192

11951193
// fold strstr(x, "y") -> strchr(x, 'y').
11961194
if (HasStr2 && ToFindStr.size() == 1) {
1197-
Value *StrChr = emitStrChr(CI->getArgOperand(0), ToFindStr[0], B, TLI);
1198-
return StrChr ? B.CreateBitCast(StrChr, CI->getType()) : nullptr;
1195+
return emitStrChr(CI->getArgOperand(0), ToFindStr[0], B, TLI);
11991196
}
12001197

12011198
annotateNonNullNoUndefBasedOnAccess(CI, {0, 1});

0 commit comments

Comments
 (0)