[llvm] [LLVM][CodeGen][AArch64] while_le(#, max_int) -> all_active (PR #111183)
Paul Walker via llvm-commits
llvm-commits at lists.llvm.org
Fri Oct 4 09:24:56 PDT 2024
https://github.com/paulwalker-arm created https://github.com/llvm/llvm-project/pull/111183
When the second operand of an incrementing while instruction is the maximum value, comparisons that include equality can never fail.
>From 0c8b01a4d75b6fbed15ecff7d590e99294427e51 Mon Sep 17 00:00:00 2001
From: Paul Walker <paul.walker at arm.com>
Date: Fri, 4 Oct 2024 16:33:12 +0100
Subject: [PATCH] [LLVM][CodeGen][AArch64] while_le(#,max_int) -> all_active
When the second operand of an incrementing while instruction is the
maximum value, comparisons that include equality can never fail.
---
.../lib/Target/AArch64/AArch64ISelLowering.cpp | 7 +++++++
.../CodeGen/AArch64/sve-intrinsics-while.ll | 18 ++++++++----------
2 files changed, 15 insertions(+), 10 deletions(-)
diff --git a/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp b/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
index 48e1b96d841efb..2646db3d64b1d2 100644
--- a/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
+++ b/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
@@ -5530,6 +5530,13 @@ static SDValue optimizeIncrementingWhile(SDValue Op, SelectionDAG &DAG,
SDLoc dl(Op);
APInt X = Op.getConstantOperandAPInt(1);
APInt Y = Op.getConstantOperandAPInt(2);
+
+ // When the second operand is the maximum value, comparisons that include
+ // equality can never fail and thus we can return an all active predicate.
+ if (IsEqual)
+ if (IsSigned ? Y.isMaxSignedValue() : Y.isMaxValue())
+ return DAG.getConstant(1, dl, Op.getValueType());
+
bool Overflow;
APInt NumActiveElems =
IsSigned ? Y.ssub_ov(X, Overflow) : Y.usub_ov(X, Overflow);
diff --git a/llvm/test/CodeGen/AArch64/sve-intrinsics-while.ll b/llvm/test/CodeGen/AArch64/sve-intrinsics-while.ll
index 8380d5ca55cf29..ab4554428be450 100644
--- a/llvm/test/CodeGen/AArch64/sve-intrinsics-while.ll
+++ b/llvm/test/CodeGen/AArch64/sve-intrinsics-while.ll
@@ -128,13 +128,12 @@ define <vscale x 16 x i1> @whilele_b_ii_dont_fold_to_ptrue_overflow() {
ret <vscale x 16 x i1> %out
}
-define <vscale x 16 x i1> @whilele_b_ii_dont_fold_to_ptrue_increment_overflow() {
-; CHECK-LABEL: whilele_b_ii_dont_fold_to_ptrue_increment_overflow:
+define <vscale x 16 x i1> @whilele_b_ii_known_always_true() {
+; CHECK-LABEL: whilele_b_ii_known_always_true:
; CHECK: // %bb.0:
-; CHECK-NEXT: mov w8, #2147483647 // =0x7fffffff
-; CHECK-NEXT: whilele p0.b, wzr, w8
+; CHECK-NEXT: ptrue p0.b
; CHECK-NEXT: ret
- %out = call <vscale x 16 x i1> @llvm.aarch64.sve.whilele.nxv16i1.i32(i32 0, i32 2147483647)
+ %out = call <vscale x 16 x i1> @llvm.aarch64.sve.whilele.nxv16i1.i32(i32 2147483646, i32 2147483647)
ret <vscale x 16 x i1> %out
}
@@ -388,13 +387,12 @@ define <vscale x 16 x i1> @whilels_b_ii_dont_fold_to_ptrue_overflow() {
ret <vscale x 16 x i1> %out
}
-define <vscale x 16 x i1> @whilels_b_ii_dont_fold_to_ptrue_increment_overflow() {
-; CHECK-LABEL: whilels_b_ii_dont_fold_to_ptrue_increment_overflow:
+define <vscale x 16 x i1> @whilels_b_ii_known_always_true() {
+; CHECK-LABEL: whilels_b_ii_known_always_true:
; CHECK: // %bb.0:
-; CHECK-NEXT: mov w8, #-1 // =0xffffffff
-; CHECK-NEXT: whilels p0.b, wzr, w8
+; CHECK-NEXT: ptrue p0.b
; CHECK-NEXT: ret
- %out = call <vscale x 16 x i1> @llvm.aarch64.sve.whilels.nxv16i1.i32(i32 0, i32 4294967295)
+ %out = call <vscale x 16 x i1> @llvm.aarch64.sve.whilels.nxv16i1.i32(i32 4294967294, i32 4294967295)
ret <vscale x 16 x i1> %out
}
More information about the llvm-commits
mailing list