[llvm] [LFI][AArch64] Add rewrites for control flow (PR #192602)

Nick Desaulniers via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 22 13:57:55 PDT 2026


================
@@ -51,3 +51,14 @@ bool MCLFIRewriter::mayModifyRegister(const MCInst &Inst,
                                       MCRegister Reg) const {
   return InstInfo->get(Inst.getOpcode()).hasDefOfPhysReg(Inst, Reg, *RegInfo);
 }
+
+bool MCLFIRewriter::explicitlyModifiesRegister(const MCInst &Inst,
+                                               MCRegister Reg) const {
+  const MCInstrDesc &Desc = InstInfo->get(Inst.getOpcode());
+  for (unsigned I = 0, E = Desc.getNumDefs(); I != E; ++I) {
+    if (Desc.operands()[I].OperandType == MCOI::OPERAND_REGISTER &&
+        RegInfo->isSubRegisterEq(Reg, Inst.getOperand(I).getReg()))
+      return true;
+  }
----------------
nickdesaulniers wrote:

Makes sense.  If you look at the definition of `MCInstrDesc::hasDefOfPhysReg`, it looks like it has two loops, then a call to `MCInstrDesc::hasImplicitDefOfPhysReg`.  Perhaps it's worth making this a new method on `MCInstrDesc`, which `hasDefOfPhysReg` then calls?

Like, it feels like perhaps we _should_ have `MCInstrDesc::hasExplicitDefOfPhysReg`, though none of the other references to `MCOI::OPERAND_REGISTER` looks like they could make use of that.

---

If not, its worth at least a comment in the sources that this is meant to effectively mirror `MCInstrDesc::hasDefOfPhysReg`, minus the implicit defs for the reasons you describe.

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


More information about the llvm-commits mailing list