Skip to content

Commit 185a4f5

Browse files
committed
[llvm] Adding scalarization of llvm.vector.insert
Needed handling the case of scalarizing operands of subvector insertion.
1 parent 1bb48c4 commit 185a4f5

File tree

3 files changed

+36
-2
lines changed

3 files changed

+36
-2
lines changed

llvm/lib/CodeGen/SelectionDAG/LegalizeTypes.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -809,6 +809,7 @@ class LLVM_LIBRARY_VISIBILITY DAGTypeLegalizer {
809809
// Vector Operand Scalarization: <1 x ty> -> ty.
810810
bool ScalarizeVectorOperand(SDNode *N, unsigned OpNo);
811811
SDValue ScalarizeVecOp_BITCAST(SDNode *N);
812+
SDValue ScalarizeVecOp_INSERT_SUBVECTOR(SDNode *N, unsigned OpNo);
812813
SDValue ScalarizeVecOp_UnaryOp(SDNode *N);
813814
SDValue ScalarizeVecOp_UnaryOp_StrictFP(SDNode *N);
814815
SDValue ScalarizeVecOp_CONCAT_VECTORS(SDNode *N);

llvm/lib/CodeGen/SelectionDAG/LegalizeVectorTypes.cpp

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -675,6 +675,9 @@ bool DAGTypeLegalizer::ScalarizeVectorOperand(SDNode *N, unsigned OpNo) {
675675
case ISD::BITCAST:
676676
Res = ScalarizeVecOp_BITCAST(N);
677677
break;
678+
case ISD::INSERT_SUBVECTOR:
679+
Res = ScalarizeVecOp_INSERT_SUBVECTOR(N, OpNo);
680+
break;
678681
case ISD::ANY_EXTEND:
679682
case ISD::ZERO_EXTEND:
680683
case ISD::SIGN_EXTEND:
@@ -766,6 +769,24 @@ SDValue DAGTypeLegalizer::ScalarizeVecOp_BITCAST(SDNode *N) {
766769
N->getValueType(0), Elt);
767770
}
768771

772+
/// If the value to subvector is a vector that needs to be scalarized, it must
773+
/// be <1 x ty>. Return the element instead.
774+
SDValue DAGTypeLegalizer::ScalarizeVecOp_INSERT_SUBVECTOR(SDNode *N,
775+
unsigned OpNo) {
776+
// If the destination vector is unary, we can just return the source vector
777+
auto src = GetScalarizedVector(N->getOperand(1));
778+
if (OpNo == 0) {
779+
return src;
780+
}
781+
782+
auto dest = N->getOperand(0);
783+
auto idx = N->getOperand(2);
784+
return DAG.getNode(ISD::INSERT_VECTOR_ELT, SDLoc(N), N->getValueType(0), dest,
785+
src, idx);
786+
787+
return GetScalarizedVector(src);
788+
}
789+
769790
/// If the input is a vector that needs to be scalarized, it must be <1 x ty>.
770791
/// Do the operation on the element instead.
771792
SDValue DAGTypeLegalizer::ScalarizeVecOp_UnaryOp(SDNode *N) {
@@ -5891,8 +5912,11 @@ SDValue DAGTypeLegalizer::WidenVecRes_SETCC(SDNode *N) {
58915912
InOp1 = GetWidenedVector(InOp1);
58925913
InOp2 = GetWidenedVector(InOp2);
58935914
} else {
5894-
InOp1 = DAG.WidenVector(InOp1, SDLoc(N));
5895-
InOp2 = DAG.WidenVector(InOp2, SDLoc(N));
5915+
do {
5916+
InOp1 = DAG.WidenVector(InOp1, SDLoc(N));
5917+
InOp2 = DAG.WidenVector(InOp2, SDLoc(N));
5918+
} while (ElementCount::isKnownLT(
5919+
InOp1.getValueType().getVectorElementCount(), WidenEC));
58965920
}
58975921

58985922
// Assume that the input and output will be widen appropriately. If not,

llvm/test/CodeGen/AArch64/aarch64-neon-v1i1-setcc.ll

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,3 +67,12 @@ if.then:
6767
if.end:
6868
ret i32 1;
6969
}
70+
71+
define dso_local <1 x half> @cmp_select(<1 x half> %i105, <1 x half> %in) {
72+
; CHECK-LABEL: @cmp_select
73+
; CHECL: fcmge
74+
newFuncRoot:
75+
%i179 = fcmp uno <1 x half> %i105, zeroinitializer
76+
%i180 = select <1 x i1> %i179, <1 x half> %in, <1 x half> %i105
77+
ret <1 x half> %i180
78+
}

0 commit comments

Comments
 (0)