diff --git a/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp b/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp index a4c1e265f0e63..3eaa06f500f11 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, CmpOpToMatch)) + return R; + } return SDValue(); }