[llvm] [LoongArch] Ensure PseudoLA* can be hoisted (PR #94723)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Jun 24 19:37:32 PDT 2024
================
@@ -796,33 +797,48 @@ SDValue LoongArchTargetLowering::getAddr(NodeTy *N, SelectionDAG &DAG,
// This is not actually used, but is necessary for successfully matching
// the PseudoLA_*_LARGE nodes.
SDValue Tmp = DAG.getConstant(0, DL, Ty);
- if (IsLocal)
+ if (IsLocal) {
// This generates the pattern (PseudoLA_PCREL_LARGE tmp sym), that
// eventually becomes the desired 5-insn code sequence.
- return SDValue(DAG.getMachineNode(LoongArch::PseudoLA_PCREL_LARGE, DL, Ty,
+ Load = SDValue(DAG.getMachineNode(LoongArch::PseudoLA_PCREL_LARGE, DL, Ty,
Tmp, Addr),
0);
-
- // This generates the pattern (PseudoLA_GOT_LARGE tmp sym), that eventually
- // becomes the desired 5-insn code sequence.
- return SDValue(
- DAG.getMachineNode(LoongArch::PseudoLA_GOT_LARGE, DL, Ty, Tmp, Addr),
- 0);
+ } else {
+ // This generates the pattern (PseudoLA_GOT_LARGE tmp sym), that
+ // eventually becomes the desired 5-insn code sequence.
+ Load = SDValue(
+ DAG.getMachineNode(LoongArch::PseudoLA_GOT_LARGE, DL, Ty, Tmp, Addr),
+ 0);
+ }
+ break;
}
case CodeModel::Small:
case CodeModel::Medium:
- if (IsLocal)
+ if (IsLocal) {
// This generates the pattern (PseudoLA_PCREL sym), which expands to
// (addi.w/d (pcalau12i %pc_hi20(sym)) %pc_lo12(sym)).
- return SDValue(
+ Load = SDValue(
DAG.getMachineNode(LoongArch::PseudoLA_PCREL, DL, Ty, Addr), 0);
+ } else {
+ // This generates the pattern (PseudoLA_GOT sym), which expands to (ld.w/d
+ // (pcalau12i %got_pc_hi20(sym)) %got_pc_lo12(sym)).
+ Load =
+ SDValue(DAG.getMachineNode(LoongArch::PseudoLA_GOT, DL, Ty, Addr), 0);
+ }
+ }
- // This generates the pattern (PseudoLA_GOT sym), which expands to (ld.w/d
- // (pcalau12i %got_pc_hi20(sym)) %got_pc_lo12(sym)).
- return SDValue(DAG.getMachineNode(LoongArch::PseudoLA_GOT, DL, Ty, Addr),
- 0);
+ if (!IsLocal) {
+ MachineFunction &MF = DAG.getMachineFunction();
+ MachineMemOperand *MemOp = MF.getMachineMemOperand(
+ MachinePointerInfo::getGOT(MF),
+ MachineMemOperand::MOLoad | MachineMemOperand::MODereferenceable |
+ MachineMemOperand::MOInvariant,
+ LLT(Ty.getSimpleVT()), Align(Ty.getFixedSizeInBits() / 8));
+ DAG.setNodeMemRefs(cast<MachineSDNode>(Load.getNode()), {MemOp});
----------------
heiher wrote:
Done. Thanks.
https://github.com/llvm/llvm-project/pull/94723
More information about the llvm-commits
mailing list