mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-23 11:13:28 +01:00
[GlobalISel][Legalizer] Convert the FP constants to the right APFloat type for G_FCONSTANT.
We weren't converting the immediate ConstantFP during legalization, which caused the wrong bit patterns to be emitted for half type FP constants. Fixes PR36106. llvm-svn: 323582
This commit is contained in:
parent
a33bd832ed
commit
8d65a6ec7e
@ -715,7 +715,24 @@ LegalizerHelper::widenScalar(MachineInstr &MI, unsigned TypeIdx, LLT WideTy) {
|
|||||||
}
|
}
|
||||||
case TargetOpcode::G_FCONSTANT: {
|
case TargetOpcode::G_FCONSTANT: {
|
||||||
unsigned DstExt = MRI.createGenericVirtualRegister(WideTy);
|
unsigned DstExt = MRI.createGenericVirtualRegister(WideTy);
|
||||||
MIRBuilder.buildFConstant(DstExt, *MI.getOperand(1).getFPImm());
|
const ConstantFP *CFP = MI.getOperand(1).getFPImm();
|
||||||
|
APFloat Val = CFP->getValueAPF();
|
||||||
|
LLVMContext &Ctx = MIRBuilder.getMF().getFunction().getContext();
|
||||||
|
auto LLT2Sem = [](LLT Ty) {
|
||||||
|
switch (Ty.getSizeInBits()) {
|
||||||
|
case 32:
|
||||||
|
return &APFloat::IEEEsingle();
|
||||||
|
break;
|
||||||
|
case 64:
|
||||||
|
return &APFloat::IEEEdouble();
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
llvm_unreachable("Unhandled fp widen type");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
bool LosesInfo;
|
||||||
|
Val.convert(*LLT2Sem(WideTy), APFloat::rmTowardZero, &LosesInfo);
|
||||||
|
MIRBuilder.buildFConstant(DstExt, *ConstantFP::get(Ctx, Val));
|
||||||
MIRBuilder.buildFPTrunc(MI.getOperand(0).getReg(), DstExt);
|
MIRBuilder.buildFPTrunc(MI.getOperand(0).getReg(), DstExt);
|
||||||
MI.eraseFromParent();
|
MI.eraseFromParent();
|
||||||
return Legalized;
|
return Legalized;
|
||||||
|
@ -75,7 +75,7 @@ body: |
|
|||||||
; CHECK: %w0 = COPY [[C]](s32)
|
; CHECK: %w0 = COPY [[C]](s32)
|
||||||
; CHECK: [[C1:%[0-9]+]]:_(s64) = G_FCONSTANT double 2.000000e+00
|
; CHECK: [[C1:%[0-9]+]]:_(s64) = G_FCONSTANT double 2.000000e+00
|
||||||
; CHECK: %x0 = COPY [[C1]](s64)
|
; CHECK: %x0 = COPY [[C1]](s64)
|
||||||
; CHECK: [[C2:%[0-9]+]]:_(s32) = G_FCONSTANT half 0xH0000
|
; CHECK: [[C2:%[0-9]+]]:_(s32) = G_FCONSTANT float 0.000000e+00
|
||||||
; CHECK: [[FPTRUNC:%[0-9]+]]:_(s16) = G_FPTRUNC [[C2]](s32)
|
; CHECK: [[FPTRUNC:%[0-9]+]]:_(s16) = G_FPTRUNC [[C2]](s32)
|
||||||
; CHECK: [[ANYEXT:%[0-9]+]]:_(s32) = G_ANYEXT [[FPTRUNC]](s16)
|
; CHECK: [[ANYEXT:%[0-9]+]]:_(s32) = G_ANYEXT [[FPTRUNC]](s16)
|
||||||
; CHECK: %w0 = COPY [[ANYEXT]](s32)
|
; CHECK: %w0 = COPY [[ANYEXT]](s32)
|
||||||
|
Loading…
Reference in New Issue
Block a user