Skip to content

Commit c564157

Browse files
JonPssontstellar
authored andcommitted
[SystemZ] Bugfix in SystemZTargetLowering::combineINT_TO_FP()
Make sure to also handle extended value types to avoid crashing. Resulting integers greater than 64 bits are not optimized (i128 is not a legal type), and vectorizing seems to result in libcalls instead of just scalarization. Other extended vector types like <10 x float> are however now handled and should result in vectorized conversions. Reviewed By: Ulrich Weigand Differential Revision: https://reviews.llvm.org/D125881 (cherry picked from commit 4273e61)
1 parent be653f6 commit c564157

File tree

2 files changed

+43
-6
lines changed

2 files changed

+43
-6
lines changed

llvm/lib/Target/SystemZ/SystemZISelLowering.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6442,22 +6442,26 @@ SDValue SystemZTargetLowering::combineINT_TO_FP(
64426442
SDNode *N, DAGCombinerInfo &DCI) const {
64436443
if (DCI.Level != BeforeLegalizeTypes)
64446444
return SDValue();
6445+
SelectionDAG &DAG = DCI.DAG;
6446+
LLVMContext &Ctx = *DAG.getContext();
64456447
unsigned Opcode = N->getOpcode();
64466448
EVT OutVT = N->getValueType(0);
6447-
SelectionDAG &DAG = DCI.DAG;
6449+
Type *OutLLVMTy = OutVT.getTypeForEVT(Ctx);
64486450
SDValue Op = N->getOperand(0);
6449-
unsigned OutScalarBits = OutVT.getScalarSizeInBits();
6451+
unsigned OutScalarBits = OutLLVMTy->getScalarSizeInBits();
64506452
unsigned InScalarBits = Op->getValueType(0).getScalarSizeInBits();
64516453

64526454
// Insert an extension before type-legalization to avoid scalarization, e.g.:
64536455
// v2f64 = uint_to_fp v2i16
64546456
// =>
64556457
// v2f64 = uint_to_fp (v2i64 zero_extend v2i16)
6456-
if (OutVT.isVector() && OutScalarBits > InScalarBits) {
6457-
MVT ExtVT = MVT::getVectorVT(MVT::getIntegerVT(OutVT.getScalarSizeInBits()),
6458-
OutVT.getVectorNumElements());
6458+
if (OutLLVMTy->isVectorTy() && OutScalarBits > InScalarBits &&
6459+
OutScalarBits <= 64) {
6460+
unsigned NumElts = cast<FixedVectorType>(OutLLVMTy)->getNumElements();
6461+
EVT ExtVT = EVT::getVectorVT(
6462+
Ctx, EVT::getIntegerVT(Ctx, OutLLVMTy->getScalarSizeInBits()), NumElts);
64596463
unsigned ExtOpcode =
6460-
(Opcode == ISD::UINT_TO_FP ? ISD::ZERO_EXTEND : ISD::SIGN_EXTEND);
6464+
(Opcode == ISD::UINT_TO_FP ? ISD::ZERO_EXTEND : ISD::SIGN_EXTEND);
64616465
SDValue ExtOp = DAG.getNode(ExtOpcode, SDLoc(N), ExtVT, Op);
64626466
return DAG.getNode(Opcode, SDLoc(N), OutVT, ExtOp);
64636467
}

llvm/test/CodeGen/SystemZ/vec-move-23.ll

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,3 +130,36 @@ define void @fun7(<4 x i16> %Src, <4 x float>* %Dst) {
130130
ret void
131131
}
132132

133+
; Test that this does not crash but results in scalarized conversions.
134+
define void @fun8(<2 x i64> %dwords, <2 x fp128> *%ptr) {
135+
; CHECK-LABEL: fun8
136+
; CHECK: vlgvg
137+
; CHECK: cxlgbr
138+
%conv = uitofp <2 x i64> %dwords to <2 x fp128>
139+
store <2 x fp128> %conv, <2 x fp128> *%ptr
140+
ret void
141+
}
142+
143+
; Test that this results in vectorized conversions.
144+
define void @fun9(<10 x i16> *%Src, <10 x float> *%ptr) {
145+
; CHECK-LABEL: fun9
146+
; Z15: larl %r1, .LCPI9_0
147+
; Z15-NEXT: vl %v0, 16(%r2), 4
148+
; Z15-NEXT: vl %v1, 0(%r2), 4
149+
; Z15-NEXT: vl %v2, 0(%r1), 3
150+
; Z15-NEXT: vperm %v2, %v2, %v1, %v2
151+
; Z15-NEXT: vuplhh %v1, %v1
152+
; Z15-NEXT: vuplhh %v0, %v0
153+
; Z15-NEXT: vcelfb %v2, %v2, 0, 0
154+
; Z15-NEXT: vcelfb %v1, %v1, 0, 0
155+
; Z15-NEXT: vcelfb %v0, %v0, 0, 0
156+
; Z15-NEXT: vsteg %v0, 32(%r3), 0
157+
; Z15-NEXT: vst %v2, 16(%r3), 4
158+
; Z15-NEXT: vst %v1, 0(%r3), 4
159+
; Z15-NEXT: br %r14
160+
161+
%Val = load <10 x i16>, <10 x i16> *%Src
162+
%conv = uitofp <10 x i16> %Val to <10 x float>
163+
store <10 x float> %conv, <10 x float> *%ptr
164+
ret void
165+
}

0 commit comments

Comments
 (0)