Skip to content

Commit f1ade1f

Browse files
[LLVM][CodeGen][AArch64] while_le(#,max_int) -> all_active (#111183)
When the second operand of an incrementing while instruction is the maximum value, comparisons that include equality can never fail.
1 parent cd290a6 commit f1ade1f

File tree

2 files changed

+15
-10
lines changed

2 files changed

+15
-10
lines changed

llvm/lib/Target/AArch64/AArch64ISelLowering.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5587,6 +5587,13 @@ static SDValue optimizeIncrementingWhile(SDValue Op, SelectionDAG &DAG,
55875587
SDLoc dl(Op);
55885588
APInt X = Op.getConstantOperandAPInt(1);
55895589
APInt Y = Op.getConstantOperandAPInt(2);
5590+
5591+
// When the second operand is the maximum value, comparisons that include
5592+
// equality can never fail and thus we can return an all active predicate.
5593+
if (IsEqual)
5594+
if (IsSigned ? Y.isMaxSignedValue() : Y.isMaxValue())
5595+
return DAG.getConstant(1, dl, Op.getValueType());
5596+
55905597
bool Overflow;
55915598
APInt NumActiveElems =
55925599
IsSigned ? Y.ssub_ov(X, Overflow) : Y.usub_ov(X, Overflow);

llvm/test/CodeGen/AArch64/sve-intrinsics-while.ll

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -128,13 +128,12 @@ define <vscale x 16 x i1> @whilele_b_ii_dont_fold_to_ptrue_overflow() {
128128
ret <vscale x 16 x i1> %out
129129
}
130130

131-
define <vscale x 16 x i1> @whilele_b_ii_dont_fold_to_ptrue_increment_overflow() {
132-
; CHECK-LABEL: whilele_b_ii_dont_fold_to_ptrue_increment_overflow:
131+
define <vscale x 16 x i1> @whilele_b_ii_known_always_true() {
132+
; CHECK-LABEL: whilele_b_ii_known_always_true:
133133
; CHECK: // %bb.0:
134-
; CHECK-NEXT: mov w8, #2147483647 // =0x7fffffff
135-
; CHECK-NEXT: whilele p0.b, wzr, w8
134+
; CHECK-NEXT: ptrue p0.b
136135
; CHECK-NEXT: ret
137-
%out = call <vscale x 16 x i1> @llvm.aarch64.sve.whilele.nxv16i1.i32(i32 0, i32 2147483647)
136+
%out = call <vscale x 16 x i1> @llvm.aarch64.sve.whilele.nxv16i1.i32(i32 2147483646, i32 2147483647)
138137
ret <vscale x 16 x i1> %out
139138
}
140139

@@ -388,13 +387,12 @@ define <vscale x 16 x i1> @whilels_b_ii_dont_fold_to_ptrue_overflow() {
388387
ret <vscale x 16 x i1> %out
389388
}
390389

391-
define <vscale x 16 x i1> @whilels_b_ii_dont_fold_to_ptrue_increment_overflow() {
392-
; CHECK-LABEL: whilels_b_ii_dont_fold_to_ptrue_increment_overflow:
390+
define <vscale x 16 x i1> @whilels_b_ii_known_always_true() {
391+
; CHECK-LABEL: whilels_b_ii_known_always_true:
393392
; CHECK: // %bb.0:
394-
; CHECK-NEXT: mov w8, #-1 // =0xffffffff
395-
; CHECK-NEXT: whilels p0.b, wzr, w8
393+
; CHECK-NEXT: ptrue p0.b
396394
; CHECK-NEXT: ret
397-
%out = call <vscale x 16 x i1> @llvm.aarch64.sve.whilels.nxv16i1.i32(i32 0, i32 4294967295)
395+
%out = call <vscale x 16 x i1> @llvm.aarch64.sve.whilels.nxv16i1.i32(i32 4294967294, i32 4294967295)
398396
ret <vscale x 16 x i1> %out
399397
}
400398

0 commit comments

Comments
 (0)