diff options
Diffstat (limited to 'llvm/lib/CodeGen/MachineFunction.cpp')
-rw-r--r-- | llvm/lib/CodeGen/MachineFunction.cpp | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/llvm/lib/CodeGen/MachineFunction.cpp b/llvm/lib/CodeGen/MachineFunction.cpp index e1cf417..0f72e4b 100644 --- a/llvm/lib/CodeGen/MachineFunction.cpp +++ b/llvm/lib/CodeGen/MachineFunction.cpp @@ -1392,7 +1392,7 @@ MachineConstantPool::~MachineConstantPool() { } /// Test whether the given two constants can be allocated the same constant pool -/// entry. +/// entry referenced by \param A. static bool CanShareConstantPoolEntry(const Constant *A, const Constant *B, const DataLayout &DL) { // Handle the trivial case quickly. @@ -1412,6 +1412,8 @@ static bool CanShareConstantPoolEntry(const Constant *A, const Constant *B, if (StoreSize != DL.getTypeStoreSize(B->getType()) || StoreSize > 128) return false; + bool ContainsUndefOrPoisonA = A->containsUndefOrPoisonElement(); + Type *IntTy = IntegerType::get(A->getContext(), StoreSize*8); // Try constant folding a bitcast of both instructions to an integer. If we @@ -1431,7 +1433,14 @@ static bool CanShareConstantPoolEntry(const Constant *A, const Constant *B, B = ConstantFoldCastOperand(Instruction::BitCast, const_cast<Constant *>(B), IntTy, DL); - return A == B; + if (A != B) + return false; + + // Constants only safely match if A doesn't contain undef/poison. + // As we'll be reusing A, it doesn't matter if B contain undef/poison. + // TODO: Handle cases where A and B have the same undef/poison elements. + // TODO: Merge A and B with mismatching undef/poison elements. + return !ContainsUndefOrPoisonA; } /// Create a new entry in the constant pool or return an existing one. |