diff options
-rw-r--r-- | llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp | 8 | ||||
-rw-r--r-- | llvm/test/Transforms/InstCombine/storemerge-dbg.ll | 26 |
2 files changed, 32 insertions, 2 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp b/llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp index e2f54606f2d..02ebb5ef294 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp @@ -19,6 +19,7 @@ #include "llvm/Transforms/Utils/Local.h" #include "llvm/IR/ConstantRange.h" #include "llvm/IR/DataLayout.h" +#include "llvm/IR/DebugInfoMetadata.h" #include "llvm/IR/IntrinsicInst.h" #include "llvm/IR/LLVMContext.h" #include "llvm/IR/MDBuilder.h" @@ -1600,11 +1601,15 @@ bool InstCombiner::mergeStoreIntoSuccessor(StoreInst &SI) { // Insert a PHI node now if we need it. Value *MergedVal = OtherStore->getOperand(0); + // The debug locations of the original instructions might differ. Merge them. + DebugLoc MergedLoc = DILocation::getMergedLocation(SI.getDebugLoc(), + OtherStore->getDebugLoc()); if (MergedVal != SI.getOperand(0)) { PHINode *PN = PHINode::Create(MergedVal->getType(), 2, "storemerge"); PN->addIncoming(SI.getOperand(0), SI.getParent()); PN->addIncoming(OtherStore->getOperand(0), OtherBB); MergedVal = InsertNewInstBefore(PN, DestBB->front()); + PN->setDebugLoc(MergedLoc); } // Advance to a place where it is safe to insert the new store and insert it. @@ -1613,8 +1618,7 @@ bool InstCombiner::mergeStoreIntoSuccessor(StoreInst &SI) { SI.isVolatile(), SI.getAlignment(), SI.getOrdering(), SI.getSyncScopeID()); InsertNewInstBefore(NewSI, *BBI); - // The debug locations of the original instructions might differ. Merge them. - NewSI->applyMergedLocation(SI.getDebugLoc(), OtherStore->getDebugLoc()); + NewSI->setDebugLoc(MergedLoc); // If the two stores had AA tags, merge them. AAMDNodes AATags; diff --git a/llvm/test/Transforms/InstCombine/storemerge-dbg.ll b/llvm/test/Transforms/InstCombine/storemerge-dbg.ll new file mode 100644 index 00000000000..dc40dd7f787 --- /dev/null +++ b/llvm/test/Transforms/InstCombine/storemerge-dbg.ll @@ -0,0 +1,26 @@ +; RUN: opt < %s -debugify -instcombine -S | FileCheck %s + +declare i32 @escape(i32) + +; CHECK-LABEL: define {{.*}}@foo( +define i32 @foo() { +entry: + %baz = alloca i32 + br i1 undef, label %lhs, label %rhs + +lhs: + store i32 1, i32* %baz + br label %cleanup + +rhs: + store i32 2, i32* %baz + br label %cleanup + +cleanup: + ; CHECK: %storemerge = phi i32 [ 1, %lhs ], [ 2, %rhs ], !dbg [[merge_loc:![0-9]+]] + %baz.val = load i32, i32* %baz + %ret.val = call i32 @escape(i32 %baz.val) + ret i32 %ret.val +} + +; CHECK: [[merge_loc]] = !DILocation(line: 0 |