[prev in list] [next in list] [prev in thread] [next in thread]
List: cfe-commits
Subject: [PATCH] D105671: [Intrinsics][ObjC] Mark objc_retain and friends as thisreturn.
From: Jon Roelofs via Phabricator via cfe-commits <cfe-commits () lists ! llvm ! org>
Date: 2023-07-31 20:31:48
Message-ID: rbhQAR29TFGhHH8gttUtXA () geopod-ismtpd-0
[Download RAW message or body]
jroelofs updated this revision to Diff 545779.
jroelofs added a comment.
Move the `stripPointerCasts()` change into its own review: https://reviews.llvm.org/D156735
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D105671/new/
https://reviews.llvm.org/D105671
Files:
llvm/include/llvm/IR/Value.h
llvm/lib/IR/Value.cpp
llvm/unittests/IR/InstructionsTest.cpp
Index: llvm/unittests/IR/InstructionsTest.cpp
===================================================================
--- llvm/unittests/IR/InstructionsTest.cpp
+++ llvm/unittests/IR/InstructionsTest.cpp
@@ -458,6 +458,35 @@
wrap(V2Int32PtrAS1Ty), true));
}
+TEST(InstructionsTest, StripPointerCasts) {
+ LLVMContext C;
+ Type *I64PtrTy = Type::getInt64PtrTy(C);
+ Type *I32PtrTy = Type::getInt32PtrTy(C);
+
+ Module M("M", C);
+ FunctionType *FTy =
+ FunctionType::get(I64PtrTy, {I64PtrTy}, false);
+ auto *F = Function::Create(FTy, Function::ExternalLinkage, "", M);
+ auto *BB = BasicBlock::Create(C, "bb", F);
+ IRBuilder<> Builder(C);
+ Builder.SetInsertPoint(BB);
+
+ Value *A0 = F->getArg(0);
+ Function *SSACopy = Intrinsic::getDeclaration(&M, Intrinsic::ssa_copy, {A0->getType()});
+ CallInst *Call = Builder.CreateCall(SSACopy, {A0});
+ Value *Cast = Builder.CreateBitCast(Call, I32PtrTy);
+
+ // When stripping for alias analysis, it is okay to look through returned
+ // argument functions, since the pointer is unchanged.
+ EXPECT_EQ(Cast->stripPointerCastsForAliasAnalysis(), A0);
+
+ // Otherwise, this is not okay.
+ EXPECT_EQ(Cast->stripPointerCasts(), Call);
+ EXPECT_EQ(Cast->stripPointerCastsAndAliases(), Call);
+ EXPECT_EQ(Cast->stripPointerCastsSameRepresentation(), Call);
+ EXPECT_EQ(Cast->stripInBoundsConstantOffsets(), Call);
+}
+
TEST(InstructionsTest, VectorGep) {
LLVMContext C;
Index: llvm/lib/IR/Value.cpp
===================================================================
--- llvm/lib/IR/Value.cpp
+++ llvm/lib/IR/Value.cpp
@@ -662,7 +662,8 @@
V = cast<PHINode>(V)->getIncomingValue(0);
} else {
if (const auto *Call = dyn_cast<CallBase>(V)) {
- if (const Value *RV = Call->getReturnedArgOperand()) {
+ if (const Value *RV = Call->getReturnedArgOperand();
+ RV && StripKind == PSK_ForAliasAnalysis) {
V = RV;
continue;
}
Index: llvm/include/llvm/IR/Value.h
===================================================================
--- llvm/include/llvm/IR/Value.h
+++ llvm/include/llvm/IR/Value.h
@@ -656,7 +656,7 @@
}
/// Strip off pointer casts, all-zero GEPs, single-argument phi nodes and
- /// invariant group info.
+ /// invariant group info. Looks through returned arg functions.
///
/// Returns the original uncasted value. If this is called on a non-pointer
/// value, it returns 'this'. This function should be used only in
["D105671.545779.patch" (D105671.545779.patch)]
Index: llvm/unittests/IR/InstructionsTest.cpp
===================================================================
--- llvm/unittests/IR/InstructionsTest.cpp
+++ llvm/unittests/IR/InstructionsTest.cpp
@@ -458,6 +458,35 @@
wrap(V2Int32PtrAS1Ty), true));
}
+TEST(InstructionsTest, StripPointerCasts) {
+ LLVMContext C;
+ Type *I64PtrTy = Type::getInt64PtrTy(C);
+ Type *I32PtrTy = Type::getInt32PtrTy(C);
+
+ Module M("M", C);
+ FunctionType *FTy =
+ FunctionType::get(I64PtrTy, {I64PtrTy}, false);
+ auto *F = Function::Create(FTy, Function::ExternalLinkage, "", M);
+ auto *BB = BasicBlock::Create(C, "bb", F);
+ IRBuilder<> Builder(C);
+ Builder.SetInsertPoint(BB);
+
+ Value *A0 = F->getArg(0);
+ Function *SSACopy = Intrinsic::getDeclaration(&M, Intrinsic::ssa_copy, {A0->getType()});
+ CallInst *Call = Builder.CreateCall(SSACopy, {A0});
+ Value *Cast = Builder.CreateBitCast(Call, I32PtrTy);
+
+ // When stripping for alias analysis, it is okay to look through returned
+ // argument functions, since the pointer is unchanged.
+ EXPECT_EQ(Cast->stripPointerCastsForAliasAnalysis(), A0);
+
+ // Otherwise, this is not okay.
+ EXPECT_EQ(Cast->stripPointerCasts(), Call);
+ EXPECT_EQ(Cast->stripPointerCastsAndAliases(), Call);
+ EXPECT_EQ(Cast->stripPointerCastsSameRepresentation(), Call);
+ EXPECT_EQ(Cast->stripInBoundsConstantOffsets(), Call);
+}
+
TEST(InstructionsTest, VectorGep) {
LLVMContext C;
Index: llvm/lib/IR/Value.cpp
===================================================================
--- llvm/lib/IR/Value.cpp
+++ llvm/lib/IR/Value.cpp
@@ -662,7 +662,8 @@
V = cast<PHINode>(V)->getIncomingValue(0);
} else {
if (const auto *Call = dyn_cast<CallBase>(V)) {
- if (const Value *RV = Call->getReturnedArgOperand()) {
+ if (const Value *RV = Call->getReturnedArgOperand();
+ RV && StripKind == PSK_ForAliasAnalysis) {
V = RV;
continue;
}
Index: llvm/include/llvm/IR/Value.h
===================================================================
--- llvm/include/llvm/IR/Value.h
+++ llvm/include/llvm/IR/Value.h
@@ -656,7 +656,7 @@
}
/// Strip off pointer casts, all-zero GEPs, single-argument phi nodes and
- /// invariant group info.
+ /// invariant group info. Looks through returned arg functions.
///
/// Returns the original uncasted value. If this is called on a non-pointer
/// value, it returns 'this'. This function should be used only in
[Attachment #4 (text/plain)]
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic