[PATCH] D78388: [globalisel][cse] Merge debug locations when CSE'ing

Daniel Sanders via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Apr 17 11:20:25 PDT 2020


dsanders created this revision.
dsanders added reviewers: aditya_nandakumar, aprantl, vsk.
Herald added subscribers: volkan, hiraditya, rovka.
Herald added a project: LLVM.
dsanders added a comment.

I currently don't have an in-tree test case for this but it should be possible to construct one. Essentially it needs CSE enabled, and needs two instructions that need legalization and emit a common instruction during their legalizations with identical constraints (to avoid the copy) and have conflicting debug locations. I'll try to make an AArch64 test case when I get chance.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D78388

Files:
  llvm/lib/CodeGen/GlobalISel/CSEMIRBuilder.cpp


Index: llvm/lib/CodeGen/GlobalISel/CSEMIRBuilder.cpp
===================================================================
--- llvm/lib/CodeGen/GlobalISel/CSEMIRBuilder.cpp
+++ llvm/lib/CodeGen/GlobalISel/CSEMIRBuilder.cpp
@@ -13,6 +13,7 @@
 
 #include "llvm/CodeGen/GlobalISel/CSEMIRBuilder.h"
 #include "llvm/CodeGen/GlobalISel/GISelChangeObserver.h"
+#include "llvm/IR/DebugInfoMetadata.h"
 
 using namespace llvm;
 
@@ -131,6 +132,21 @@
     if (Op.getDstOpKind() == DstOp::DstType::Ty_Reg)
       return buildCopy(Op.getReg(), MIB.getReg(0));
   }
+
+  // If we didn't generate a copy then we're re-using an existing node directly
+  // instead of emitting any code. Merge the debug location we wanted to emit
+  // into the instruction we're CSE'ing with. Debug locations arent part of the
+  // profile so we don't need to recompute it.
+  if (getDebugLoc()) {
+    GISelChangeObserver *Observer = getState().Observer;
+    if (Observer)
+      Observer->changingInstr(*MIB);
+    MIB->setDebugLoc(
+        DILocation::getMergedLocation(MIB->getDebugLoc(), getDebugLoc()));
+    if (Observer)
+      Observer->changedInstr(*MIB);
+  }
+
   return MIB;
 }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D78388.258374.patch
Type: text/x-patch
Size: 1163 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200417/3f14a059/attachment.bin>


More information about the llvm-commits mailing list