[llvm-branch-commits] [lld] 82a29d7 - [lld][LoongArch] Clean up CALL30 relocation with setK16 and checkInt (#176311)

Cullen Rhodes via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Thu Jan 22 00:27:58 PST 2026


Author: hev
Date: 2026-01-22T08:27:36Z
New Revision: 82a29d757450a8d3c7a06f79a92a334694dd6202

URL: https://github.com/llvm/llvm-project/commit/82a29d757450a8d3c7a06f79a92a334694dd6202
DIFF: https://github.com/llvm/llvm-project/commit/82a29d757450a8d3c7a06f79a92a334694dd6202.diff

LOG: [lld][LoongArch] Clean up CALL30 relocation with setK16 and checkInt (#176311)

(cherry picked from commit fe8447d00796bc4795b28b8036b0f49e5f118f1d)

Added: 
    

Modified: 
    lld/ELF/Arch/LoongArch.cpp

Removed: 
    


################################################################################
diff  --git a/lld/ELF/Arch/LoongArch.cpp b/lld/ELF/Arch/LoongArch.cpp
index 264990be48ec3..9682b4722ac1e 100644
--- a/lld/ELF/Arch/LoongArch.cpp
+++ b/lld/ELF/Arch/LoongArch.cpp
@@ -184,10 +184,6 @@ static uint32_t setJ5(uint32_t insn, uint32_t imm) {
   return (insn & 0xfffffc1f) | (extractBits(imm, 4, 0) << 5);
 }
 
-static uint32_t setK10(uint32_t insn, uint32_t imm) {
-  return (insn & 0xffc003ff) | (extractBits(imm, 9, 0) << 10);
-}
-
 static uint32_t setK12(uint32_t insn, uint32_t imm) {
   return (insn & 0xffc003ff) | (extractBits(imm, 11, 0) << 10);
 }
@@ -651,17 +647,15 @@ void LoongArch::relocate(uint8_t *loc, const Relocation &rel,
     // This relocation is designed for adjacent pcaddu12i+jirl pairs that
     // are patched in one time.
     // The relocation range is [-2G, +2G) (of course must be 4-byte aligned).
-    if ((int64_t)val != llvm::SignExtend64(val, 32))
-      reportRangeError(ctx, loc, rel, Twine(val), llvm::minIntN(32),
-                       llvm::maxIntN(32));
+    checkInt(ctx, loc, val, 32, rel);
     checkAlignment(ctx, loc, val, 4, rel);
     // Although jirl adds the immediate as a signed value, it is always positive
-    // in this case, so no adjustment is needed, unlink CALL36.
+    // in this case, so no adjustment is needed, unlike CALL36.
     uint32_t hi20 = extractBits(val, 31, 12);
     // Despite the name, the lower part is actually 12 bits with 4-byte aligned.
     uint32_t lo10 = extractBits(val, 11, 2);
     write32le(loc, setJ20(read32le(loc), hi20));
-    write32le(loc + 4, setK10(read32le(loc + 4), lo10));
+    write32le(loc + 4, setK16(read32le(loc + 4), lo10));
     return;
   }
 


        


More information about the llvm-branch-commits mailing list