[llvm] c609846 - [TBAA] Extract logic to use TBAA tag for field of !tbaa.struct (NFC). (#81284)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Feb 12 03:19:06 PST 2024
Author: Florian Hahn
Date: 2024-02-12T11:19:02Z
New Revision: c609846155279090a4f9e659f63fb851e4946cb7
URL: https://github.com/llvm/llvm-project/commit/c609846155279090a4f9e659f63fb851e4946cb7
DIFF: https://github.com/llvm/llvm-project/commit/c609846155279090a4f9e659f63fb851e4946cb7.diff
LOG: [TBAA] Extract logic to use TBAA tag for field of !tbaa.struct (NFC). (#81284)
Added:
Modified:
llvm/include/llvm/IR/Metadata.h
llvm/lib/Analysis/TypeBasedAliasAnalysis.cpp
llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/IR/Metadata.h b/llvm/include/llvm/IR/Metadata.h
index db1f44fea3b459..6f23ac44dee968 100644
--- a/llvm/include/llvm/IR/Metadata.h
+++ b/llvm/include/llvm/IR/Metadata.h
@@ -844,6 +844,11 @@ struct AAMDNodes {
/// together. Different from `merge`, where
diff erent locations should
/// overlap each other, `concat` puts non-overlapping locations together.
AAMDNodes concat(const AAMDNodes &Other) const;
+
+ /// Create a new AAMDNode for accessing \p AccessSize bytes of this AAMDNode.
+ /// If his AAMDNode has !tbaa.struct and \p AccessSize matches the size of the
+ /// field at offset 0, get the TBAA tag describing the accessed field.
+ AAMDNodes adjustForAccess(unsigned AccessSize);
};
// Specialize DenseMapInfo for AAMDNodes.
diff --git a/llvm/lib/Analysis/TypeBasedAliasAnalysis.cpp b/llvm/lib/Analysis/TypeBasedAliasAnalysis.cpp
index e4dc1a867f6f0c..d05f42552e81de 100644
--- a/llvm/lib/Analysis/TypeBasedAliasAnalysis.cpp
+++ b/llvm/lib/Analysis/TypeBasedAliasAnalysis.cpp
@@ -817,3 +817,18 @@ MDNode *AAMDNodes::extendToTBAA(MDNode *MD, ssize_t Len) {
ConstantAsMetadata::get(ConstantInt::get(PreviousSize->getType(), Len));
return MDNode::get(MD->getContext(), NextNodes);
}
+
+AAMDNodes AAMDNodes::adjustForAccess(unsigned AccessSize) {
+ AAMDNodes New = *this;
+ MDNode *M = New.TBAAStruct;
+ New.TBAAStruct = nullptr;
+ if (M && M->getNumOperands() == 3 && M->getOperand(0) &&
+ mdconst::hasa<ConstantInt>(M->getOperand(0)) &&
+ mdconst::extract<ConstantInt>(M->getOperand(0))->isZero() &&
+ M->getOperand(1) && mdconst::hasa<ConstantInt>(M->getOperand(1)) &&
+ mdconst::extract<ConstantInt>(M->getOperand(1))->getValue() ==
+ AccessSize &&
+ M->getOperand(2) && isa<MDNode>(M->getOperand(2)))
+ New.TBAA = cast<MDNode>(M->getOperand(2));
+ return New;
+}
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
index ed5d44757fbeb6..56d1259e955196 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
@@ -172,20 +172,7 @@ Instruction *InstCombinerImpl::SimplifyAnyMemTransfer(AnyMemTransferInst *MI) {
// If the memcpy has metadata describing the members, see if we can get the
// TBAA tag describing our copy.
- AAMDNodes AACopyMD = MI->getAAMetadata();
-
- if (MDNode *M = AACopyMD.TBAAStruct) {
- AACopyMD.TBAAStruct = nullptr;
- if (M->getNumOperands() == 3 && M->getOperand(0) &&
- mdconst::hasa<ConstantInt>(M->getOperand(0)) &&
- mdconst::extract<ConstantInt>(M->getOperand(0))->isZero() &&
- M->getOperand(1) &&
- mdconst::hasa<ConstantInt>(M->getOperand(1)) &&
- mdconst::extract<ConstantInt>(M->getOperand(1))->getValue() ==
- Size &&
- M->getOperand(2) && isa<MDNode>(M->getOperand(2)))
- AACopyMD.TBAA = cast<MDNode>(M->getOperand(2));
- }
+ AAMDNodes AACopyMD = MI->getAAMetadata().adjustForAccess(Size);
Value *Src = MI->getArgOperand(1);
Value *Dest = MI->getArgOperand(0);
More information about the llvm-commits
mailing list