@@ -2987,53 +2987,48 @@ static void getUnmergePieces(SmallVectorImpl<Register> &Pieces,
2987
2987
Pieces.push_back (Unmerge.getReg (I));
2988
2988
}
2989
2989
2990
- LegalizerHelper::LegalizeResult
2991
- LegalizerHelper::lowerConstant (MachineInstr &MI) {
2992
- Register Dst = MI. getOperand ( 0 ). getReg ();
2993
-
2990
+ static void emitLoadFromConstantPool (
2991
+ Register DstReg, const Constant *ConstVal,
2992
+ MachineIRBuilder &MIRBuilder) {
2993
+ MachineRegisterInfo &MRI = *MIRBuilder. getMRI ();
2994
2994
MachineFunction &MF = MIRBuilder.getMF ();
2995
2995
const DataLayout &DL = MIRBuilder.getDataLayout ();
2996
-
2997
2996
unsigned AddrSpace = DL.getDefaultGlobalsAddressSpace ();
2998
2997
LLT AddrPtrTy = LLT::pointer (AddrSpace, DL.getPointerSizeInBits (AddrSpace));
2999
- Align Alignment = Align (DL.getABITypeAlign (
3000
- getFloatTypeForLLT (MF.getFunction ().getContext (), MRI.getType (Dst))));
2998
+ LLT DstLLT = MRI.getType (DstReg);
2999
+
3000
+ Align Alignment (DL.getABITypeAlign (ConstVal->getType ()));
3001
3001
3002
3002
auto Addr = MIRBuilder.buildConstantPool (
3003
- AddrPtrTy, MF. getConstantPool ()-> getConstantPoolIndex (
3004
- MI. getOperand ( 1 ). getFPImm () , Alignment));
3003
+ AddrPtrTy,
3004
+ MF. getConstantPool ()-> getConstantPoolIndex (ConstVal , Alignment));
3005
3005
3006
- MachineMemOperand *MMO = MF.getMachineMemOperand (
3007
- MachinePointerInfo::getConstantPool (MF), MachineMemOperand::MOLoad,
3008
- MRI.getType (Dst), Alignment);
3006
+ MachineMemOperand *MMO =
3007
+ MF.getMachineMemOperand (MachinePointerInfo::getConstantPool (MF),
3008
+ MachineMemOperand::MOLoad, DstLLT, Alignment);
3009
+
3010
+ MIRBuilder.buildLoadInstr (TargetOpcode::G_LOAD, DstReg, Addr, *MMO);
3011
+ }
3012
+
3013
+ LegalizerHelper::LegalizeResult
3014
+ LegalizerHelper::lowerConstant (MachineInstr &MI) {
3015
+ MachineOperand ConstOperand = MI.getOperand (1 );
3016
+ assert (ConstOperand.isCImm ());
3017
+ const Constant *ConstantVal = ConstOperand.getCImm ();
3009
3018
3010
- MIRBuilder. buildLoadInstr (TargetOpcode::G_LOAD, Dst, Addr, *MMO );
3019
+ emitLoadFromConstantPool (MI. getOperand ( 0 ). getReg (), ConstantVal, MIRBuilder );
3011
3020
MI.eraseFromParent ();
3012
3021
3013
3022
return Legalized;
3014
3023
}
3015
3024
3016
3025
LegalizerHelper::LegalizeResult
3017
3026
LegalizerHelper::lowerFConstant (MachineInstr &MI) {
3018
- Register Dst = MI.getOperand (0 ).getReg ();
3019
-
3020
- MachineFunction &MF = MIRBuilder.getMF ();
3021
- const DataLayout &DL = MIRBuilder.getDataLayout ();
3022
-
3023
- unsigned AddrSpace = DL.getDefaultGlobalsAddressSpace ();
3024
- LLT AddrPtrTy = LLT::pointer (AddrSpace, DL.getPointerSizeInBits (AddrSpace));
3025
- Align Alignment = Align (DL.getABITypeAlign (
3026
- getFloatTypeForLLT (MF.getFunction ().getContext (), MRI.getType (Dst))));
3027
-
3028
- auto Addr = MIRBuilder.buildConstantPool (
3029
- AddrPtrTy, MF.getConstantPool ()->getConstantPoolIndex (
3030
- MI.getOperand (1 ).getFPImm (), Alignment));
3031
-
3032
- MachineMemOperand *MMO = MF.getMachineMemOperand (
3033
- MachinePointerInfo::getConstantPool (MF), MachineMemOperand::MOLoad,
3034
- MRI.getType (Dst), Alignment);
3027
+ MachineOperand ConstOperand = MI.getOperand (1 );
3028
+ assert (ConstOperand.isFPImm ());
3029
+ const Constant *ConstantVal = ConstOperand.getFPImm ();
3035
3030
3036
- MIRBuilder. buildLoadInstr (TargetOpcode::G_LOAD, Dst, Addr, *MMO );
3031
+ emitLoadFromConstantPool (MI. getOperand ( 0 ). getReg (), ConstantVal, MIRBuilder );
3037
3032
MI.eraseFromParent ();
3038
3033
3039
3034
return Legalized;
0 commit comments