[llvm] [GlobalIsel] Lower integer constants to constant pool in `LegalizerHelper`. (PR #81957)
Mikhail Gudim via llvm-commits
llvm-commits at lists.llvm.org
Thu Feb 15 22:43:55 PST 2024
================
@@ -2987,27 +2987,47 @@ static void getUnmergePieces(SmallVectorImpl<Register> &Pieces,
Pieces.push_back(Unmerge.getReg(I));
}
-LegalizerHelper::LegalizeResult
-LegalizerHelper::lowerFConstant(MachineInstr &MI) {
- Register Dst = MI.getOperand(0).getReg();
-
+static void emitLoadFromConstantPool(Register DstReg, const Constant *ConstVal,
+ MachineIRBuilder &MIRBuilder) {
+ MachineRegisterInfo &MRI = *MIRBuilder.getMRI();
MachineFunction &MF = MIRBuilder.getMF();
const DataLayout &DL = MIRBuilder.getDataLayout();
-
unsigned AddrSpace = DL.getDefaultGlobalsAddressSpace();
LLT AddrPtrTy = LLT::pointer(AddrSpace, DL.getPointerSizeInBits(AddrSpace));
- Align Alignment = Align(DL.getABITypeAlign(
- getFloatTypeForLLT(MF.getFunction().getContext(), MRI.getType(Dst))));
+ LLT DstLLT = MRI.getType(DstReg);
+
+ Align Alignment(DL.getABITypeAlign(ConstVal->getType()));
auto Addr = MIRBuilder.buildConstantPool(
- AddrPtrTy, MF.getConstantPool()->getConstantPoolIndex(
- MI.getOperand(1).getFPImm(), Alignment));
+ AddrPtrTy,
+ MF.getConstantPool()->getConstantPoolIndex(ConstVal, Alignment));
- MachineMemOperand *MMO = MF.getMachineMemOperand(
- MachinePointerInfo::getConstantPool(MF), MachineMemOperand::MOLoad,
- MRI.getType(Dst), Alignment);
+ MachineMemOperand *MMO =
+ MF.getMachineMemOperand(MachinePointerInfo::getConstantPool(MF),
+ MachineMemOperand::MOLoad, DstLLT, Alignment);
+
+ MIRBuilder.buildLoadInstr(TargetOpcode::G_LOAD, DstReg, Addr, *MMO);
+}
+
+LegalizerHelper::LegalizeResult
+LegalizerHelper::lowerConstant(MachineInstr &MI) {
+ MachineOperand ConstOperand = MI.getOperand(1);
----------------
mgudim wrote:
done.
https://github.com/llvm/llvm-project/pull/81957
More information about the llvm-commits
mailing list