[PATCH] D159098: [NFC][AMDGPU] Small cleanup to R600 CF Finalizer

Luke Drummond via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 29 07:50:29 PDT 2023


ldrumm created this revision.
ldrumm added a reviewer: arsenm.
ldrumm added a project: LLVM.
Herald added subscribers: foad, kerbowa, hiraditya, tpr, dstuttard, yaxunl, jvesely, kzhuravl.
Herald added a project: All.
ldrumm requested review of this revision.
Herald added a subscriber: wdng.

A static analyzer was getting aggravated about the use of potentially
uninitialized `DstMI` / `SrcMI`. I don't think that's possible for the
present case which will only use VTX_INST || TEX_INST instructions - all
having a source and destination register - but it couldn't hurt to
ensure that's invariant.

`optional` will do the asserting for us.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D159098

Files:
  llvm/lib/Target/AMDGPU/R600ControlFlowFinalizer.cpp


Index: llvm/lib/Target/AMDGPU/R600ControlFlowFinalizer.cpp
===================================================================
--- llvm/lib/Target/AMDGPU/R600ControlFlowFinalizer.cpp
+++ llvm/lib/Target/AMDGPU/R600ControlFlowFinalizer.cpp
@@ -265,11 +265,8 @@
 
   bool isCompatibleWithClause(const MachineInstr &MI,
                               std::set<unsigned> &DstRegs) const {
-    unsigned DstMI, SrcMI;
-    for (MachineInstr::const_mop_iterator I = MI.operands_begin(),
-                                          E = MI.operands_end();
-         I != E; ++I) {
-      const MachineOperand &MO = *I;
+    std::optional<unsigned> DstMI, SrcMI;
+    for (const MachineOperand &MO : MI.operands()) {
       if (!MO.isReg())
         continue;
       if (MO.isDef()) {
@@ -280,8 +277,8 @@
           DstMI = TRI->getMatchingSuperReg(Reg,
               R600RegisterInfo::getSubRegFromChannel(TRI->getHWRegChan(Reg)),
               &R600::R600_Reg128RegClass);
-      }
-      if (MO.isUse()) {
+      } else {
+        assert(MO.isUse());
         Register Reg = MO.getReg();
         if (R600::R600_Reg128RegClass.contains(Reg))
           SrcMI = Reg;
@@ -291,11 +288,12 @@
               &R600::R600_Reg128RegClass);
       }
     }
-    if ((DstRegs.find(SrcMI) == DstRegs.end())) {
-      DstRegs.insert(DstMI);
-      return true;
-    } else
+    // If we've already seen this def in the given register set, we can't
+    // use a clause instruction
+    if (DstRegs.find(SrcMI.value()) != DstRegs.end())
       return false;
+    DstRegs.insert(DstMI.value());
+    return true;
   }
 
   ClauseFile


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D159098.554336.patch
Type: text/x-patch
Size: 1615 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230829/52266198/attachment.bin>


More information about the llvm-commits mailing list