-
Notifications
You must be signed in to change notification settings - Fork 13.7k
ObjCARCContract: Use stripPointerCastsAndAliases #134275
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ObjCARCContract: Use stripPointerCastsAndAliases #134275
Conversation
@llvm/pr-subscribers-llvm-transforms Author: Matt Arsenault (arsenm) ChangesFull diff: https://github.com/llvm/llvm-project/pull/134275.diff 1 Files Affected:
diff --git a/llvm/lib/Transforms/ObjCARC/ObjCARCContract.cpp b/llvm/lib/Transforms/ObjCARC/ObjCARCContract.cpp
index e11748b2c9dbb..ed7a235f5e2e3 100644
--- a/llvm/lib/Transforms/ObjCARC/ObjCARCContract.cpp
+++ b/llvm/lib/Transforms/ObjCARC/ObjCARCContract.cpp
@@ -661,30 +661,16 @@ bool ObjCARCContract::run(Function &F, AAResults *A, DominatorTree *D) {
Value *Arg = cast<CallInst>(Inst)->getArgOperand(0);
- // TODO: Change this to a do-while.
- for (;;) {
- ReplaceArgUses(Arg);
-
- // If Arg is a no-op casted pointer, strip one level of casts and iterate.
- if (const BitCastInst *BI = dyn_cast<BitCastInst>(Arg))
- Arg = BI->getOperand(0);
- else if (isa<GEPOperator>(Arg) &&
- cast<GEPOperator>(Arg)->hasAllZeroIndices())
- Arg = cast<GEPOperator>(Arg)->getPointerOperand();
- else if (isa<GlobalAlias>(Arg) &&
- !cast<GlobalAlias>(Arg)->isInterposable())
- Arg = cast<GlobalAlias>(Arg)->getAliasee();
- else {
- // If Arg is a PHI node, get PHIs that are equivalent to it and replace
- // their uses.
- if (PHINode *PN = dyn_cast<PHINode>(Arg)) {
- SmallVector<Value *, 1> PHIList;
- getEquivalentPHIs(*PN, PHIList);
- for (Value *PHI : PHIList)
- ReplaceArgUses(PHI);
- }
- break;
- }
+ ReplaceArgUses(Arg);
+
+ Arg = Arg->stripPointerCastsAndAliases();
+ // If Arg is a PHI node, get PHIs that are equivalent to it and replace
+ // their uses.
+ if (PHINode *PN = dyn_cast<PHINode>(Arg)) {
+ SmallVector<Value *, 1> PHIList;
+ getEquivalentPHIs(*PN, PHIList);
+ for (Value *PHI : PHIList)
+ ReplaceArgUses(PHI);
}
}
|
14866ad
to
f0c5f77
Compare
94bafd4
to
981f435
Compare
981f435
to
6614a6b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ping
Is this supposed to be a NFC patch? With the changes in this patch, the pass no longer rewrites the argument to the second call to
This is a contrived example and maybe it's okay if we know that clang/llvm never generates IR like this in practice. But I'd like to understand what assumptions you are making about the IR that's fed to this pass. |
Correction: with the changes in this patch, the pass no longer rewrites the argument to the first call to use_pointer in the following IR: |
Yes. This is code that's plainly reinventing a common helper function
Missing test coverage. I'm assuming this loop is not properly tested. Can you push this to fix the gaps?
My only assumption is the lit test suite is adequate to cover all of the functionality exercised in the code |
6614a6b
to
238597d
Compare
238597d
to
cfd2525
Compare
I'm not convinced that the replacement with stripPointerCastsAndAliases() makes sense. Yes, this does something similar, but the important difference is that the current code performs the replacement at each instruction in the chain. Now you are only doing it at the first and last value in the chain, which is not the same. |
Don't care about this to spend any time on it |
No description provided.