[llvm] d3e2b4c - [SROA][TBAA] Handle shift of regular TBAA nodes
William S. Moses via llvm-commits
llvm-commits at lists.llvm.org
Wed Apr 14 11:35:28 PDT 2021
Author: William S. Moses
Date: 2021-04-14T14:35:20-04:00
New Revision: d3e2b4c0a21f8b3861d8b64a4c2ed051694094d1
URL: https://github.com/llvm/llvm-project/commit/d3e2b4c0a21f8b3861d8b64a4c2ed051694094d1
DIFF: https://github.com/llvm/llvm-project/commit/d3e2b4c0a21f8b3861d8b64a4c2ed051694094d1.diff
LOG: [SROA][TBAA] Handle shift of regular TBAA nodes
SROA shifts TBAA nodes in a way that may present a problem for !tbaa but not !tbaa.struct nodes.
Differential Revision: https://reviews.llvm.org/D99851
Added:
llvm/test/Transforms/SROA/tbaa-subload.ll
Modified:
llvm/lib/Analysis/TypeBasedAliasAnalysis.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Analysis/TypeBasedAliasAnalysis.cpp b/llvm/lib/Analysis/TypeBasedAliasAnalysis.cpp
index 983d69b5f8435..9f381209ef773 100644
--- a/llvm/lib/Analysis/TypeBasedAliasAnalysis.cpp
+++ b/llvm/lib/Analysis/TypeBasedAliasAnalysis.cpp
@@ -746,47 +746,15 @@ MDNode *AAMDNodes::ShiftTBAA(MDNode *MD, size_t Offset) {
if (!isStructPathTBAA(MD))
return MD;
- TBAAStructTagNode Tag(MD);
- SmallVector<Metadata *, 5> Sub;
- Sub.push_back(MD->getOperand(0));
- Sub.push_back(MD->getOperand(1));
- ConstantInt *InnerOffset = mdconst::extract<ConstantInt>(MD->getOperand(2));
-
- if (Tag.isNewFormat()) {
- ConstantInt *InnerSize = mdconst::extract<ConstantInt>(MD->getOperand(3));
-
- if (InnerOffset->getZExtValue() + InnerSize->getZExtValue() <= Offset) {
- return nullptr;
- }
-
- uint64_t NewSize = InnerSize->getZExtValue();
- uint64_t NewOffset = InnerOffset->getZExtValue() - Offset;
- if (InnerOffset->getZExtValue() < Offset) {
- NewOffset = 0;
- NewSize -= Offset - InnerOffset->getZExtValue();
- }
-
- Sub.push_back(ConstantAsMetadata::get(
- ConstantInt::get(InnerOffset->getType(), NewOffset)));
-
- Sub.push_back(ConstantAsMetadata::get(
- ConstantInt::get(InnerSize->getType(), NewSize)));
-
- // immutable type
- if (MD->getNumOperands() >= 5)
- Sub.push_back(MD->getOperand(4));
- } else {
- if (InnerOffset->getZExtValue() < Offset)
- return nullptr;
-
- Sub.push_back(ConstantAsMetadata::get(ConstantInt::get(
- InnerOffset->getType(), InnerOffset->getZExtValue() - Offset)));
-
- // immutable type
- if (MD->getNumOperands() >= 4)
- Sub.push_back(MD->getOperand(3));
- }
- return MDNode::get(MD->getContext(), Sub);
+ // The correct behavior here is to add the offset into the TBAA
+ // struct node offset. The base type, however may not have defined
+ // a type at this additional offset, resulting in errors. Since
+ // this method is only used within a given load/store access
+ // the offset provided is only used to subdivide the previous load
+ // maintaining the validity of the previous TBAA.
+ //
+ // This, however, should be revisited in the future.
+ return MD;
}
MDNode *AAMDNodes::ShiftTBAAStruct(MDNode *MD, size_t Offset) {
diff --git a/llvm/test/Transforms/SROA/tbaa-subload.ll b/llvm/test/Transforms/SROA/tbaa-subload.ll
new file mode 100644
index 0000000000000..4e3a71f52296a
--- /dev/null
+++ b/llvm/test/Transforms/SROA/tbaa-subload.ll
@@ -0,0 +1,36 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
+; RUN: opt -S -sroa %s | FileCheck %s
+
+; This should not crash
+
+%class.ar = type { i8 }
+%class.anon = type <{ %class.ar, [7 x i8], { i64, i64 } }>
+
+define void @caller() {
+; CHECK-LABEL: @caller(
+; CHECK-NEXT: entry:
+; CHECK-NEXT: [[AGG:%.*]] = alloca [[CLASS_ANON:%.*]], align 8
+; CHECK-NEXT: [[OFF:%.*]] = getelementptr inbounds [[CLASS_ANON]], %class.anon* [[AGG]], i32 0, i32 2
+; CHECK-NEXT: [[DOTFCA_0_GEP:%.*]] = getelementptr inbounds { i64, i64 }, { i64, i64 }* [[OFF]], i32 0, i32 0
+; CHECK-NEXT: store i64 1, i64* [[DOTFCA_0_GEP]], align 8, !tbaa [[TBAA0:![0-9]+]]
+; CHECK-NEXT: [[DOTFCA_1_GEP:%.*]] = getelementptr inbounds { i64, i64 }, { i64, i64 }* [[OFF]], i32 0, i32 1
+; CHECK-NEXT: store i64 2, i64* [[DOTFCA_1_GEP]], align 8, !tbaa [[TBAA0]]
+; CHECK-NEXT: call void @use(%class.anon* [[AGG]])
+; CHECK-NEXT: ret void
+;
+entry:
+ %agg = alloca %class.anon, align 8
+ %off = getelementptr inbounds %class.anon, %class.anon* %agg, i32 0, i32 2
+ store { i64, i64 } { i64 1, i64 2 }, { i64, i64 }* %off, align 8, !tbaa !7
+ call void @use(%class.anon* %agg)
+ ret void
+}
+
+declare void @use(%class.anon* %this)
+
+!3 = !{!"omnipotent char", !4, i64 0}
+!4 = !{!"Simple C++ TBAA"}
+
+!7 = !{!8, !3, i64 8}
+!8 = !{!"_ZTSZN2ax2baEMS_FvvE2an2arE3$_0", !9, i64 0, !3, i64 8}
+!9 = !{!"_ZTS2ar"}
More information about the llvm-commits
mailing list