diff options
| author | Diana Picus <diana.picus@linaro.org> | 2018-01-10 10:01:49 +0000 |
|---|---|---|
| committer | Diana Picus <diana.picus@linaro.org> | 2018-01-10 10:01:49 +0000 |
| commit | 8f14886630c530c61510fb8497c6a59e4adbe181 (patch) | |
| tree | a06cee718d6058843650721b0e72c31150a4382b | |
| parent | 9222b91e24dfefd596b01f51c3e46c247e0115b3 (diff) | |
| download | bcm5719-llvm-8f14886630c530c61510fb8497c6a59e4adbe181.tar.gz bcm5719-llvm-8f14886630c530c61510fb8497c6a59e4adbe181.zip | |
[ARM GlobalISel] Legalize s32/s64 G_FCONSTANT
Legal for hard float.
Change to G_CONSTANT for soft float (but preserve the binary
representation).
llvm-svn: 322164
| -rw-r--r-- | llvm/lib/Target/ARM/ARMLegalizerInfo.cpp | 17 | ||||
| -rw-r--r-- | llvm/test/CodeGen/ARM/GlobalISel/arm-legalize-fp.mir | 56 |
2 files changed, 70 insertions, 3 deletions
diff --git a/llvm/lib/Target/ARM/ARMLegalizerInfo.cpp b/llvm/lib/Target/ARM/ARMLegalizerInfo.cpp index fe526fef97e..b3bfd2a53ad 100644 --- a/llvm/lib/Target/ARM/ARMLegalizerInfo.cpp +++ b/llvm/lib/Target/ARM/ARMLegalizerInfo.cpp @@ -161,7 +161,7 @@ ARMLegalizerInfo::ARMLegalizerInfo(const ARMSubtarget &ST) { setAction({G_ICMP, 1, Ty}, Legal); if (!ST.useSoftFloat() && ST.hasVFP2()) { - for (unsigned BinOp : {G_FADD, G_FSUB, G_FMUL, G_FDIV}) + for (unsigned BinOp : {G_FADD, G_FSUB, G_FMUL, G_FDIV, G_FCONSTANT}) for (auto Ty : {s32, s64}) setAction({BinOp, Ty}, Legal); @@ -183,6 +183,10 @@ ARMLegalizerInfo::ARMLegalizerInfo(const ARMSubtarget &ST) { for (auto Ty : {s32, s64}) setAction({BinOp, Ty}, Libcall); + for (auto Ty : {s32, s64}) { + setAction({G_FCONSTANT, Ty}, Custom); + } + setAction({G_FCMP, s1}, Legal); setAction({G_FCMP, 1, s32}, Custom); setAction({G_FCMP, 1, s64}, Custom); @@ -313,6 +317,7 @@ bool ARMLegalizerInfo::legalizeCustom(MachineInstr &MI, using namespace TargetOpcode; MIRBuilder.setInstr(MI); + LLVMContext &Ctx = MIRBuilder.getMF().getFunction().getContext(); switch (MI.getOpcode()) { default: @@ -329,7 +334,6 @@ bool ARMLegalizerInfo::legalizeCustom(MachineInstr &MI, // Our divmod libcalls return a struct containing the quotient and the // remainder. We need to create a virtual register for it. - auto &Ctx = MIRBuilder.getMF().getFunction().getContext(); Type *ArgTy = Type::getInt32Ty(Ctx); StructType *RetTy = StructType::get(Ctx, {ArgTy, ArgTy}, /* Packed */ true); auto RetVal = MRI.createGenericVirtualRegister( @@ -370,7 +374,6 @@ bool ARMLegalizerInfo::legalizeCustom(MachineInstr &MI, return true; } - auto &Ctx = MIRBuilder.getMF().getFunction().getContext(); assert((OpSize == 32 || OpSize == 64) && "Unsupported operand size"); auto *ArgTy = OpSize == 32 ? Type::getFloatTy(Ctx) : Type::getDoubleTy(Ctx); auto *RetTy = Type::getInt32Ty(Ctx); @@ -415,6 +418,14 @@ bool ARMLegalizerInfo::legalizeCustom(MachineInstr &MI, } break; } + case G_FCONSTANT: { + // Convert to integer constants, while preserving the binary representation. + auto AsInteger = + MI.getOperand(1).getFPImm()->getValueAPF().bitcastToAPInt(); + MIRBuilder.buildConstant(MI.getOperand(0).getReg(), + *ConstantInt::get(Ctx, AsInteger)); + break; + } } MI.eraseFromParent(); diff --git a/llvm/test/CodeGen/ARM/GlobalISel/arm-legalize-fp.mir b/llvm/test/CodeGen/ARM/GlobalISel/arm-legalize-fp.mir index 65e7ccd4ab5..2beb2485997 100644 --- a/llvm/test/CodeGen/ARM/GlobalISel/arm-legalize-fp.mir +++ b/llvm/test/CodeGen/ARM/GlobalISel/arm-legalize-fp.mir @@ -20,6 +20,9 @@ define void @test_fdiv_float() { ret void } define void @test_fdiv_double() { ret void } + define void @test_fconstant_float() { ret void } + define void @test_fconstant_double() { ret void } + define void @test_fcmp_true_s32() { ret void } define void @test_fcmp_false_s32() { ret void } @@ -597,6 +600,59 @@ body: | BX_RET 14, %noreg, implicit %r0, implicit %r1 ... --- +name: test_fconstant_float +# CHECK-LABEL: name: test_fconstant_float +legalized: false +# CHECK: legalized: true +regBankSelected: false +selected: false +tracksRegLiveness: true +registers: + - { id: 0, class: _ } +body: | + bb.0: + liveins: + + ; HARD: [[R:%[0-9]+]]:_(s32) = G_FCONSTANT float -1.25 + ; SOFT-NOT: G_FCONSTANT + ; SOFT: [[R:%[0-9]+]]:_(s32) = G_CONSTANT i32 -1080033280 + ; SOFT-NOT: G_FCONSTANT + %0(s32) = G_FCONSTANT float -1.25 + ; CHECK: %r0 = COPY [[R]] + %r0 = COPY %0(s32) + BX_RET 14, %noreg, implicit %r0 +... +--- +name: test_fconstant_double +# CHECK-LABEL: name: test_fconstant_double +legalized: false +# CHECK: legalized: true +regBankSelected: false +selected: false +tracksRegLiveness: true +registers: + - { id: 0, class: _ } + - { id: 1, class: _ } + - { id: 2, class: _ } +body: | + bb.0: + liveins: + + ; HARD: [[R:%[0-9]+]]:_(s64) = G_FCONSTANT double -2.4 + ; SOFT-NOT: G_FCONSTANT + ; SOFT-DAG: [[HI:%[0-9]+]]:_(s32) = G_CONSTANT i32 -1073532109 + ; SOFT-DAG: [[LO:%[0-9]+]]:_(s32) = G_CONSTANT i32 858993459 + ; SOFT-NOT: G_FCONSTANT + %0(s64) = G_FCONSTANT double -2.4 + ; HARD-DAG: G_UNMERGE_VALUES [[R]](s64) + ; SOFT-DAG: %r0 = COPY [[HI]] + ; SOFT-DAG: %r1 = COPY [[LO]] + %1(s32),%2(s32) = G_UNMERGE_VALUES %0(s64) + %r0 = COPY %2(s32) + %r1 = COPY %1(s32) + BX_RET 14, %noreg, implicit %r0, implicit %r1 +... +--- name: test_fcmp_true_s32 # CHECK-LABEL: name: test_fcmp_true_s32 legalized: false |

