[llvm] ba4764c - Fix leak in GVNSink introduced in D72467.
Eli Friedman via llvm-commits
llvm-commits at lists.llvm.org
Tue Mar 31 16:22:10 PDT 2020
Author: Eli Friedman
Date: 2020-03-31T16:21:27-07:00
New Revision: ba4764c2cc14b0b495af539a913de10cf8268420
URL: https://github.com/llvm/llvm-project/commit/ba4764c2cc14b0b495af539a913de10cf8268420
DIFF: https://github.com/llvm/llvm-project/commit/ba4764c2cc14b0b495af539a913de10cf8268420.diff
LOG: Fix leak in GVNSink introduced in D72467.
Added:
Modified:
llvm/lib/Transforms/Scalar/GVNSink.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Scalar/GVNSink.cpp b/llvm/lib/Transforms/Scalar/GVNSink.cpp
index d0b96218137c..df1d97877c59 100644
--- a/llvm/lib/Transforms/Scalar/GVNSink.cpp
+++ b/llvm/lib/Transforms/Scalar/GVNSink.cpp
@@ -350,7 +350,7 @@ using ModelledPHISet = DenseSet<ModelledPHI, DenseMapInfo<ModelledPHI>>;
class InstructionUseExpr : public GVNExpression::BasicExpression {
unsigned MemoryUseOrder = -1;
bool Volatile = false;
- std::vector<int> ShuffleMask;
+ ArrayRef<int> ShuffleMask;
public:
InstructionUseExpr(Instruction *I, ArrayRecycler<Value *> &R,
@@ -360,6 +360,13 @@ class InstructionUseExpr : public GVNExpression::BasicExpression {
setOpcode(I->getOpcode());
setType(I->getType());
+ if (ShuffleVectorInst *SVI = dyn_cast<ShuffleVectorInst>(I)) {
+ ArrayRef<int> OrigMask = SVI->getShuffleMask();
+ int *Mask = A.Allocate<int>(OrigMask.size());
+ llvm::copy(OrigMask, Mask);
+ ShuffleMask = ArrayRef<int>(Mask, OrigMask.size());
+ }
+
for (auto &U : I->uses())
op_push_back(U.getUser());
llvm::sort(op_begin(), op_end());
@@ -367,18 +374,15 @@ class InstructionUseExpr : public GVNExpression::BasicExpression {
void setMemoryUseOrder(unsigned MUO) { MemoryUseOrder = MUO; }
void setVolatile(bool V) { Volatile = V; }
- void setShuffleMask(ArrayRef<int> Mask) {
- ShuffleMask.assign(Mask.begin(), Mask.end());
- }
hash_code getHashValue() const override {
return hash_combine(GVNExpression::BasicExpression::getHashValue(),
- MemoryUseOrder, Volatile, ArrayRef<int>(ShuffleMask));
+ MemoryUseOrder, Volatile, ShuffleMask);
}
template <typename Function> hash_code getHashValue(Function MapFn) {
hash_code H = hash_combine(getOpcode(), getType(), MemoryUseOrder, Volatile,
- ArrayRef<int>(ShuffleMask));
+ ShuffleMask);
for (auto *V : operands())
H = hash_combine(H, MapFn(V));
return H;
@@ -406,8 +410,6 @@ class ValueTable {
CmpInst::Predicate Predicate = C->getPredicate();
E->setOpcode((C->getOpcode() << 8) | Predicate);
}
- if (ShuffleVectorInst *SVI = dyn_cast<ShuffleVectorInst>(I))
- E->setShuffleMask(SVI->getShuffleMask());
return E;
}
More information about the llvm-commits
mailing list