[PATCH] D140917: [AVR] Optimize away cpi instructions when possible

Ben Shi via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jan 9 20:35:47 PST 2023


benshi001 added a comment.

Generally speaking



================
Comment at: llvm/lib/Target/AVR/AVRInstrInfo.cpp:214
+// specific way).
+static bool setsZeroFlag(MachineInstr *Instr) {
+  switch (Instr->getOpcode()) {
----------------
benshi001 wrote:
> Rename this function to `setsZeroFlagInstr`.
change the parameter to `const MachineInstr *` .


================
Comment at: llvm/lib/Target/AVR/AVRInstrInfo.cpp:251
+  if (CmpInstr.getOpcode() != AVR::CPIRdK)
+    return false; // only optimize CPI instructions
+  if (CmpMask != ~0 || CmpValue != 0)
----------------
Generally speaking, I suggest you make a skeleton first, then handle special situations (current `cpi` and further ones you mentioned in your commit message) in stand alone funcitons, this way would make the code looks more clear.


================
Comment at: llvm/lib/Target/AVR/AVRInstrInfo.cpp:256
+  // Find the instruction that defines the register input for cpi.
+  MachineInstr *SrcRegDef = MRI->getVRegDef(SrcReg);
+
----------------
` const auto *` ?


================
Comment at: llvm/lib/Target/AVR/AVRInstrInfo.cpp:268
+  MachineBasicBlock &CmpMBB = *CmpInstr.getParent();
+  bool FoundDef = false;
+  MachineBasicBlock::reverse_iterator From =
----------------
`FoundDef` -> `FoundClobber` .


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D140917/new/

https://reviews.llvm.org/D140917



More information about the llvm-commits mailing list