[llvm] [AMDGPU][SIPreEmitPeephole] mustRetainExeczBranch: estimate ThenBlock cost using MachineTraceInfo (PR #111117)

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Fri Oct 4 02:32:33 PDT 2024


Juan Manuel Martinez =?utf-8?q?Caamaño?= <juamarti at amd.com>,
Juan Manuel Martinez =?utf-8?q?Caamaño?= <juamarti at amd.com>
Message-ID:
In-Reply-To: <llvm.org/llvm/llvm-project/pull/111117 at github.com>


================
@@ -304,11 +311,20 @@ bool SIPreEmitPeephole::getBlockDestinations(
   return true;
 }
 
-bool SIPreEmitPeephole::mustRetainExeczBranch(
-    const MachineBasicBlock &From, const MachineBasicBlock &To) const {
-  unsigned NumInstr = 0;
-  const MachineFunction *MF = From.getParent();
+bool SIPreEmitPeephole::mustRetainExeczBranch(const MachineBasicBlock &Head,
+                                              const MachineBasicBlock &From,
+                                              const MachineBasicBlock &To) {
 
+  const auto *FromIt = find(Head.successors(), &From);
+  assert(FromIt != Head.succ_end());
+
+  auto BranchProb = Head.getSuccProbability(FromIt);
+  assert(!BranchProb.isUnknown());
+  unsigned BranchCost = TII->getSchedModel().computeInstrLatency(
+      &*Head.getFirstTerminator(), false);
----------------
arsenm wrote:

Ought to just pass in the branch instruction the caller already found, rather than doing the block scan again in getFirstTerminator 

https://github.com/llvm/llvm-project/pull/111117


More information about the llvm-commits mailing list