[llvm] [AArch64] Signed comparison using CMN is safe when the subtraction is nsw (PR #141993)
Craig Topper via llvm-commits
llvm-commits at lists.llvm.org
Mon Jun 9 13:36:49 PDT 2025
================
@@ -3375,8 +3375,20 @@ bool isLegalCmpImmed(APInt C) {
return isLegalArithImmed(C.abs().getZExtValue());
}
-static bool cannotBeIntMin(SDValue CheckedVal, SelectionDAG &DAG) {
- KnownBits KnownSrc = DAG.computeKnownBits(CheckedVal);
+static bool isSafeSignedCMN(SDValue Op, SelectionDAG &DAG) {
+ // 0 - INT_MIN sign wraps, so no signed wrap means cmn is safe.
+ if (Op->getFlags().hasNoSignedWrap())
+ return true;
+
+ // We can still figure out if the second operand is safe to use
+ // in a CMN instruction by checking if it is known to be not the minimum
+ // signed value. If it is not, then we can safely use CMN.
+ // FIXME: Can we can remove this check and simply rely on
+ // Op->getFlags().hasNoSignedWrap() once SelectionDAG/ISelLowering never
+ // creates subtract nodes, or SelectionDAG/ISelLowering consistently sets them
----------------
topperc wrote:
What do you mean by "once SelectionDAG/ISelLowering never creates subtract nodes"?
https://github.com/llvm/llvm-project/pull/141993
More information about the llvm-commits
mailing list