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