[llvm] [X86][CodeGen] Return true when MIR is changed after optimizeCompareInstr (PR #91723)

Shengchen Kan via llvm-commits llvm-commits at lists.llvm.org
Fri May 10 20:22:50 PDT 2024


================
@@ -5169,7 +5169,7 @@ bool X86InstrInfo::optimizeCompareInstr(MachineInstr &CmpInstr, Register SrcReg,
     // Fall through to optimize Cmp if Cmp is CMPrr or CMPri.
     if (NewOpcode == X86::CMP64rm || NewOpcode == X86::CMP32rm ||
         NewOpcode == X86::CMP16rm || NewOpcode == X86::CMP8rm)
-      return false;
+      return true;
----------------
KanRobert wrote:

```
      if ((isUncoalescableCopy(*MI) &&
           optimizeUncoalescableCopy(*MI, LocalMIs)) ||
          (MI->isCompare() && optimizeCmpInstr(*MI)) ||
          (MI->isSelect() && optimizeSelect(*MI, LocalMIs))) {
        // MI is deleted.
        LocalMIs.erase(MI);
        Changed = true;
        continue;
      }

      if (MI->isConditionalBranch() && optimizeCondBranch(*MI)) {
        Changed = true;
        continue;
      }

      if (isCoalescableCopy(*MI) && optimizeCoalescableCopy(*MI)) {
        // MI is just rewritten.
        Changed = true;
        continue;
      }
```
According to the call site,it's wrong whether it returns `true` or `false`.

`true` breaks the assumption that  `optimizeCmpInstr` deletes the MI.
`false` makes the flag `-print-changed` not work correctly.

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


More information about the llvm-commits mailing list