Skip to content

Commit 1a493b0

Browse files
committed
[PowerPC] Add missing handling for half precision
The fix for PR39865 took care of some of the handling for half precision but it missed a number of issues that still exist. This patch fixes the remaining issues that cause crashes in the PPC back end. Fixes: https://bugs.llvm.org/show_bug.cgi?id=45776 Differential revision: https://reviews.llvm.org/D79283
1 parent eddcce0 commit 1a493b0

File tree

6 files changed

+1151
-179
lines changed

6 files changed

+1151
-179
lines changed

llvm/lib/Target/PowerPC/PPCISelLowering.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10755,6 +10755,7 @@ SDValue PPCTargetLowering::LowerFP_EXTEND(SDValue Op, SelectionDAG &DAG) const {
1075510755
assert(Op.getOpcode() == ISD::FP_EXTEND &&
1075610756
"Should only be called for ISD::FP_EXTEND");
1075710757

10758+
// FIXME: handle extends from half precision float vectors on P9.
1075810759
// We only want to custom lower an extend from v2f32 to v2f64.
1075910760
if (Op.getValueType() != MVT::v2f64 ||
1076010761
Op.getOperand(0).getValueType() != MVT::v2f32)
@@ -10968,6 +10969,11 @@ void PPCTargetLowering::ReplaceNodeResults(SDNode *N,
1096810969
case ISD::BITCAST:
1096910970
// Don't handle bitcast here.
1097010971
return;
10972+
case ISD::FP_EXTEND:
10973+
SDValue Lowered = LowerFP_EXTEND(SDValue(N, 0), DAG);
10974+
if (Lowered)
10975+
Results.push_back(Lowered);
10976+
return;
1097110977
}
1097210978
}
1097310979

llvm/lib/Target/PowerPC/PPCISelLowering.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -640,7 +640,7 @@ namespace llvm {
640640
/// then the VPERM for the shuffle. All in all a very slow sequence.
641641
TargetLoweringBase::LegalizeTypeAction getPreferredVectorAction(MVT VT)
642642
const override {
643-
if (VT.getScalarSizeInBits() % 8 == 0)
643+
if (VT.getVectorNumElements() != 1 && VT.getScalarSizeInBits() % 8 == 0)
644644
return TypeWidenVector;
645645
return TargetLoweringBase::getPreferredVectorAction(VT);
646646
}

llvm/lib/Target/PowerPC/PPCInstrVSX.td

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3658,6 +3658,13 @@ def : Pat<(f32 (extloadf16 xoaddr:$src)),
36583658
(f32 (COPY_TO_REGCLASS (XSCVHPDP (LXSIHZX xoaddr:$src)), VSSRC))>;
36593659
def : Pat<(truncstoref16 f32:$src, xoaddr:$dst),
36603660
(STXSIHX (XSCVDPHP (COPY_TO_REGCLASS $src, VSFRC)), xoaddr:$dst)>;
3661+
def : Pat<(f64 (f16_to_fp i32:$A)),
3662+
(f64 (XSCVHPDP (MTVSRWZ $A)))>;
3663+
def : Pat<(f32 (f16_to_fp i32:$A)),
3664+
(f32 (COPY_TO_REGCLASS (XSCVHPDP (MTVSRWZ $A)), VSSRC))>;
3665+
def : Pat<(i32 (fp_to_f16 f32:$A)),
3666+
(i32 (MFVSRWZ (XSCVDPHP (COPY_TO_REGCLASS $A, VSFRC))))>;
3667+
def : Pat<(i32 (fp_to_f16 f64:$A)), (i32 (MFVSRWZ (XSCVDPHP $A)))>;
36613668

36623669
// Vector sign extensions
36633670
def : Pat<(f64 (PPCVexts f64:$A, 1)),

0 commit comments

Comments
 (0)