[llvm] Remove dead flags from virtual registers, but only when not compiling for MIPS (PR #86462)

via llvm-commits llvm-commits at lists.llvm.org
Sun Mar 24 19:38:46 PDT 2024


https://github.com/AtariDreams updated https://github.com/llvm/llvm-project/pull/86462

>From f0f310b634131acea3214cdded4524d85de73c86 Mon Sep 17 00:00:00 2001
From: Rose <gfunni234 at gmail.com>
Date: Sun, 24 Mar 2024 22:14:59 -0400
Subject: [PATCH] Remove dead flags from virtual registers, but only when not
 compiling for MIPS

---
 llvm/lib/CodeGen/LiveVariables.cpp | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/llvm/lib/CodeGen/LiveVariables.cpp b/llvm/lib/CodeGen/LiveVariables.cpp
index b85526cfb380b6..92d2e7938b4ab4 100644
--- a/llvm/lib/CodeGen/LiveVariables.cpp
+++ b/llvm/lib/CodeGen/LiveVariables.cpp
@@ -38,6 +38,8 @@
 #include "llvm/Support/Debug.h"
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/raw_ostream.h"
+#include "llvm/Target/TargetMachine.h"
+#include "llvm/TargetParser/Triple.h"
 #include <algorithm>
 using namespace llvm;
 
@@ -494,6 +496,8 @@ void LiveVariables::runOnInstr(MachineInstr &MI,
   SmallVector<unsigned, 4> UseRegs;
   SmallVector<unsigned, 4> DefRegs;
   SmallVector<unsigned, 1> RegMasks;
+  Triple::ArchType Arch = MF->getTarget().getTargetTriple().getArch();
+  bool isMips = Triple::getArchTypePrefix(Arch) == "mips";
   for (unsigned i = 0; i != NumOperandsToProcess; ++i) {
     MachineOperand &MO = MI.getOperand(i);
     if (MO.isRegMask()) {
@@ -512,8 +516,13 @@ void LiveVariables::runOnInstr(MachineInstr &MI,
       assert(MO.isDef());
       // FIXME: We should not remove any dead flags. However the MIPS RDDSP
       // instruction needs it at the moment: http://llvm.org/PR27116.
-      if (MOReg.isPhysical() && !MRI->isReserved(MOReg))
-        MO.setIsDead(false);
+      if (isMips) {
+        if (MOReg.isPhysical() && !MRI->isReserved(MOReg))
+          MO.setIsDead(false);
+      } else {
+        if (!(MOReg.isPhysical() && MRI->isReserved(MOReg)))
+          MO.setIsDead(false);
+      }
       DefRegs.push_back(MOReg);
     }
   }



More information about the llvm-commits mailing list