Skip to content

[NFC] [MTE] simplify tagp logic #110337

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

Conversation

fmayer
Copy link
Contributor

@fmayer fmayer commented Sep 27, 2024

We would put a placeholder in the tagp instruction, then replace all
uses of the original alloca with this, then replace the placeholder.

We use replaceUsesWithIf anyway, so it's easier to understand if we just
exclude the tagp call there.

Created using spr 1.3.4
@llvmbot
Copy link
Member

llvmbot commented Sep 27, 2024

@llvm/pr-subscribers-backend-aarch64

Author: Florian Mayer (fmayer)

Changes

We would put a placeholder in the tagp instruction, then replace all
uses of the original alloca with this, then replace the placeholder.

We use replaceUsesWithIf anyway, so it's easier to understand if we just
exclude the tagp call there.


Full diff: https://github.com/llvm/llvm-project/pull/110337.diff

1 Files Affected:

  • (modified) llvm/lib/Target/AArch64/AArch64StackTagging.cpp (+4-5)
diff --git a/llvm/lib/Target/AArch64/AArch64StackTagging.cpp b/llvm/lib/Target/AArch64/AArch64StackTagging.cpp
index 6ea58e26d07229..09910cc7bd47bd 100644
--- a/llvm/lib/Target/AArch64/AArch64StackTagging.cpp
+++ b/llvm/lib/Target/AArch64/AArch64StackTagging.cpp
@@ -594,16 +594,15 @@ bool AArch64StackTagging::runOnFunction(Function &Fn) {
     IRBuilder<> IRB(Info.AI->getNextNode());
     Function *TagP = Intrinsic::getDeclaration(
         F->getParent(), Intrinsic::aarch64_tagp, {Info.AI->getType()});
-    Instruction *TagPCall =
-        IRB.CreateCall(TagP, {Constant::getNullValue(Info.AI->getType()), Base,
-                              ConstantInt::get(IRB.getInt64Ty(), Tag)});
+    Instruction *TagPCall = IRB.CreateCall(
+        TagP, {Info.AI, Base, ConstantInt::get(IRB.getInt64Ty(), Tag)});
     if (Info.AI->hasName())
       TagPCall->setName(Info.AI->getName() + ".tag");
     // Does not replace metadata, so we don't have to handle DbgVariableRecords.
     Info.AI->replaceUsesWithIf(TagPCall, [&](const Use &U) {
-      return !memtag::isLifetimeIntrinsic(U.getUser());
+      return !memtag::isLifetimeIntrinsic(U.getUser()) &&
+             U.getUser() != TagPCall;
     });
-    TagPCall->setOperand(0, Info.AI);
 
     // Calls to functions that may return twice (e.g. setjmp) confuse the
     // postdominator analysis, and will leave us to keep memory tagged after

@fmayer fmayer requested a review from vitalybuka September 27, 2024 23:33
@fmayer fmayer merged commit eb739e9 into users/fmayer/spr/main.nfc-mte-simplify-tagp-logic Oct 8, 2024
8 of 10 checks passed
@fmayer fmayer deleted the users/fmayer/spr/nfc-mte-simplify-tagp-logic branch October 8, 2024 22:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants