[llvm] [AArch64] Allow peephole to optimize AND + signed compare with 0 (PR #153608)

Benjamin Maxwell via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 22 09:01:05 PDT 2025


================
@@ -1921,7 +1998,8 @@ static bool canInstrSubstituteCmpInstr(MachineInstr &MI, MachineInstr &CmpInstr,
   // 1) MI and CmpInstr set N and V to the same value.
   // 2) If MI is add/sub with no-signed-wrap, it produces a poison value when
   //    signed overflow occurs, so CmpInstr could still be simplified away.
-  if (NZVCUsed->V && !MI.getFlag(MachineInstr::NoSWrap))
+  // 3) ANDS/BICS on AArch64 always sets V to 0, so it is safe to look through.
----------------
MacDue wrote:

I'm not sure what you mean by "SLE 0 is not MI", but I'm saying that 

```
x = ands/bics ...
subs/adds x, #0 
```

Set `N` and `V` to the same flags as just:
```
x = ands/bics ...
```

Which is what that comment says, so your new comment seems redundant. 


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


More information about the llvm-commits mailing list