[llvm] [X86][GlobalISel] Enable G_BRJT (PR #81811)
Evgenii Kudriashov via llvm-commits
llvm-commits at lists.llvm.org
Tue Feb 27 15:04:21 PST 2024
================
@@ -549,6 +559,64 @@ X86LegalizerInfo::X86LegalizerInfo(const X86Subtarget &STI,
verify(*STI.getInstrInfo());
}
+bool X86LegalizerInfo::legalizeCustom(LegalizerHelper &Helper, MachineInstr &MI,
+ LostDebugLocObserver &LocObserver) const {
+ switch (MI.getOpcode()) {
+ case G_BRJT:
+ return legalizeBrJT(Helper, MI);
+ default:
+ llvm_unreachable("instruction is not in switch");
+ }
+}
+
+bool X86LegalizerInfo::legalizeBrJT(LegalizerHelper &Helper,
+ MachineInstr &MI) const {
+ MachineIRBuilder &MIB = Helper.MIRBuilder;
+ MachineFunction &MF = *MI.getMF();
+ MachineRegisterInfo &MRI = *MIB.getMRI();
+ const MachineJumpTableInfo *MJTI = MF.getJumpTableInfo();
+
+ unsigned EntrySize = MJTI->getEntrySize(MF.getDataLayout());
+
+ auto PtrReg = MI.getOperand(0).getReg();
+ auto PtrTy = MRI.getType(PtrReg);
+ auto IdxReg = MI.getOperand(2).getReg();
+ auto IdxTy = MRI.getType(IdxReg);
+
+ MachineMemOperand *MMO = MF.getMachineMemOperand(
+ MachinePointerInfo::getJumpTable(MF), MachineMemOperand::MOLoad,
+ PtrTy.getSizeInBytes(), Align(EntrySize));
+
+ auto ShiftAmt = MIB.buildConstant(IdxTy, Log2_32(PtrTy.getSizeInBytes()));
+ auto Shift = MIB.buildShl(IdxTy, IdxReg, ShiftAmt);
+ auto Target =
+ MIB.buildPtrAdd(PtrTy, PtrReg, Shift->getOperand(0).getReg()).getReg(0);
----------------
e-kud wrote:
You can simply pass `Shift` instead of `Shift->getOperand(0).getReg()`. Also you can drop `getReg(0)` when reassigning `Target` and invoke `getReg` once on the argument of `buildBRIndirect`.
https://github.com/llvm/llvm-project/pull/81811
More information about the llvm-commits
mailing list