Skip to content

Commit 0073582

Browse files
author
Joe Ellis
committed
[DAGCombiner] Use getVectorElementCount inside visitINSERT_SUBVECTOR
This avoids TypeSize-/ElementCount-related warnings. Differential Revision: https://reviews.llvm.org/D92747
1 parent 5522547 commit 0073582

File tree

2 files changed

+35
-5
lines changed

2 files changed

+35
-5
lines changed

llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21008,8 +21008,8 @@ SDValue DAGCombiner::visitINSERT_SUBVECTOR(SDNode *N) {
2100821008
if (N0.isUndef() && N1.getOpcode() == ISD::BITCAST &&
2100921009
N1.getOperand(0).getOpcode() == ISD::EXTRACT_SUBVECTOR &&
2101021010
N1.getOperand(0).getOperand(1) == N2 &&
21011-
N1.getOperand(0).getOperand(0).getValueType().getVectorNumElements() ==
21012-
VT.getVectorNumElements() &&
21011+
N1.getOperand(0).getOperand(0).getValueType().getVectorElementCount() ==
21012+
VT.getVectorElementCount() &&
2101321013
N1.getOperand(0).getOperand(0).getValueType().getSizeInBits() ==
2101421014
VT.getSizeInBits()) {
2101521015
return DAG.getBitcast(VT, N1.getOperand(0).getOperand(0));
@@ -21026,7 +21026,7 @@ SDValue DAGCombiner::visitINSERT_SUBVECTOR(SDNode *N) {
2102621026
EVT CN1VT = CN1.getValueType();
2102721027
if (CN0VT.isVector() && CN1VT.isVector() &&
2102821028
CN0VT.getVectorElementType() == CN1VT.getVectorElementType() &&
21029-
CN0VT.getVectorNumElements() == VT.getVectorNumElements()) {
21029+
CN0VT.getVectorElementCount() == VT.getVectorElementCount()) {
2103021030
SDValue NewINSERT = DAG.getNode(ISD::INSERT_SUBVECTOR, SDLoc(N),
2103121031
CN0.getValueType(), CN0, CN1, N2);
2103221032
return DAG.getBitcast(VT, NewINSERT);
@@ -21107,8 +21107,10 @@ SDValue DAGCombiner::visitINSERT_SUBVECTOR(SDNode *N) {
2110721107
// If the input vector is a concatenation, and the insert replaces
2110821108
// one of the pieces, we can optimize into a single concat_vectors.
2110921109
if (N0.getOpcode() == ISD::CONCAT_VECTORS && N0.hasOneUse() &&
21110-
N0.getOperand(0).getValueType() == N1.getValueType()) {
21111-
unsigned Factor = N1.getValueType().getVectorNumElements();
21110+
N0.getOperand(0).getValueType() == N1.getValueType() &&
21111+
N0.getOperand(0).getValueType().isScalableVector() ==
21112+
N1.getValueType().isScalableVector()) {
21113+
unsigned Factor = N1.getValueType().getVectorMinNumElements();
2111221114
SmallVector<SDValue, 8> Ops(N0->op_begin(), N0->op_end());
2111321115
Ops[InsIdx / Factor] = N1;
2111421116
return DAG.getNode(ISD::CONCAT_VECTORS, SDLoc(N), VT, Ops);
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
; RUN: llc < %s -o /dev/null 2>&1 | FileCheck --allow-empty %s
2+
3+
; This regression test is defending against a ElementCount warning 'Possible incorrect use of
4+
; EVT::getVectorNumElements() for scalable vector'. This warning appeared in
5+
; DAGCombiner::visitINSERT_SUBVECTOR because of the use of getVectorNumElements() on scalable
6+
; types.
7+
8+
; If this check fails please read test/CodeGen/AArch64/README for instructions on how to resolve it.
9+
; CHECK-NOT: warning:
10+
11+
target triple = "aarch64-unknown-linux-gnu"
12+
attributes #0 = {"target-features"="+sve"}
13+
14+
declare <16 x float> @llvm.experimental.vector.extract.v16f32.nxv4f32(<vscale x 4 x float>, i64)
15+
declare <vscale x 2 x double> @llvm.experimental.vector.insert.nxv2f64.v8f64(<vscale x 2 x double>, <8 x double>, i64)
16+
17+
define <vscale x 2 x double> @reproducer_one(<vscale x 4 x float> %vec_a) #0 {
18+
%a = call <16 x float> @llvm.experimental.vector.extract.v16f32.nxv4f32(<vscale x 4 x float> %vec_a, i64 0)
19+
%b = bitcast <16 x float> %a to <8 x double>
20+
%retval = call <vscale x 2 x double> @llvm.experimental.vector.insert.nxv2f64.v8f64(<vscale x 2 x double> undef, <8 x double> %b, i64 0)
21+
ret <vscale x 2 x double> %retval
22+
}
23+
24+
define <vscale x 2 x double> @reproducer_two(<4 x double> %a, <4 x double> %b) #0 {
25+
%concat = shufflevector <4 x double> %a, <4 x double> %b, <8 x i32> <i32 4, i32 5, i32 6, i32 7, i32 0, i32 1, i32 2, i32 3>
26+
%retval = call <vscale x 2 x double> @llvm.experimental.vector.insert.nxv2f64.v8f64(<vscale x 2 x double> undef, <8 x double> %concat, i64 0)
27+
ret <vscale x 2 x double> %retval
28+
}

0 commit comments

Comments
 (0)