Index: llvm/lib/Transforms/Scalar/LoopIdiomRecognize.cpp =================================================================== --- llvm/lib/Transforms/Scalar/LoopIdiomRecognize.cpp +++ llvm/lib/Transforms/Scalar/LoopIdiomRecognize.cpp @@ -1088,8 +1088,12 @@ return false; } - if (avoidLIRForMultiBlockLoop()) + if (avoidLIRForMultiBlockLoop()) { + Expander.clear(); + RecursivelyDeleteTriviallyDeadInstructions(LoadBasePtr, TLI); + RecursivelyDeleteTriviallyDeadInstructions(StoreBasePtr, TLI); return false; + } // Okay, everything is safe, we can transform this! @@ -1111,17 +1115,32 @@ // anything where the alignment isn't at least the element size. const MaybeAlign StoreAlign = SI->getAlign(); const MaybeAlign LoadAlign = LI->getAlign(); - if (StoreAlign == None || LoadAlign == None) + if (StoreAlign == None || LoadAlign == None) { + Expander.clear(); + RecursivelyDeleteTriviallyDeadInstructions(NumBytes, TLI); + RecursivelyDeleteTriviallyDeadInstructions(LoadBasePtr, TLI); + RecursivelyDeleteTriviallyDeadInstructions(StoreBasePtr, TLI); return false; - if (*StoreAlign < StoreSize || *LoadAlign < StoreSize) + } + if (*StoreAlign < StoreSize || *LoadAlign < StoreSize) { + Expander.clear(); + RecursivelyDeleteTriviallyDeadInstructions(NumBytes, TLI); + RecursivelyDeleteTriviallyDeadInstructions(LoadBasePtr, TLI); + RecursivelyDeleteTriviallyDeadInstructions(StoreBasePtr, TLI); return false; + } // If the element.atomic memcpy is not lowered into explicit // loads/stores later, then it will be lowered into an element-size // specific lib call. If the lib call doesn't exist for our store size, then // we shouldn't generate the memcpy. - if (StoreSize > TTI->getAtomicMemIntrinsicMaxElementSize()) + if (StoreSize > TTI->getAtomicMemIntrinsicMaxElementSize()) { + Expander.clear(); + RecursivelyDeleteTriviallyDeadInstructions(NumBytes, TLI); + RecursivelyDeleteTriviallyDeadInstructions(LoadBasePtr, TLI); + RecursivelyDeleteTriviallyDeadInstructions(StoreBasePtr, TLI); return false; + } // Create the call. // Note that unordered atomic loads/stores are *required* by the spec to