<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/202127>202127</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [RISC-V][lld] lld.riscv.missing_lui_to_cli_relax
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          XiaobingHou1219
      </td>
    </tr>
</table>

<pre>
    I ran into this while reducing a RISC-V linker testcase. The reproducer is small, and I have been seeing the same result consistently across three reruns.

### Summary
GNU ld.bfd relaxes the first instruction to c.li x10,0, but ld.lld leaves the pair as lui x10,0x1; addi x10,x10,-0x800 on the same legal input and linker script.

### Expected behavior
An RV32IC image computes the absolute address 0x7fe using lui %hi(foo) plus addi %lo(foo). After final layout, the high part becomes zero and the first instruction should be compressed to c.li while the low part remains addi x10,x0,2046.

### Environment
- linker route: gas+ld.lld with gas+ld.bfd control
- march: rv32ic
- mabi: ilp32
- first failing stage: link
- local stability check: True

### Reduced testcase
These are the reduced input files from the minimized reproducer I used locally:

#### `c-lui-2.ld`
```ld
ENTRY(_start)
SECTIONS {
        .text 0x00000000 : {
                *(.text*)
        }
}
```

#### `c-lui-2.s`
```asm
        .option nopic
        .text
        .align 1
        .globl _start
        .type _start, @function
_start:
        lui a0,%hi(foo)
        addi a0,a0,%lo(foo)
        .skip 0x7f8
foo:
        ret
        .size _start, .-_start
```

### Reproduction notes
- This packaged root does not have a single canonical `run.ps1` wrapper.
- Use the reduced inputs under `case/` and follow the commands documented in `case/README.md`.
- Stable witness outputs, when present, are preserved under `verify/run1..run3/`.

### What I checked
- Reduced inputs are preserved under case/.
- Stable witness outputs are preserved under verify/run1..run3/.
- The strict recheck says stable normalized run signatures across three runs: True.
- Tracker guidance link: https://llvm.org/docs/HowToSubmitABug.html
- evidence summary: 3 clean reproductions under hunt/verify/lld_cli_relax_from_lui/run1..run3 show stable GNU ld.bfd output beginning with c.li x10,0 and stable ld.lld output beginning with lui x10,0x1; addi x10,x10,-0x800.

### Notes
upstream///binutils-gdb/ld/testsuite/ld-riscv-elf/c-lui-2.s

Root key: `lld.riscv.missing_lui_to_cli_relax`
Case id: `20260526-lld-cli-relax-from-lui`

</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJyMVktz67oN_jX0BmONTNmOvfDCebg3i57OJLm37SpDkbDEhiI1fDjx-fUd6GE5bXLvOePjyCBAfPgEfKQIQVcWccdWt2x1PxMp1s7v_qWFK7WtfnNpwRfbWenUefcIXljQNjqItQ7wXmuD4FElqW0FAp4en-_mf4DR9g09RAxRioAZvNTk1nqnkkQPOkBohDGM34GwCh6hFieEEtFCQKS9Yo0QRENhIZkI0tmgQ0QbzRmE9C4EiLVHcvDJhozl9yzfD9-86D_wnJpG-HNv_tuP38GorDwq8GjEB4YuzVH7EEHbEH2SUTsL0YHMjIaPRc74Hf2HMkWKNUaBQXEaQluhPYgAJl2cPxasuAWh1Gjpv-f5xybPgTYfKzNYCQPatil2LAysBel1G7-p5-GjRRlRQYm1OGnne4e9hac_Cv54B7oRFYJ0TZviAFKUwZkUkUB5DAHyj5sjQgrEMyFnfFVrxjdH5xjfQmtS6AtgfGXcZSGD_TGih6O2woARZ5ciUUM5al3V0AofoUTpGgzwE73ryvqa4lC7ZKiMDivBQnXhve8rCjTuvd_WYyO0DZ-IpS-eL9ffcWVP2jvboI390nyk2LsUkRV7qERg_HZ4r-861pOFukQ6G70zY3QjvKwpzJ8KruVkLjVZtWkLPhr7io9CG2I5RFF1CQnABYyTwtBSqY2OZ5A1yjdyevEJvy7piUaNiBomq19_qTEgCN9T5gefvrGO2mCAo3dNt9hoqxv9E9X1OD5CIvY7PObMiv2XySk_W-dybpKe88wots4Hl3Xef4zqDQ8_Xp7-zfjmNUThI-Pb3vz8cPfy-I8fz8BubscU2yziR4T8Ix_-ATFw7UAfvmd803l2j9tp8eZ-eL48jGB-pY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