[llvm] [AArch64] Add a FeatureFuseCmpCSet (PR #153189)

David Green via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 28 13:03:12 PDT 2025


================
@@ -279,6 +279,40 @@ static bool isCCSelectPair(const MachineInstr *FirstMI,
   return false;
 }
 
+/// Compare and cset.
+static bool isCmpCSetPair(const MachineInstr *FirstMI,
+                          const MachineInstr &SecondMI) {
+  if ((SecondMI.getOpcode() == AArch64::CSINCWr &&
+       SecondMI.getOperand(1).getReg() == AArch64::WZR &&
+       SecondMI.getOperand(2).getReg() == AArch64::WZR) ||
+      (SecondMI.getOpcode() == AArch64::CSINCXr &&
+       SecondMI.getOperand(1).getReg() == AArch64::XZR &&
+       SecondMI.getOperand(2).getReg() == AArch64::XZR)) {
+    // Assume the 1st instr to be a wildcard if it is unspecified.
+    if (FirstMI == nullptr)
+      return true;
+
+    if (FirstMI->definesRegister(AArch64::WZR, /*TRI=*/nullptr) ||
+        FirstMI->definesRegister(AArch64::XZR, /*TRI=*/nullptr))
----------------
davemgreen wrote:

I might be making assumptions about how the hardware works, but both instructions do the same thing. They either set the return value to i64 0/1 or they set it to zext(i32 0)/zext(i32 1). So I imagine it should be fine to fuse in both directions.

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


More information about the llvm-commits mailing list