[llvm] r323582 - [GlobalISel][Legalizer] Convert the FP constants to the right APFloat type for G_FCONSTANT.
Amara Emerson via llvm-commits
llvm-commits at lists.llvm.org
Fri Jan 26 23:07:20 PST 2018
Author: aemerson
Date: Fri Jan 26 23:07:20 2018
New Revision: 323582
URL: http://llvm.org/viewvc/llvm-project?rev=323582&view=rev
Log:
[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.
Modified:
llvm/trunk/lib/CodeGen/GlobalISel/LegalizerHelper.cpp
llvm/trunk/test/CodeGen/AArch64/GlobalISel/legalize-constant.mir
Modified: llvm/trunk/lib/CodeGen/GlobalISel/LegalizerHelper.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/GlobalISel/LegalizerHelper.cpp?rev=323582&r1=323581&r2=323582&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/GlobalISel/LegalizerHelper.cpp (original)
+++ llvm/trunk/lib/CodeGen/GlobalISel/LegalizerHelper.cpp Fri Jan 26 23:07:20 2018
@@ -715,7 +715,24 @@ LegalizerHelper::widenScalar(MachineInst
}
case TargetOpcode::G_FCONSTANT: {
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);
MI.eraseFromParent();
return Legalized;
Modified: llvm/trunk/test/CodeGen/AArch64/GlobalISel/legalize-constant.mir
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/AArch64/GlobalISel/legalize-constant.mir?rev=323582&r1=323581&r2=323582&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/AArch64/GlobalISel/legalize-constant.mir (original)
+++ llvm/trunk/test/CodeGen/AArch64/GlobalISel/legalize-constant.mir Fri Jan 26 23:07:20 2018
@@ -75,7 +75,7 @@ body: |
; CHECK: %w0 = COPY [[C]](s32)
; CHECK: [[C1:%[0-9]+]]:_(s64) = G_FCONSTANT double 2.000000e+00
; 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: [[ANYEXT:%[0-9]+]]:_(s32) = G_ANYEXT [[FPTRUNC]](s16)
; CHECK: %w0 = COPY [[ANYEXT]](s32)
More information about the llvm-commits
mailing list