Skip to content

Conversation

AZero13
Copy link
Contributor

@AZero13 AZero13 commented Sep 25, 2025

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.

@AZero13 AZero13 changed the title Have fallback for getSwappedCondition(CC) in the Fold check. [AArch64] Have fallback for getSwappedCondition(CC) in the Fold check. Sep 25, 2025
@llvmbot
Copy link
Member

llvmbot commented Sep 25, 2025

@llvm/pr-subscribers-backend-aarch64

Author: AZero13 (AZero13)

Changes

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.


Full diff: https://github.com/llvm/llvm-project/pull/160753.diff

1 Files Affected:

  • (modified) llvm/lib/Target/AArch64/AArch64ISelLowering.cpp (+4-1)
diff --git a/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp b/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
index a4c1e265f0e63..0e68d5b570c28 100644
--- a/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
+++ b/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
@@ -25764,8 +25764,11 @@ 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.
+    auto NewCC = getSwappedCondition(CC);
+    if (NewCC == AArch64CC::AL)
+      return SDValue();
     std::swap(CmpOpToMatch, CmpOpOther);
-    if (SDValue R = Fold(getSwappedCondition(CC), CmpOpToMatch, CmpOpToMatch))
+    if (SDValue R = Fold(NewCC, CmpOpToMatch, CmpOpToMatch))
       return R;
     return SDValue();
   }

@AZero13 AZero13 changed the title [AArch64] Have fallback for getSwappedCondition(CC) in the Fold check. [AArch64] Have fallback for getSwappedCondition(CC) in the Fold check (NFC) Sep 25, 2025
@AZero13 AZero13 changed the title [AArch64] Have fallback for getSwappedCondition(CC) in the Fold check (NFC) [AArch64] Do not try to fold if getSwappedCondition(CC) has no swapped condition Sep 25, 2025
@AZero13 AZero13 force-pushed the getswapped branch 2 times, most recently from 89051a4 to f3647f2 Compare September 25, 2025 19:16
…d 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.
@AZero13
Copy link
Contributor Author

AZero13 commented Oct 3, 2025

@davemgreen

@AZero13
Copy link
Contributor Author

AZero13 commented Oct 8, 2025

@topperc

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants