diff options
Diffstat (limited to 'llvm/lib/CodeGen/CodeGenPrepare.cpp')
-rw-r--r-- | llvm/lib/CodeGen/CodeGenPrepare.cpp | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/llvm/lib/CodeGen/CodeGenPrepare.cpp b/llvm/lib/CodeGen/CodeGenPrepare.cpp index 16196b0..ddbba80 100644 --- a/llvm/lib/CodeGen/CodeGenPrepare.cpp +++ b/llvm/lib/CodeGen/CodeGenPrepare.cpp @@ -3559,10 +3559,15 @@ private: /// Original Address. Value *Original; + /// Common value among addresses + Value *CommonValue = nullptr; + public: AddressingModeCombiner(const SimplifyQuery &_SQ, Value *OriginalValue) : SQ(_SQ), Original(OriginalValue) {} + ~AddressingModeCombiner() { eraseCommonValueIfDead(); } + /// Get the combined AddrMode const ExtAddrMode &getAddrMode() const { return AddrModes[0]; } @@ -3647,13 +3652,21 @@ public: if (!initializeMap(Map)) return false; - Value *CommonValue = findCommon(Map); + CommonValue = findCommon(Map); if (CommonValue) AddrModes[0].SetCombinedField(DifferentField, CommonValue, AddrModes); return CommonValue != nullptr; } private: + /// `CommonValue` may be a placeholder inserted by us. + /// If the placeholder is not used, we should remove this dead instruction. + void eraseCommonValueIfDead() { + if (CommonValue && CommonValue->getNumUses() == 0) + if (Instruction *CommonInst = dyn_cast<Instruction>(CommonValue)) + CommonInst->eraseFromParent(); + } + /// Initialize Map with anchor values. For address seen /// we set the value of different field saw in this address. /// At the same time we find a common type for different field we will |