[llvm] [llvm-exegesis] Implement the loop repetition mode for AArch64 (PR #154751)

David Green via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 21 11:56:55 PDT 2025


================
@@ -141,6 +147,31 @@ class ExegesisAArch64Target : public ExegesisTarget {
     errs() << "setRegTo is not implemented, results will be unreliable\n";
     return {};
   }
+  MCRegister getDefaultLoopCounterRegister(const Triple &) const override {
+    return kDefaultLoopCounterReg;
+  }
+
+  void decrementLoopCounterAndJump(
+      MachineBasicBlock &MBB, MachineBasicBlock &TargetMBB,
+      const MCInstrInfo &MII, MCRegister LoopRegister) const override {
+     // subs LoopRegister, LoopRegister, #1
+    BuildMI(&MBB, DebugLoc(), MII.get(AArch64::SUBSXri))
+        .addDef(LoopRegister)
+        .addUse(LoopRegister)
+        .addImm(1)   // Subtract 1
+        .addImm(0);  // No shift amount
+    // cbnz LoopRegister, TargetMBB
+    BuildMI(&MBB, DebugLoc(), MII.get(AArch64::CBNZX))
----------------
davemgreen wrote:

Could this be either `SUB+CBNZ` or `SUBS+Bcc`? I don't know if there is a lot of difference between the two if LoopRegister needs to get updated. (There might be a chance of fusing the SUBS+Bcc, I'm not sure when that does and doesn't happen).

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


More information about the llvm-commits mailing list