[llvm] [AArch64] Do not try to fold if getSwappedCondition(CC) has no swapped condition (PR #160753)

via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 25 12:16:33 PDT 2025


https://github.com/AZero13 updated https://github.com/llvm/llvm-project/pull/160753

>From f3647f2f2a7b2a5653c6dd1a0e91552e4063cb88 Mon Sep 17 00:00:00 2001
From: AZero13 <gfunni234 at gmail.com>
Date: Thu, 25 Sep 2025 14:37:04 -0400
Subject: [PATCH] [AArch64] Do not try to fold if getSwappedCondition(CC) has
 no swapped condition

NFC for now, but if we simplify nodes where we can remove a compare with 0 and we are stuck with condition codes MI or PL, we are in trouble, as you cannot swap that.
---
 llvm/lib/Target/AArch64/AArch64ISelLowering.cpp | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp b/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
index a4c1e265f0e63..d0ba87fe94730 100644
--- a/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
+++ b/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
@@ -25764,9 +25764,12 @@ static SDValue reassociateCSELOperandsForCSE(SDNode *N, SelectionDAG &DAG) {
     // Try again with the operands of the SUBS instruction and the condition
     // swapped. Due to canonicalization, this only helps for non-constant
     // operands of the SUBS instruction.
-    std::swap(CmpOpToMatch, CmpOpOther);
-    if (SDValue R = Fold(getSwappedCondition(CC), CmpOpToMatch, CmpOpToMatch))
-      return R;
+    auto NewCC = getSwappedCondition(CC);
+    if (NewCC != AArch64CC::AL) {
+      std::swap(CmpOpToMatch, CmpOpOther);
+      if (SDValue R = Fold(NewCC, CmpOpToMatch, CmpOpOther))
+        return R;
+    }
     return SDValue();
   }
 



More information about the llvm-commits mailing list