[PATCH] D48640: [WIP][SROA] Preserve DebugLoc when rewriting alloca partitions

Anastasis via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 27 05:42:29 PDT 2018


gramanas created this revision.
gramanas added reviewers: vsk, gbedwell.
Herald added a subscriber: llvm-commits.

When rewriting an alloca partition copy the DL from the
old alloca over the the new one.

Based on Greg's report
https://bugs.llvm.org/show_bug.cgi?id=37942


Repository:
  rL LLVM

https://reviews.llvm.org/D48640

Files:
  lib/Transforms/Scalar/SROA.cpp
  test/Transforms/SROA/alloca-debugloc.ll


Index: test/Transforms/SROA/alloca-debugloc.ll
===================================================================
--- /dev/null
+++ test/Transforms/SROA/alloca-debugloc.ll
@@ -0,0 +1,29 @@
+; RUN: opt -debugify -instcombine -sroa -S < %s | FileCheck %s
+
+; Check that when sroa rewrites the alloca partition
+; for the baz vector, it preserves the original DebugLocation
+
+target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128"
+
+define dso_local void @foo() {
+entry:
+  %baz = alloca [6 x i32], align 16
+  %qaz = alloca i32, align 4
+  %0 = bitcast [6 x i32]* %baz to i8*
+  call void @llvm.memset.p0i8.i64(i8* align 16 %0, i8 0, i64 24, i1 false)
+  %arrayidx = getelementptr inbounds [6 x i32], [6 x i32]* %baz, i64 0, i64 2
+  %1 = load i32, i32* %arrayidx, align 8
+  %call = call i32 @bar(i32 %1)
+  %arraydecay = getelementptr inbounds [6 x i32], [6 x i32]* %baz, i32 0, i32 0
+  %2 = ptrtoint i32* %arraydecay to i32
+  store i32 %2, i32* %qaz, align 4
+  ret void
+}
+
+declare void @llvm.memset.p0i8.i64(i8* nocapture writeonly, i8, i64, i1)
+declare dso_local i32 @bar(i32)
+
+; CHECK: entry:
+; CHECK-NEXT: {{.*}} = alloca {{.*}} !dbg ![[DbgLoc:[0-9]+]]
+
+; CHECK: ![[DbgLoc]] = !DILocation(
Index: lib/Transforms/Scalar/SROA.cpp
===================================================================
--- lib/Transforms/Scalar/SROA.cpp
+++ lib/Transforms/Scalar/SROA.cpp
@@ -4029,6 +4029,8 @@
     NewAI = new AllocaInst(
       SliceTy, AI.getType()->getAddressSpace(), nullptr, Alignment,
         AI.getName() + ".sroa." + Twine(P.begin() - AS.begin()), &AI);
+    // Copy the old AI debug location over to the new one
+    NewAI->setDebugLoc(AI.getDebugLoc());
     ++NumNewAllocas;
   }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D48640.153055.patch
Type: text/x-patch
Size: 1715 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180627/ced727c5/attachment.bin>


More information about the llvm-commits mailing list