Skip to content

Commit 710aef8

Browse files
[LLVM][SVE] Relax optimizeIncrementingWhile constant operand requirements.
Only the latter part of optimizeIncrementingWhile requires a constant first operand and so the initial bailout code is preventing the obvious whilele(X,MAX_INT) -> splat(true) combine.
1 parent f97648e commit 710aef8

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

llvm/lib/Target/AArch64/AArch64ISelLowering.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5744,12 +5744,10 @@ static SDValue optimizeIncrementingWhile(SDNode *N, SelectionDAG &DAG,
57445744
unsigned Op0 = N->getOpcode() == ISD::INTRINSIC_WO_CHAIN ? 1 : 0;
57455745
unsigned Op1 = N->getOpcode() == ISD::INTRINSIC_WO_CHAIN ? 2 : 1;
57465746

5747-
if (!isa<ConstantSDNode>(N->getOperand(Op0)) ||
5748-
!isa<ConstantSDNode>(N->getOperand(Op1)))
5747+
if (!isa<ConstantSDNode>(N->getOperand(Op1)))
57495748
return SDValue();
57505749

57515750
SDLoc dl(N);
5752-
APInt X = N->getConstantOperandAPInt(Op0);
57535751
APInt Y = N->getConstantOperandAPInt(Op1);
57545752

57555753
// When the second operand is the maximum value, comparisons that include
@@ -5758,6 +5756,11 @@ static SDValue optimizeIncrementingWhile(SDNode *N, SelectionDAG &DAG,
57585756
if (IsSigned ? Y.isMaxSignedValue() : Y.isMaxValue())
57595757
return DAG.getConstant(1, dl, N->getValueType(0));
57605758

5759+
if (!isa<ConstantSDNode>(N->getOperand(Op0)))
5760+
return SDValue();
5761+
5762+
APInt X = N->getConstantOperandAPInt(Op0);
5763+
57615764
bool Overflow;
57625765
APInt NumActiveElems =
57635766
IsSigned ? Y.ssub_ov(X, Overflow) : Y.usub_ov(X, Overflow);

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,7 @@ define <vscale x 16 x i1> @whilele_b_ii_dont_fold_to_ptrue_overflow() {
131131
define <vscale x 16 x i1> @whilele_b_ii_known_always_true(i32 %a) {
132132
; 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, w0, w8
134+
; CHECK-NEXT: ptrue p0.b
136135
; CHECK-NEXT: ret
137136
%out = call <vscale x 16 x i1> @llvm.aarch64.sve.whilele.nxv16i1.i32(i32 %a, i32 2147483647)
138137
ret <vscale x 16 x i1> %out
@@ -391,8 +390,7 @@ define <vscale x 16 x i1> @whilels_b_ii_dont_fold_to_ptrue_overflow() {
391390
define <vscale x 16 x i1> @whilels_b_ii_known_always_true(i32 %a) {
392391
; 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, w0, w8
393+
; CHECK-NEXT: ptrue p0.b
396394
; CHECK-NEXT: ret
397395
%out = call <vscale x 16 x i1> @llvm.aarch64.sve.whilels.nxv16i1.i32(i32 %a, i32 4294967295)
398396
ret <vscale x 16 x i1> %out

0 commit comments

Comments
 (0)