[llvm] 0608764 - [Hexagon] Do not track reserved regs in RDF optimizations

Krzysztof Parzyszek via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 15 09:01:27 PDT 2023


Author: Krzysztof Parzyszek
Date: 2023-06-15T09:01:04-07:00
New Revision: 0608764d6f3b199882ef68b94a0c8409cfe778bc

URL: https://github.com/llvm/llvm-project/commit/0608764d6f3b199882ef68b94a0c8409cfe778bc
DIFF: https://github.com/llvm/llvm-project/commit/0608764d6f3b199882ef68b94a0c8409cfe778bc.diff

LOG: [Hexagon] Do not track reserved regs in RDF optimizations

Added: 
    

Modified: 
    llvm/lib/Target/Hexagon/HexagonRDFOpt.cpp
    llvm/lib/Target/Hexagon/RDFCopy.cpp
    llvm/lib/Target/Hexagon/RDFDeadCode.cpp
    llvm/lib/Target/Hexagon/RDFDeadCode.h
    llvm/test/CodeGen/Hexagon/rdf-copy-renamable-reserved.mir

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Target/Hexagon/HexagonRDFOpt.cpp b/llvm/lib/Target/Hexagon/HexagonRDFOpt.cpp
index 418cb3cbe0897..7eccbd2cb0236 100644
--- a/llvm/lib/Target/Hexagon/HexagonRDFOpt.cpp
+++ b/llvm/lib/Target/Hexagon/HexagonRDFOpt.cpp
@@ -47,9 +47,11 @@ namespace llvm {
 
 static unsigned RDFCount = 0;
 
-static cl::opt<unsigned> RDFLimit("rdf-limit",
-    cl::init(std::numeric_limits<unsigned>::max()));
-static cl::opt<bool> RDFDump("rdf-dump", cl::init(false));
+static cl::opt<unsigned>
+    RDFLimit("hexagon-rdf-limit",
+             cl::init(std::numeric_limits<unsigned>::max()));
+static cl::opt<bool> RDFDump("hexagon-rdf-dump", cl::Hidden);
+static cl::opt<bool> RDFTrackReserved("hexagon-rdf-track-reserved", cl::Hidden);
 
 namespace {
 
@@ -303,7 +305,11 @@ bool HexagonRDFOpt::runOnMachineFunction(MachineFunction &MF) {
   // Dead phi nodes are necessary for copy propagation: we can add a use
   // of a register in a block where it would need a phi node, but which
   // was dead (and removed) during the graph build time.
-  G.build(BuildOptions::KeepDeadPhis);
+  DataFlowGraph::Config Cfg;
+  Cfg.Options = RDFTrackReserved
+                    ? BuildOptions::KeepDeadPhis
+                    : BuildOptions::KeepDeadPhis | BuildOptions::OmitReserved;
+  G.build(Cfg);
 
   if (RDFDump)
     dbgs() << "Starting copy propagation on: " << MF.getName() << '\n'

diff  --git a/llvm/lib/Target/Hexagon/RDFCopy.cpp b/llvm/lib/Target/Hexagon/RDFCopy.cpp
index c26811e9cd05d..b26821cd01718 100644
--- a/llvm/lib/Target/Hexagon/RDFCopy.cpp
+++ b/llvm/lib/Target/Hexagon/RDFCopy.cpp
@@ -51,6 +51,8 @@ bool CopyPropagation::interpretAsCopy(const MachineInstr *MI, EqualityMap &EM) {
       if (TRI.getMinimalPhysRegClass(DstR.Reg) !=
           TRI.getMinimalPhysRegClass(SrcR.Reg))
         return false;
+      if (!DFG.isTracked(SrcR) || !DFG.isTracked(DstR))
+        return false;
       EM.insert(std::make_pair(DstR, SrcR));
       return true;
     }

diff  --git a/llvm/lib/Target/Hexagon/RDFDeadCode.cpp b/llvm/lib/Target/Hexagon/RDFDeadCode.cpp
index 894bdf38fe176..d90923d6d3edc 100644
--- a/llvm/lib/Target/Hexagon/RDFDeadCode.cpp
+++ b/llvm/lib/Target/Hexagon/RDFDeadCode.cpp
@@ -55,7 +55,8 @@ template<typename T> struct DeadCodeElimination::SetQueue {
 // overly conservative (i.e. return "true" for all instructions), but it
 // is not safe to return "false" for an instruction that should not be
 // considered removable.
-bool DeadCodeElimination::isLiveInstr(const MachineInstr *MI) const {
+bool DeadCodeElimination::isLiveInstr(NodeAddr<StmtNode *> S) const {
+  const MachineInstr *MI = S.Addr->getCode();
   if (MI->mayStore() || MI->isBranch() || MI->isCall() || MI->isReturn())
     return true;
   if (MI->hasOrderedMemoryRef() || MI->hasUnmodeledSideEffects() ||
@@ -83,7 +84,7 @@ void DeadCodeElimination::scanInstr(NodeAddr<InstrNode*> IA,
       SetQueue<NodeId> &WorkQ) {
   if (!DFG.IsCode<NodeAttrs::Stmt>(IA))
     return;
-  if (!isLiveInstr(NodeAddr<StmtNode*>(IA).Addr->getCode()))
+  if (!isLiveInstr(IA))
     return;
   for (NodeAddr<RefNode*> RA : IA.Addr->members(DFG)) {
     if (!LiveNodes.count(RA.Id))
@@ -160,7 +161,7 @@ bool DeadCodeElimination::collect() {
         if (!LiveNodes.count(RA.Id))
           DeadNodes.insert(RA.Id);
       if (DFG.IsCode<NodeAttrs::Stmt>(IA))
-        if (isLiveInstr(NodeAddr<StmtNode*>(IA).Addr->getCode()))
+        if (isLiveInstr(IA) || DFG.hasUntrackedRef(IA))
           continue;
       if (IsDead(IA)) {
         DeadInstrs.insert(IA.Id);

diff  --git a/llvm/lib/Target/Hexagon/RDFDeadCode.h b/llvm/lib/Target/Hexagon/RDFDeadCode.h
index 859c8161d355c..16e6c6a39aa14 100644
--- a/llvm/lib/Target/Hexagon/RDFDeadCode.h
+++ b/llvm/lib/Target/Hexagon/RDFDeadCode.h
@@ -55,7 +55,7 @@ namespace rdf {
 
     template<typename T> struct SetQueue;
 
-    bool isLiveInstr(const MachineInstr *MI) const;
+    bool isLiveInstr(NodeAddr<StmtNode*> S) const;
     void scanInstr(NodeAddr<InstrNode*> IA, SetQueue<NodeId> &WorkQ);
     void processDef(NodeAddr<DefNode*> DA, SetQueue<NodeId> &WorkQ);
     void processUse(NodeAddr<UseNode*> UA, SetQueue<NodeId> &WorkQ);

diff  --git a/llvm/test/CodeGen/Hexagon/rdf-copy-renamable-reserved.mir b/llvm/test/CodeGen/Hexagon/rdf-copy-renamable-reserved.mir
index 1a74401a2e7be..ea8e5fb3cfcbc 100644
--- a/llvm/test/CodeGen/Hexagon/rdf-copy-renamable-reserved.mir
+++ b/llvm/test/CodeGen/Hexagon/rdf-copy-renamable-reserved.mir
@@ -1,4 +1,4 @@
-# RUN: llc -march=hexagon -run-pass hexagon-rdf-opt %s -o - | FileCheck %s
+# RUN: llc -march=hexagon -run-pass hexagon-rdf-opt -hexagon-rdf-track-reserved %s -o - | FileCheck %s
 
 # Check that r29 gets propagated into the A2_addi, and that the renamable
 # flag is cleared.


        


More information about the llvm-commits mailing list