Skip to content

Commit 52e0150

Browse files
committed
[AArch64] Avoid SCALAR_TO_VECTOR for single FP constant vector.
Currently the code only checks for integer constants (ConstantSDNode) and triggers an infinite cycle for single-element floating point vector constants. We need to check for both FP and integer constants. Reviewed By: t.p.northover Differential Revision: https://reviews.llvm.org/D99384
1 parent 3ccbd4f commit 52e0150

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

llvm/lib/Target/AArch64/AArch64ISelLowering.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9724,7 +9724,7 @@ SDValue AArch64TargetLowering::LowerBUILD_VECTOR(SDValue Op,
97249724
// Convert BUILD_VECTOR where all elements but the lowest are undef into
97259725
// SCALAR_TO_VECTOR, except for when we have a single-element constant vector
97269726
// as SimplifyDemandedBits will just turn that back into BUILD_VECTOR.
9727-
if (isOnlyLowElement && !(NumElts == 1 && isa<ConstantSDNode>(Value))) {
9727+
if (isOnlyLowElement && !(NumElts == 1 && isIntOrFPConstant(Value))) {
97289728
LLVM_DEBUG(dbgs() << "LowerBUILD_VECTOR: only low element used, creating 1 "
97299729
"SCALAR_TO_VECTOR node\n");
97309730
return DAG.getNode(ISD::SCALAR_TO_VECTOR, dl, VT, Value);

llvm/test/CodeGen/AArch64/arm64-build-vector.ll

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,3 +88,20 @@ entry:
8888
%add = fadd <1 x double> %arg, <double 1.0>
8989
ret <1 x double> %add
9090
}
91+
92+
; Make sure BUILD_VECTOR does not get stuck in a loop trying to convert a
93+
; single element FP vector constant from a scalar to vector.
94+
define <1 x double> @convert_single_fp_vector_constant(i1 %cmp) {
95+
; CHECK-LABEL: convert_single_fp_vector_constant:
96+
; CHECK: // %bb.0: // %entry
97+
; CHECK-NEXT: tst w0, #0x1
98+
; CHECK-NEXT: mov x8, #4607182418800017408
99+
; CHECK-NEXT: csetm x9, ne
100+
; CHECK-NEXT: fmov d0, x8
101+
; CHECK-NEXT: fmov d1, x9
102+
; CHECK-NEXT: and.8b v0, v0, v1
103+
; CHECK-NEXT: ret
104+
entry:
105+
%sel = select i1 %cmp, <1 x double> <double 1.000000e+00>, <1 x double> zeroinitializer
106+
ret <1 x double> %sel
107+
}

0 commit comments

Comments
 (0)