[llvm] [InitUndef] Only compute DeadLaneDetector if subreg liveness enabled (NFC) (PR #108279)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 11 12:46:28 PDT 2024


https://github.com/nikic created https://github.com/llvm/llvm-project/pull/108279

InitUndef currently always computes DeadLaneDetector, but only actually uses it if subreg liveness is enabled for the target. Make the calculation optional to avoid an unnecessary compile-time impact for targets that don't enable subreg liveness.

>From 7c09d636cebb5457dda9122593b219b9ca7caec5 Mon Sep 17 00:00:00 2001
From: Nikita Popov <npopov at redhat.com>
Date: Wed, 11 Sep 2024 12:46:24 +0200
Subject: [PATCH] [InitUndef] Only compute DeadLaneDetector if subreg liveness
 enabled (NFC)

InitUndef currently always computes DeadLaneDetector, but only
actually uses it if subreg liveness is enabled for the target.
Make the calculation optional to avoid an unnecessary compile-time
impact for targets that don't enable subreg liveness.
---
 llvm/lib/CodeGen/InitUndef.cpp | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)

diff --git a/llvm/lib/CodeGen/InitUndef.cpp b/llvm/lib/CodeGen/InitUndef.cpp
index 1613e413712d26..d6f7c0d7cf0f5f 100644
--- a/llvm/lib/CodeGen/InitUndef.cpp
+++ b/llvm/lib/CodeGen/InitUndef.cpp
@@ -84,7 +84,7 @@ class InitUndef : public MachineFunctionPass {
 
 private:
   bool processBasicBlock(MachineFunction &MF, MachineBasicBlock &MBB,
-                         const DeadLaneDetector &DLD);
+                         const DeadLaneDetector *DLD);
   bool handleSubReg(MachineFunction &MF, MachineInstr &MI,
                     const DeadLaneDetector &DLD);
   bool fixupIllOperand(MachineInstr *MI, MachineOperand &MO);
@@ -210,7 +210,7 @@ bool InitUndef::fixupIllOperand(MachineInstr *MI, MachineOperand &MO) {
 }
 
 bool InitUndef::processBasicBlock(MachineFunction &MF, MachineBasicBlock &MBB,
-                                  const DeadLaneDetector &DLD) {
+                                  const DeadLaneDetector *DLD) {
   bool Changed = false;
   for (MachineBasicBlock::iterator I = MBB.begin(); I != MBB.end(); ++I) {
     MachineInstr &MI = *I;
@@ -236,7 +236,7 @@ bool InitUndef::processBasicBlock(MachineFunction &MF, MachineBasicBlock &MBB,
 
     if (isEarlyClobberMI(MI)) {
       if (MRI->subRegLivenessEnabled())
-        Changed |= handleSubReg(MF, MI, DLD);
+        Changed |= handleSubReg(MF, MI, *DLD);
       Changed |= handleReg(&MI);
     }
   }
@@ -260,11 +260,14 @@ bool InitUndef::runOnMachineFunction(MachineFunction &MF) {
   TRI = MRI->getTargetRegisterInfo();
 
   bool Changed = false;
-  DeadLaneDetector DLD(MRI, TRI);
-  DLD.computeSubRegisterLaneBitInfo();
+  std::unique_ptr<DeadLaneDetector> DLD;
+  if (MRI->subRegLivenessEnabled()) {
+    DLD = std::make_unique<DeadLaneDetector>(MRI, TRI);
+    DLD->computeSubRegisterLaneBitInfo();
+  }
 
   for (MachineBasicBlock &BB : MF)
-    Changed |= processBasicBlock(MF, BB, DLD);
+    Changed |= processBasicBlock(MF, BB, DLD.get());
 
   for (auto *DeadMI : DeadInsts)
     DeadMI->eraseFromParent();



More information about the llvm-commits mailing list