[FastISel][AArch64] Refactor float zero materialization. NFCI.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@216403 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Juergen Ributzka 2014-08-25 19:58:05 +00:00
parent f9526ac188
commit 670885e56e

View File

@ -218,6 +218,7 @@ public:
// Backend specific FastISel code. // Backend specific FastISel code.
unsigned TargetMaterializeAlloca(const AllocaInst *AI) override; unsigned TargetMaterializeAlloca(const AllocaInst *AI) override;
unsigned TargetMaterializeConstant(const Constant *C) override; unsigned TargetMaterializeConstant(const Constant *C) override;
unsigned TargetMaterializeFloatZero(const ConstantFP* CF) override;
explicit AArch64FastISel(FunctionLoweringInfo &funcInfo, explicit AArch64FastISel(FunctionLoweringInfo &funcInfo,
const TargetLibraryInfo *libInfo) const TargetLibraryInfo *libInfo)
@ -283,31 +284,24 @@ unsigned AArch64FastISel::AArch64MaterializeInt(const ConstantInt *CI, MVT VT) {
} }
unsigned AArch64FastISel::AArch64MaterializeFP(const ConstantFP *CFP, MVT VT) { unsigned AArch64FastISel::AArch64MaterializeFP(const ConstantFP *CFP, MVT VT) {
// Positive zero (+0.0) has to be materialized with a fmov from the zero
// register, because the immediate version of fmov cannot encode zero.
if (CFP->isNullValue())
return TargetMaterializeFloatZero(CFP);
if (VT != MVT::f32 && VT != MVT::f64) if (VT != MVT::f32 && VT != MVT::f64)
return 0; return 0;
const APFloat Val = CFP->getValueAPF(); const APFloat Val = CFP->getValueAPF();
bool Is64Bit = (VT == MVT::f64); bool Is64Bit = (VT == MVT::f64);
// This checks to see if we can use FMOV instructions to materialize // This checks to see if we can use FMOV instructions to materialize
// a constant, otherwise we have to materialize via the constant pool. // a constant, otherwise we have to materialize via the constant pool.
if (TLI.isFPImmLegal(Val, VT)) { if (TLI.isFPImmLegal(Val, VT)) {
unsigned ResultReg = createResultReg(TLI.getRegClassFor(VT)); int Imm =
// Positive zero (+0.0) has to be materialized with a fmov from the zero Is64Bit ? AArch64_AM::getFP64Imm(Val) : AArch64_AM::getFP32Imm(Val);
// register, because the immediate version of fmov cannot encode zero. assert((Imm != -1) && "Cannot encode floating-point constant.");
if (Val.isPosZero()) {
unsigned ZReg = Is64Bit ? AArch64::XZR : AArch64::WZR;
unsigned Opc = Is64Bit ? AArch64::FMOVXDr : AArch64::FMOVWSr;
BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, TII.get(Opc), ResultReg)
.addReg(ZReg, getKillRegState(true));
return ResultReg;
}
int Imm = Is64Bit ? AArch64_AM::getFP64Imm(Val)
: AArch64_AM::getFP32Imm(Val);
unsigned Opc = Is64Bit ? AArch64::FMOVDi : AArch64::FMOVSi; unsigned Opc = Is64Bit ? AArch64::FMOVDi : AArch64::FMOVSi;
BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, TII.get(Opc), ResultReg) return FastEmitInst_i(Opc, TLI.getRegClassFor(VT), Imm);
.addImm(Imm);
return ResultReg;
} }
// Materialize via constant pool. MachineConstantPool wants an explicit // Materialize via constant pool. MachineConstantPool wants an explicit
@ -319,14 +313,13 @@ unsigned AArch64FastISel::AArch64MaterializeFP(const ConstantFP *CFP, MVT VT) {
unsigned CPI = MCP.getConstantPoolIndex(cast<Constant>(CFP), Align); unsigned CPI = MCP.getConstantPoolIndex(cast<Constant>(CFP), Align);
unsigned ADRPReg = createResultReg(&AArch64::GPR64commonRegClass); unsigned ADRPReg = createResultReg(&AArch64::GPR64commonRegClass);
BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, TII.get(AArch64::ADRP), BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, TII.get(AArch64::ADRP),
ADRPReg) ADRPReg).addConstantPoolIndex(CPI, 0, AArch64II::MO_PAGE);
.addConstantPoolIndex(CPI, 0, AArch64II::MO_PAGE);
unsigned Opc = Is64Bit ? AArch64::LDRDui : AArch64::LDRSui; unsigned Opc = Is64Bit ? AArch64::LDRDui : AArch64::LDRSui;
unsigned ResultReg = createResultReg(TLI.getRegClassFor(VT)); unsigned ResultReg = createResultReg(TLI.getRegClassFor(VT));
BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, TII.get(Opc), ResultReg) BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, TII.get(Opc), ResultReg)
.addReg(ADRPReg) .addReg(ADRPReg)
.addConstantPoolIndex(CPI, 0, AArch64II::MO_PAGEOFF | AArch64II::MO_NC); .addConstantPoolIndex(CPI, 0, AArch64II::MO_PAGEOFF | AArch64II::MO_NC);
return ResultReg; return ResultReg;
} }
@ -395,6 +388,22 @@ unsigned AArch64FastISel::TargetMaterializeConstant(const Constant *C) {
return 0; return 0;
} }
unsigned AArch64FastISel::TargetMaterializeFloatZero(const ConstantFP* CFP) {
assert(CFP->isNullValue() &&
"Floating-point constant is not a positive zero.");
MVT VT;
if (!isTypeLegal(CFP->getType(), VT))
return 0;
if (VT != MVT::f32 && VT != MVT::f64)
return 0;
bool Is64Bit = (VT == MVT::f64);
unsigned ZReg = Is64Bit ? AArch64::XZR : AArch64::WZR;
unsigned Opc = Is64Bit ? AArch64::FMOVXDr : AArch64::FMOVWSr;
return FastEmitInst_r(Opc, TLI.getRegClassFor(VT), ZReg, /*IsKill=*/true);
}
// Computes the address to get to an object. // Computes the address to get to an object.
bool AArch64FastISel::ComputeAddress(const Value *Obj, Address &Addr, Type *Ty) bool AArch64FastISel::ComputeAddress(const Value *Obj, Address &Addr, Type *Ty)
{ {