[PATCH] D95826: [SROA] Propagate correct TBAA/TBAA Struct offsets
William Moses via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Feb 11 17:58:54 PST 2021
wsmoses updated this revision to Diff 323195.
wsmoses added a comment.
Remove temporary GEP
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D95826/new/
https://reviews.llvm.org/D95826
Files:
llvm/include/llvm/IR/Operator.h
llvm/lib/IR/Operator.cpp
llvm/lib/Transforms/Scalar/SROA.cpp
Index: llvm/lib/Transforms/Scalar/SROA.cpp
===================================================================
--- llvm/lib/Transforms/Scalar/SROA.cpp
+++ llvm/lib/Transforms/Scalar/SROA.cpp
@@ -3382,13 +3382,11 @@
LoadInst *Load =
IRB.CreateAlignedLoad(Ty, GEP, Alignment, Name + ".load");
- // Make a temporary GEP to compute the offset in case its constant folded
- auto GEPToCompute = GetElementPtrInst::Create(BaseTy, Ptr, GEPIndices);
APInt Offset(
- DL.getIndexSizeInBits(GEPToCompute->getPointerAddressSpace()), 0);
- if (AATags && GEPToCompute->accumulateConstantOffset(DL, Offset))
+ DL.getIndexSizeInBits(Ptr->getType()->getPointerAddressSpace()), 0);
+ if (AATags &&
+ GEPOperator::accumulateConstantOffset(BaseTy, GEPIndices, DL, Offset))
Load->setAAMetadata(AATags.shift(Offset.getZExtValue()));
- delete GEPToCompute;
Agg = IRB.CreateInsertValue(Agg, Load, Indices, Name + ".insert");
LLVM_DEBUG(dbgs() << " to: " << *Load << "\n");
@@ -3436,13 +3434,12 @@
StoreInst *Store =
IRB.CreateAlignedStore(ExtractValue, InBoundsGEP, Alignment);
- // Make a temporary GEP to compute the offset in case its constant folded
- auto GEPToCompute = GetElementPtrInst::Create(BaseTy, Ptr, GEPIndices);
APInt Offset(
- DL.getIndexSizeInBits(GEPToCompute->getPointerAddressSpace()), 0);
- if (AATags && GEPToCompute->accumulateConstantOffset(DL, Offset))
+ DL.getIndexSizeInBits(Ptr->getType()->getPointerAddressSpace()), 0);
+ if (AATags &&
+ GEPOperator::accumulateConstantOffset(BaseTy, GEPIndices, DL, Offset))
Store->setAAMetadata(AATags.shift(Offset.getZExtValue()));
- delete GEPToCompute;
+
LLVM_DEBUG(dbgs() << " to: " << *Store << "\n");
}
};
Index: llvm/lib/IR/Operator.cpp
===================================================================
--- llvm/lib/IR/Operator.cpp
+++ llvm/lib/IR/Operator.cpp
@@ -61,10 +61,17 @@
bool GEPOperator::accumulateConstantOffset(
const DataLayout &DL, APInt &Offset,
function_ref<bool(Value &, APInt &)> ExternalAnalysis) const {
- assert(Offset.getBitWidth() ==
- DL.getIndexSizeInBits(getPointerAddressSpace()) &&
- "The offset bit width does not match DL specification.");
+ assert(Offset.getBitWidth() ==
+ DL.getIndexSizeInBits(getPointerAddressSpace()) &&
+ "The offset bit width does not match DL specification.");
+ SmallVector<const Value *> Index(value_op_begin() + 1, value_op_end());
+ return GEPOperator::accumulateConstantOffset(getSourceElementType(), Index,
+ DL, Offset, ExternalAnalysis);
+}
+bool GEPOperator::accumulateConstantOffset(
+ Type *SourceType, ArrayRef<const Value *> Index, const DataLayout &DL,
+ APInt &Offset, function_ref<bool(Value &, APInt &)> ExternalAnalysis) {
bool UsedExternalAnalysis = false;
auto AccumulateOffset = [&](APInt Index, uint64_t Size) -> bool {
Index = Index.sextOrTrunc(Offset.getBitWidth());
@@ -85,9 +92,10 @@
}
return true;
};
-
- for (gep_type_iterator GTI = gep_type_begin(this), GTE = gep_type_end(this);
- GTI != GTE; ++GTI) {
+ auto begin = generic_gep_type_iterator<decltype(Index.begin())>::begin(
+ SourceType, Index.begin());
+ auto end = generic_gep_type_iterator<decltype(Index.end())>::end(Index.end());
+ for (auto GTI = begin, GTE = end; GTI != GTE; ++GTI) {
// Scalable vectors are multiplied by a runtime constant.
bool ScalableType = false;
if (isa<ScalableVectorType>(GTI.getIndexedType()))
Index: llvm/include/llvm/IR/Operator.h
===================================================================
--- llvm/include/llvm/IR/Operator.h
+++ llvm/include/llvm/IR/Operator.h
@@ -571,6 +571,11 @@
bool accumulateConstantOffset(
const DataLayout &DL, APInt &Offset,
function_ref<bool(Value &, APInt &)> ExternalAnalysis = nullptr) const;
+
+ static bool accumulateConstantOffset(
+ Type *SourceType, ArrayRef<const Value *> Index, const DataLayout &DL,
+ APInt &Offset,
+ function_ref<bool(Value &, APInt &)> ExternalAnalysis = nullptr);
};
class PtrToIntOperator
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D95826.323195.patch
Type: text/x-patch
Size: 4309 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210212/074db974/attachment.bin>
More information about the llvm-commits
mailing list