Skip to content

Commit 87e1d4a

Browse files
committed
[Legalizer] Soften EXTRACT_ELEMENT on ppcf128
ppc_fp128 values are always split into two f64. Implement soften operation in soft-float mode to handle output f64 correctly.
1 parent c7cae61 commit 87e1d4a

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

llvm/lib/CodeGen/SelectionDAG/LegalizeFloatTypes.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,9 @@ void DAGTypeLegalizer::SoftenFloatResult(SDNode *N, unsigned ResNo) {
6060
#endif
6161
report_fatal_error("Do not know how to soften the result of this "
6262
"operator!");
63-
63+
case ISD::EXTRACT_ELEMENT:
64+
R = SoftenFloatRes_EXTRACT_ELEMENT(N);
65+
break;
6466
case ISD::ARITH_FENCE: R = SoftenFloatRes_ARITH_FENCE(N); break;
6567
case ISD::MERGE_VALUES:R = SoftenFloatRes_MERGE_VALUES(N, ResNo); break;
6668
case ISD::BITCAST: R = SoftenFloatRes_BITCAST(N); break;
@@ -262,6 +264,16 @@ SDValue DAGTypeLegalizer::SoftenFloatRes_ConstantFP(SDNode *N) {
262264
}
263265
}
264266

267+
SDValue DAGTypeLegalizer::SoftenFloatRes_EXTRACT_ELEMENT(SDNode *N) {
268+
SDValue Src = N->getOperand(0);
269+
assert(Src.getValueType() == MVT::ppcf128 &&
270+
Src.getOperand(0)->getOpcode() == ISD::BUILD_PAIR &&
271+
"In floats only ppcf128 can be extracted by element!");
272+
EVT DestVT = EVT::getIntegerVT(*DAG.getContext(), N->getValueSizeInBits(0));
273+
return DAG.getNode(ISD::EXTRACT_ELEMENT, SDLoc(N), DestVT,
274+
Src.getOperand(0), N->getOperand(1));
275+
}
276+
265277
SDValue DAGTypeLegalizer::SoftenFloatRes_EXTRACT_VECTOR_ELT(SDNode *N, unsigned ResNo) {
266278
SDValue NewOp = BitConvertVectorToIntegerVector(N->getOperand(0));
267279
return DAG.getNode(ISD::EXTRACT_VECTOR_ELT, SDLoc(N),

llvm/lib/CodeGen/SelectionDAG/LegalizeTypes.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -541,6 +541,7 @@ class LLVM_LIBRARY_VISIBILITY DAGTypeLegalizer {
541541
SDValue SoftenFloatRes_BITCAST(SDNode *N);
542542
SDValue SoftenFloatRes_BUILD_PAIR(SDNode *N);
543543
SDValue SoftenFloatRes_ConstantFP(SDNode *N);
544+
SDValue SoftenFloatRes_EXTRACT_ELEMENT(SDNode *N);
544545
SDValue SoftenFloatRes_EXTRACT_VECTOR_ELT(SDNode *N, unsigned ResNo);
545546
SDValue SoftenFloatRes_FABS(SDNode *N);
546547
SDValue SoftenFloatRes_FMINNUM(SDNode *N);

llvm/test/CodeGen/PowerPC/ppcsoftops.ll

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,18 @@ define dso_local zeroext i32 @func(double noundef %0, double noundef %1) #0 {
6868
; CHECK-LABEL: __adddf3
6969
}
7070

71+
; To check ppc_fp128 soften without crash
72+
define zeroext i1 @ppcf128_soften(ppc_fp128 %a) #0 {
73+
entry:
74+
%0 = tail call i1 @llvm.is.fpclass.ppcf128(ppc_fp128 %a, i32 100)
75+
ret i1 %0
76+
77+
; CHECK-LABEL: ppcf128_soften
78+
}
79+
7180
; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
7281
declare double @llvm.fmuladd.f64(double, double, double) #1
82+
declare i1 @llvm.is.fpclass.ppcf128(ppc_fp128, i32 immarg) #1
7383

7484
attributes #0 = {"use-soft-float"="true" }
7585
attributes #1 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }

0 commit comments

Comments
 (0)