[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:11:01 PST 2023


benshi001 added inline comments.


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


================
Comment at: llvm/lib/Target/AVR/AVRInstrInfo.cpp:252
+    return false; // only optimize CPI instructions
+  if (CmpMask != ~0 || CmpValue != 0)
+    return false; // currently we only support optimizing comparisons against 0
----------------
Can it be 

```
if ((CmpMask & CmpValue) != 0)
  return false;
```

This look more clear.


================
Comment at: llvm/lib/Target/AVR/AVRInstrInfo.cpp:267
+  const TargetRegisterInfo *TRI = &getRegisterInfo();
+  MachineBasicBlock &CmpMBB = *CmpInstr.getParent();
+  bool FoundDef = false;
----------------
`const MachineBasicBlock &` ?


================
Comment at: llvm/lib/Target/AVR/AVRInstrInfo.cpp:269
+  bool FoundDef = false;
+  MachineBasicBlock::reverse_iterator From =
+      std::next(MachineBasicBlock::reverse_iterator(CmpInstr));
----------------
Use `auto From` ?


================
Comment at: llvm/lib/Target/AVR/AVRInstrInfo.cpp:273
+    if (&Inst == SrcRegDef) {
+      FoundDef = true;
+      break;
----------------
This piece of searching previous instr clobbers `SREG` code, can be isolated to a stand alone `bool` function, it may be used by future optimizations you have planed. 


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