Skip to content

Commit 6e198aa

Browse files
[SelectionDAG] Prevent warnings when extracting fixed length vector from scalable.
ComputeNumSignBits and computeKnownBits both trigger "Scalable flag may be dropped" warnings when a fixed length vector is extracted from a scalable vector. This patch assumes nothing about the demanded elements thus matching the behaviour when extracting a scalable vector from a scalable vector. Differential Revision: https://reviews.llvm.org/D83642
1 parent 3cdbacc commit 6e198aa

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2718,6 +2718,9 @@ KnownBits SelectionDAG::computeKnownBits(SDValue Op, const APInt &DemandedElts,
27182718
case ISD::EXTRACT_SUBVECTOR: {
27192719
// Offset the demanded elts by the subvector index.
27202720
SDValue Src = Op.getOperand(0);
2721+
// Bail until we can represent demanded elements for scalable vectors.
2722+
if (Src.getValueType().isScalableVector())
2723+
break;
27212724
uint64_t Idx = Op.getConstantOperandVal(1);
27222725
unsigned NumSrcElts = Src.getValueType().getVectorNumElements();
27232726
APInt DemandedSrcElts = DemandedElts.zextOrSelf(NumSrcElts).shl(Idx);
@@ -3973,6 +3976,9 @@ unsigned SelectionDAG::ComputeNumSignBits(SDValue Op, const APInt &DemandedElts,
39733976
case ISD::EXTRACT_SUBVECTOR: {
39743977
// Offset the demanded elts by the subvector index.
39753978
SDValue Src = Op.getOperand(0);
3979+
// Bail until we can represent demanded elements for scalable vectors.
3980+
if (Src.getValueType().isScalableVector())
3981+
break;
39763982
uint64_t Idx = Op.getConstantOperandVal(1);
39773983
unsigned NumSrcElts = Src.getValueType().getVectorNumElements();
39783984
APInt DemandedSrcElts = DemandedElts.zextOrSelf(NumSrcElts).shl(Idx);

llvm/test/CodeGen/AArch64/sve-fixed-length-subvector.ll

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@
1313
; RUN: llc -aarch64-sve-vector-bits-min=1664 -aarch64-enable-atomic-cfg-tidy=false < %s | FileCheck %s -check-prefixes=CHECK,VBITS_GE_512,VBITS_GE_1024
1414
; RUN: llc -aarch64-sve-vector-bits-min=1792 -aarch64-enable-atomic-cfg-tidy=false < %s | FileCheck %s -check-prefixes=CHECK,VBITS_GE_512,VBITS_GE_1024
1515
; RUN: llc -aarch64-sve-vector-bits-min=1920 -aarch64-enable-atomic-cfg-tidy=false < %s | FileCheck %s -check-prefixes=CHECK,VBITS_GE_512,VBITS_GE_1024
16-
; RUN: llc -aarch64-sve-vector-bits-min=2048 -aarch64-enable-atomic-cfg-tidy=false < %s | FileCheck %s -check-prefixes=CHECK,VBITS_GE_512,VBITS_GE_1024,VBITS_GE_2048
16+
; RUN: llc -aarch64-sve-vector-bits-min=2048 -aarch64-enable-atomic-cfg-tidy=false < %s 2>%t | FileCheck %s -check-prefixes=CHECK,VBITS_GE_512,VBITS_GE_1024,VBITS_GE_2048
17+
; RUN: FileCheck --check-prefix=WARN --allow-empty %s <%t
18+
19+
; WARN-NOT: warning
1720

1821
; Test we can code generater patterns of the form:
1922
; fixed_length_vector = ISD::EXTRACT_SUBVECTOR scalable_vector, 0
@@ -85,4 +88,19 @@ bb1:
8588
ret void
8689
}
8790

91+
;
92+
define <8 x i1> @no_warn_dropped_scalable(<8 x i32>* %in) #0 {
93+
; CHECK-LABEL: no_warn_dropped_scalable:
94+
; CHECK: ptrue [[PG:p[0-9]+]].s, vl8
95+
; CHECK: ld1w { z{{[0-9]+}}.s }, [[PG]]/z, [x0]
96+
; CHECK-COUNT-8: cmp w{{[0-9]+}}, #0
97+
; CHECK: ret
98+
%a = load <8 x i32>, <8 x i32>* %in
99+
br label %bb1
100+
101+
bb1:
102+
%cond = icmp sgt <8 x i32> %a, zeroinitializer
103+
ret <8 x i1> %cond
104+
}
105+
88106
attributes #0 = { "target-features"="+sve" }

0 commit comments

Comments
 (0)