From 92ec61498831550b0e1231c2150e686cdf2fc125 Mon Sep 17 00:00:00 2001 From: Anton Sidorenko Date: Fri, 28 Oct 2022 12:19:04 +0300 Subject: [PATCH] [GlobalISel] Compute debug location when merging stores more accurately Originaly the loop did almost nothing as the calculated location was overwritten on the next iteration. Differential Revision: https://reviews.llvm.org/D136937 --- llvm/lib/CodeGen/GlobalISel/LoadStoreOpt.cpp | 8 ++++---- llvm/test/CodeGen/AArch64/GlobalISel/store-merging-debug.mir | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/llvm/lib/CodeGen/GlobalISel/LoadStoreOpt.cpp b/llvm/lib/CodeGen/GlobalISel/LoadStoreOpt.cpp index be1bc86..f5fa5fe 100644 --- a/llvm/lib/CodeGen/GlobalISel/LoadStoreOpt.cpp +++ b/llvm/lib/CodeGen/GlobalISel/LoadStoreOpt.cpp @@ -355,10 +355,10 @@ bool LoadStoreOpt::doSingleStoreMerge(SmallVectorImpl &Stores) { LLT::scalar(NumStores * SmallTy.getSizeInBits().getFixedSize()); // For each store, compute pairwise merged debug locs. - DebugLoc MergedLoc; - for (unsigned AIdx = 0, BIdx = 1; BIdx < NumStores; ++AIdx, ++BIdx) - MergedLoc = DILocation::getMergedLocation(Stores[AIdx]->getDebugLoc(), - Stores[BIdx]->getDebugLoc()); + DebugLoc MergedLoc = Stores.front()->getDebugLoc(); + for (auto *Store : drop_begin(Stores)) + MergedLoc = DILocation::getMergedLocation(MergedLoc, Store->getDebugLoc()); + Builder.setInstr(*Stores.back()); Builder.setDebugLoc(MergedLoc); diff --git a/llvm/test/CodeGen/AArch64/GlobalISel/store-merging-debug.mir b/llvm/test/CodeGen/AArch64/GlobalISel/store-merging-debug.mir index f95f41d..200281f 100644 --- a/llvm/test/CodeGen/AArch64/GlobalISel/store-merging-debug.mir +++ b/llvm/test/CodeGen/AArch64/GlobalISel/store-merging-debug.mir @@ -127,7 +127,7 @@ body: | ; CHECK-NEXT: [[PTR_ADD2:%[0-9]+]]:_(p0) = G_PTR_ADD [[COPY]], [[C6]](s64), debug-location !DILocation(line: 14, column: 1, scope: !5) ; CHECK-NEXT: DBG_VALUE [[PTR_ADD2]](p0), $noreg, !9, !DIExpression(), debug-location !DILocation(line: 14, column: 1, scope: !5) ; CHECK-NEXT: [[C7:%[0-9]+]]:_(s64) = G_CONSTANT i64 3940688328982532 - ; CHECK-NEXT: G_STORE [[C7]](s64), [[COPY]](p0), debug-location !DILocation(line: 9, column: 4, scope: !5) :: (store (s64), align 2) + ; CHECK-NEXT: G_STORE [[C7]](s64), [[COPY]](p0), debug-location !DILocation(line: 9, scope: !5) :: (store (s64), align 2) ; CHECK-NEXT: DBG_VALUE 3, $noreg, !9, !DIExpression(), debug-location !DILocation(line: 15, column: 1, scope: !5) ; CHECK-NEXT: RET_ReallyLR debug-location !DILocation(line: 16, column: 1, scope: !5) %0:_(p0) = COPY $x0, debug-location !11 -- 2.7.4