Skip to content
This repository was archived by the owner on Feb 5, 2019. It is now read-only.

Commit 54136ca

Browse files
Kevin QinKevin Qin
authored andcommitted
[AArch64 NEON] Fix a bug to avoid using floating type as condition type in lowering SELECT_CC.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@201395 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 89eb5dc commit 54136ca

File tree

2 files changed

+28
-11
lines changed

2 files changed

+28
-11
lines changed

lib/Target/AArch64/AArch64ISelLowering.cpp

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3036,6 +3036,8 @@ static SDValue LowerVectorSELECT_CC(SDValue Op, SelectionDAG &DAG) {
30363036
SDValue RHS = Op.getOperand(1);
30373037
SDValue IfTrue = Op.getOperand(2);
30383038
SDValue IfFalse = Op.getOperand(3);
3039+
EVT IfTrueVT = IfTrue.getValueType();
3040+
EVT CondVT = IfTrueVT.changeVectorElementTypeToInteger();
30393041
ISD::CondCode CC = cast<CondCodeSDNode>(Op.getOperand(4))->get();
30403042

30413043
// If LHS & RHS are floating point and IfTrue & IfFalse are vectors, we will
@@ -3060,19 +3062,14 @@ static SDValue LowerVectorSELECT_CC(SDValue Op, SelectionDAG &DAG) {
30603062

30613063
SDValue VSetCC = DAG.getSetCC(dl, CVT, LHS, RHS, CC);
30623064
SDValue ResCC = LowerVectorSETCC(VSetCC, DAG);
3063-
EVT IfTrueVT = IfTrue.getValueType();
3064-
EVT CastEltT =
3065-
MVT::getIntegerVT(IfTrueVT.getVectorElementType().getSizeInBits());
3066-
EVT CastVT = EVT::getVectorVT(*DAG.getContext(), CastEltT,
3067-
IfTrueVT.getVectorNumElements());
30683065
if (CEltT.getSizeInBits() < IfTrueVT.getSizeInBits()) {
30693066
EVT DUPVT =
30703067
EVT::getVectorVT(*DAG.getContext(), CEltT,
30713068
IfTrueVT.getSizeInBits() / CEltT.getSizeInBits());
30723069
ResCC = DAG.getNode(AArch64ISD::NEON_VDUPLANE, dl, DUPVT, ResCC,
30733070
DAG.getConstant(0, MVT::i64, false));
30743071

3075-
ResCC = DAG.getNode(ISD::BITCAST, dl, CastVT, ResCC);
3072+
ResCC = DAG.getNode(ISD::BITCAST, dl, CondVT, ResCC);
30763073
} else {
30773074
// FIXME: If IfTrue & IfFalse hold v1i8, v1i16 or v1i32, this function
30783075
// can't handle them and will hit this assert.
@@ -3084,7 +3081,7 @@ static SDValue LowerVectorSELECT_CC(SDValue Op, SelectionDAG &DAG) {
30843081
EVT ExVT = EVT::getVectorVT(*DAG.getContext(), CEltT, ExEltNum);
30853082
ResCC = DAG.getNode(ISD::EXTRACT_SUBVECTOR, dl, ExVT, ResCC,
30863083
DAG.getConstant(0, MVT::i64, false));
3087-
ResCC = DAG.getNode(ISD::BITCAST, dl, CastVT, ResCC);
3084+
ResCC = DAG.getNode(ISD::BITCAST, dl, CondVT, ResCC);
30883085
}
30893086
SDValue VSelect = DAG.getNode(ISD::VSELECT, dl, IfTrue.getValueType(),
30903087
ResCC, IfTrue, IfFalse);
@@ -3113,11 +3110,9 @@ static SDValue LowerVectorSELECT_CC(SDValue Op, SelectionDAG &DAG) {
31133110
}
31143111
SDValue VDup;
31153112
if (IfTrue.getValueType().getVectorNumElements() == 1)
3116-
VDup = DAG.getNode(ISD::SCALAR_TO_VECTOR, dl, IfTrue.getValueType(),
3117-
A64SELECT_CC);
3113+
VDup = DAG.getNode(ISD::SCALAR_TO_VECTOR, dl, CondVT, A64SELECT_CC);
31183114
else
3119-
VDup = DAG.getNode(AArch64ISD::NEON_VDUP, dl, IfTrue.getValueType(),
3120-
A64SELECT_CC);
3115+
VDup = DAG.getNode(AArch64ISD::NEON_VDUP, dl, CondVT, A64SELECT_CC);
31213116
SDValue VSelect = DAG.getNode(ISD::VSELECT, dl, IfTrue.getValueType(),
31223117
VDup, IfTrue, IfFalse);
31233118
return VSelect;

test/CodeGen/AArch64/neon-select_cc.ll

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,17 @@ define <4x float> @test_select_cc_v4f32(float %a, float %b, <4x float> %c, <4x f
160160
ret <4x float> %e
161161
}
162162

163+
define <4x float> @test_select_cc_v4f32_icmp(i32 %a, i32 %b, <4x float> %c, <4x float> %d ) {
164+
; CHECK-LABEL: test_select_cc_v4f32_icmp:
165+
; CHECK: cmp w0, w1, uxtw
166+
; CHECK: csinv w0, wzr, wzr, ne
167+
; CHECK-NEXT: dup v{{[0-9]+}}.4s, w0
168+
; CHECK-NEXT: bsl v{{[0-9]+}}.16b, v0.16b, v1.16b
169+
%cmp31 = icmp eq i32 %a, %b
170+
%e = select i1 %cmp31, <4x float> %c, <4x float> %d
171+
ret <4x float> %e
172+
}
173+
163174
define <1 x double> @test_select_cc_v1f64(double %a, double %b, <1 x double> %c, <1 x double> %d ) {
164175
; CHECK-LABEL: test_select_cc_v1f64:
165176
; CHECK: fcmeq v{{[0-9]+}}.2d, v0.2d, v1.2d
@@ -169,6 +180,17 @@ define <1 x double> @test_select_cc_v1f64(double %a, double %b, <1 x double> %c,
169180
ret <1 x double> %e
170181
}
171182

183+
define <1 x double> @test_select_cc_v1f64_icmp(i64 %a, i64 %b, <1 x double> %c, <1 x double> %d ) {
184+
; CHECK-LABEL: test_select_cc_v1f64_icmp:
185+
; CHECK: cmp x0, x1
186+
; CHECK-NEXT: csinv x0, xzr, xzr, ne
187+
; CHECK-NEXT: fmov d{{[0-9]+}}, x0
188+
; CHECK-NEXT: bsl v{{[0-9]+}}.8b, v0.8b, v1.8b
189+
%cmp31 = icmp eq i64 %a, %b
190+
%e = select i1 %cmp31, <1 x double> %c, <1 x double> %d
191+
ret <1 x double> %e
192+
}
193+
172194
define <2 x double> @test_select_cc_v2f64(double %a, double %b, <2 x double> %c, <2 x double> %d ) {
173195
; CHECK-LABEL: test_select_cc_v2f64:
174196
; CHECK: fcmeq v{{[0-9]+}}.2d, v0.2d, v1.2d

0 commit comments

Comments
 (0)