[llvm] [AMDGPU][SIPreEmitPeephole] mustRetainExeczBranch: use BranchProbability and TargetSchedmodel (PR #109818)

Juan Manuel Martinez CaamaƱo via llvm-commits llvm-commits at lists.llvm.org
Fri Oct 4 04:10:03 PDT 2024


================
@@ -304,11 +311,23 @@ 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) {
 
+  assert(is_contained(Head.successors(), &From));
+
+  const auto *FromIt = find(Head.successors(), &From);
+  assert(FromIt != Head.succ_end());
+
+  auto BranchProb = Head.getSuccProbability(FromIt);
+  assert(!BranchProb.isUnknown());
+  uint64_t BranchTakenCost = TII->getSchedModel().computeInstrLatency(
+      &*Head.getFirstTerminator(), false);
+  constexpr uint64_t BranchNotTakenCost = 1;
----------------
jmmartinez wrote:

I think that keeping 1 may be safe in this case, since it only makes the transformation more unlikely.

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


More information about the llvm-commits mailing list