[llvm] [AArch64] Fold -smin/-smax(X, 0) to neg + masked AND (PR #207671)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Jul 6 00:31:25 PDT 2026
github-actions[bot] wrote:
<!--LLVM CODE FORMAT COMMENT: {clang-format}-->
:warning: C/C++ code formatter, clang-format found issues in your code. :warning:
<details>
<summary>
You can test this locally with the following command:
</summary>
``````````bash
git-clang-format --diff origin/main HEAD --extensions cpp -- llvm/lib/Target/AArch64/AArch64ISelLowering.cpp --diff_from_common_commit
``````````
:warning:
The reproduction instructions above might return results for more than one PR
in a stack if you are using a stacked PR workflow. You can limit the results by
changing `origin/main` to the base branch/commit you want to compare against.
:warning:
</details>
<details>
<summary>
View the diff from clang-format here.
</summary>
``````````diff
diff --git a/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp b/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
index cafc9fb6e..eeff26094 100644
--- a/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
+++ b/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
@@ -23428,8 +23428,9 @@ static SDValue performAddCombineForShiftedOperands(SDNode *N,
// (sub 0, (smin X, 0)) --> (and (sub 0, X), (sra X, bw-1))
// (sub 0, (smax X, 0)) --> (and (sub 0, X), (not (sra X, bw-1)))
// smin(X,0)/smax(X,0) select to (X & M)/(X & ~M) with sign mask M = X sra bw-1.
-// Since M is 0/-1 the negate distributes: -(X & M) == (-X) & M. The latter keeps
-// the shift off the negate's critical path so both issue in parallel; same count.
+// Since M is 0/-1 the negate distributes: -(X & M) == (-X) & M. The latter
+// keeps the shift off the negate's critical path so both issue in parallel;
+// same count.
static SDValue performNegSMinMaxZeroCombine(SDNode *N, SelectionDAG &DAG) {
if (N->getOpcode() != ISD::SUB || !isNullConstant(N->getOperand(0)))
return SDValue();
@@ -23448,7 +23449,8 @@ static SDValue performNegSMinMaxZeroCombine(SDNode *N, SelectionDAG &DAG) {
// ahead of the sign mask would defeat that and cost an instruction.
if (any_of(N->users(), [](const SDNode *U) {
unsigned UOpc = U->getOpcode();
- return UOpc == ISD::SETCC || UOpc == ISD::SELECT_CC || UOpc == ISD::BR_CC;
+ return UOpc == ISD::SETCC || UOpc == ISD::SELECT_CC ||
+ UOpc == ISD::BR_CC;
}))
return SDValue();
``````````
</details>
https://github.com/llvm/llvm-project/pull/207671
More information about the llvm-commits
mailing list