[llvm-branch-commits] [llvm] [LoongArch] Avoid scheduling relaxable code sequence and attach relax relocs (PR #121330)

via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Thu Jan 2 03:49:09 PST 2025


================
@@ -187,18 +187,23 @@ bool LoongArchPreRAExpandPseudo::expandPcalau12iInstPair(
   MachineInstr &MI = *MBBI;
   DebugLoc DL = MI.getDebugLoc();
 
+  const auto &STI = MF->getSubtarget<LoongArchSubtarget>();
+  bool EnableRelax = STI.hasFeature(LoongArch::FeatureRelax);
+
   Register DestReg = MI.getOperand(0).getReg();
   Register ScratchReg =
       MF->getRegInfo().createVirtualRegister(&LoongArch::GPRRegClass);
   MachineOperand &Symbol = MI.getOperand(1);
 
   BuildMI(MBB, MBBI, DL, TII->get(LoongArch::PCALAU12I), ScratchReg)
-      .addDisp(Symbol, 0, FlagsHi);
+      .addDisp(Symbol, 0,
+               EnableRelax ? LoongArchII::addRelaxFlag(FlagsHi) : FlagsHi);
----------------
heiher wrote:

```c++
EnableRelax ? LoongArchII::addRelaxFlag(FlagsHi) : FlagsHi
```

->

```c++
LoongArchII::encodeFlags(FlagsHi, EnableRelax)
```

```c++
static inline unsigned encodeFlags(unsigned Flags, bool Relax) {
  return Flags | (Relax ? MO_RELAX : 0);
}
```

https://github.com/llvm/llvm-project/pull/121330


More information about the llvm-branch-commits mailing list