[lld] [llvm] [LoongArch] Use R_LARCH_ALIGN without symbol as much as possible (PR #93775)

Lu Weining via llvm-commits llvm-commits at lists.llvm.org
Thu May 30 20:01:43 PDT 2024


================
@@ -224,20 +224,25 @@ bool LoongArchAsmBackend::shouldInsertFixupForCodeAlign(
   // Create fixup_loongarch_align fixup.
   MCFixup Fixup =
       MCFixup::create(0, Dummy, MCFixupKind(LoongArch::fixup_loongarch_align));
-  const MCSymbolRefExpr *MCSym = getSecToAlignSym()[Sec];
-  if (MCSym == nullptr) {
-    // Create a symbol and make the value of symbol is zero.
-    MCSymbol *Sym = Ctx.createNamedTempSymbol("la-relax-align");
-    Sym->setFragment(&*Sec->getBeginSymbol()->getFragment());
-    Asm.registerSymbol(*Sym);
-    MCSym = MCSymbolRefExpr::create(Sym, Ctx);
-    getSecToAlignSym()[Sec] = MCSym;
-  }
+
+  auto createExtendedValue = [&]() {
+    const MCSymbolRefExpr *MCSym = getSecToAlignSym()[Sec];
+    if (MCSym == nullptr) {
+      // Create a symbol and make the value of symbol is zero.
+      MCSymbol *Sym = Ctx.createNamedTempSymbol("la-relax-align");
+      Sym->setFragment(&*Sec->getBeginSymbol()->getFragment());
+      Asm.registerSymbol(*Sym);
+      MCSym = MCSymbolRefExpr::create(Sym, Ctx);
+      getSecToAlignSym()[Sec] = MCSym;
+    }
+    unsigned Lo = Log2_64(Count) + 1;
----------------
SixWeining wrote:

Thanks, but I find `Log2(AF.getAlignment())` is simpler.

llvm/Support/Alignment.h:
```
/// Returns the log2 of the alignment.
inline unsigned Log2(Align A) { return A.ShiftValue; }
```

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


More information about the llvm-commits mailing list