Skip to content
gaulPublic

About

Examine RISC-V machine code to find suboptimal instruction sequences

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

126 Commits

Folders and files

Repository files navigation

riscvlint

A RISC-V analogue of armlint: a static checker for missed peephole opportunities in riscv64 binaries.

Fifty-five checks and two audits (-a imm, -a const) are implemented, and the ledger's candidate list is empty. TODO.md is that ledger: every candidate that was measured, the population it came back with, and the ones rejected on that evidence. What got written was decided by the corpus rather than by intuition, and what did not get written was rejected the same way.

Checks

Fifty-five of them, and the table lists the forty-six that report something over the corpus. Twelve of those -- the jump pair, the constant chain, the no-op, the push run, the zero store, the zero branch, the andi pair, the max clamp, the immediate operand, the mask, the jump threading and the floating-point constant built through an integer register -- were written for the JetStream corpus of TODO.md and measured there first, and the release run, the cancelling pair, the needless copy, the scratch-register call and the shared tail were sized over the SpiderMonkey corpus there, the complement check came out of a SpiderMonkey patch, the t0 call out of a probe for what only RISC-V has, and the move spelling and the fixed branch out of the ISA manual's and RISE's optimization guide's advice; their rows here are what they report over this corpus, and their entries in the ledger say what that is. Nine report nothing over this corpus -- the bit count because no baseline object declares Zbb; the three indexed loads, the equality branch and the compare-exchange loop because those five require their extension to be positively present rather than merely un-denied, and no object declares Zilx, Zibi or Zacas; the unsigned divide by a power of two because all three toolchains already do that fold themselves; and the release run and the scratch-register call because each of them frees a frame with one adjustment and calls through the link register. Those entries below say why. Every figure is what the check itself reports over the corpus -- 108,165,211 instructions of three toolchains across 31 objects -- rather than what a mining tool estimated for it. The two have differed by an order of magnitude every time both were measured.

The table is generated, not maintained: scripts/check_table.py scans the corpus and prints it, which is how adding two objects stopped silently leaving every figure describing the other 29. Each object is read under its own declared extensions, no -m, so a Zcb figure is what riscvlint would tell that object's owner rather than what rebuilding it would buy. bytes comes from each finding's own stated saving and sized says how many findings stated one -- assumed marks the row where no finding does and the arithmetic is uniform instead.

check C++ Rust Go sites bytes sized
instruction compressible to a base C form 33,792 1,235 2,961,593 2,996,620 5,993,240 all
call pair foldable to jal 120,580 171,665 56 292,301 1,169,204 assumed
redundant stack-pointer restore 204,543 11,683 0 216,226 864,904 all
computation a live register already holds 42,573 3,450 4,915 50,938 106,004 all
call through t0 that pops the return-address stack 1 0 48,207 48,208 0 all
instruction compressible to a Zcb form 706 181 29,762 30,649 61,298 all
dead register definition 14,151 265 7,876 22,292 60,126 all
load of a value the register still holds 13,957 519 5,592 20,068 50,496 all
constant re-materialization 16,410 571 1,457 18,438 36,876 all
slli + srli foldable to zext.w 2 52 18,071 18,125 50,178 all
slli + add foldable to shNadd 73 165 13,180 13,418 23,842 all
redundant sign or zero extension 8,283 333 1,593 10,209 25,074 all
copy its only reader could do without 4,307 1,027 4,399 9,733 22,428 all
conditional branch over an unconditional jump 9,031 340 331 9,702 28,072 all
load of a just-stored value 5,244 267 4,041 9,552 8,200 all
slli + srli foldable to zext.h 0 0 9,522 9,522 29,634 all
transfer to an unconditional jump 7,221 301 1,824 9,346 0 all
base add foldable into memory offset 5,768 429 2,993 9,190 26,216 all
constant built in more instructions than li needs 3,553 257 4,964 8,774 13,944 all
redundant reload 3,631 231 4,408 8,270 10,878 all
run of zero stores one wider store would do 5,942 143 1,292 7,377 37,928 all
store of a value the slot already holds 1,552 225 5,341 7,118 21,128 all
comparison a branch could have made 6,880 42 0 6,922 17,422 all
transfer to the instruction that follows it 4,299 831 20 5,150 10,354 all
dead store to a frame slot 395 1 4,172 4,568 17,160 all
branch over a move foldable to max or min 0 5 3,459 3,464 9,964 all
slli + srai foldable to sext.b or sext.h 0 0 2,562 2,562 6,450 all
not + and/or/xor foldable to andn/orn/xnor 2 1 2,518 2,521 9,152 all
constant loaded for an immediate operand 2,267 209 0 2,476 7,784 all
jump pair foldable to j 46 1,973 12 2,031 8,124 all
tail every jump to one label repeats 1,035 119 430 1,584 35,132 all
instruction with no architectural effect 1,223 63 282 1,568 4,394 all
conditional branch whose operands fix its outcome 1,460 19 23 1,502 4,028 all
mask loaded for a zero extension 589 0 808 1,397 4,280 all
bit-cast routed through a frame slot 1,149 0 10 1,159 0 all
zero loaded for a store 8 0 944 952 2,192 all
move or zeroing spelled other than mv or li 799 23 12 834 1,652 all
li + mul foldable to shNadd 0 0 416 416 1,046 all
constant loaded for a branch against zero 79 0 202 281 1,050 all
floating-point constant built through an integer register 0 0 205 205 1,672 all
and/or/xor constant whose complement builds shorter 74 7 58 139 132 all
floating-point constant fli would have built 0 0 120 120 480 all
release followed by a reservation 12 0 0 12 42 all
pushes one stack adjustment would do 0 0 12 12 28 all
zero loaded for an equality branch 9 0 0 9 24 all
slli + srli foldable to andi 0 1 0 1 4 all
total 521,646 196,633 3,147,682 3,865,961 8,782,236

Do not read the total row as a result. One row is 78% of it, and that row is Go's assembler declining to select RVC at all, which is a different kind of finding from the forty-five around it. The second row is 8% and belongs to the linker. The assumed in the call-pair row is the one byte figure that is arithmetic rather than measurement: that check prints no size, and every site is eight bytes in and four out except a handful of jalr ra,0(ra) that were already two.

  • call pair foldable to jal -- auipc rd,X + jalr rd,Y(rd) builds a call with +/-2GB of reach out of eight bytes and a register dependency. Where the target is inside jal's +/-1MB, one four-byte jal rd,target does the same job. The check reports only the shape whose jalr writes back the register the auipc wrote, which folds exactly; the tail-call spelling jalr x0,Y(rd) would stop writing that register and needs a liveness proof this check does not have.

    Population: 292,301 sites -- 171,665 Rust, 120,580 C++, 56 Go. It is a linker-relaxation finding rather than a compiler one.

    The C++ figure used to be 0, and the explanation given for it was wrong. libLLVM really does contribute 0 of its 679,812 call pairs, but not because its text segment is too large: every one of those pairs is auipc ra,0x31ad + jalr, which lands in the PLT about 52 MB away, so the distance is to the PLT rather than to any code. libxul's .text is 105 MB -- twice libLLVM's -- and 120,578 of its call pairs still reach, because they are local intra-module calls that were never relaxed. Two binaries agreeing on zero was a property of those two binaries.

    7 of libxul's sites are auipc ra,0 + jalr ra,0(ra), a call to its own address, which is what a call to an undefined weak symbol degenerates into. Folding one changes nothing, and at 7 sites it is not worth a rule.

  • jump pair foldable to j -- the call pair's shape with x0 for the link register. auipc t6,X + jr Y(t6) spends eight bytes and a scratch register on a jump that j makes in four when the target is inside +/-1MB.

     12ea41c: auipc t6, 0x3
     12ea420: jr -1700(t6)             -> j 0x12ecd78
    

    The call pair folds exactly because jal writes the link register the jalr wrote. j writes nothing, so after the fold t6 holds whatever it held before the pair rather than the auipc's result, and the pair is reported only where the liveness walk finds t6 written before it is read. The walk starts at the target: a jump has no fall-through to ask about. The jr must not be a branch target and neither half may be relocated, as for the call.

    This is V8's shape. MacroAssembler::BranchLong spells every jump to a label not yet bound this way, and the JetStream corpus in TODO.md (entry 36) has 1,116,777 of them, every one inside j's reach. The check reports 720,121: 426,516 in Maglev, 135,370 in TurboFan, 115,518 in baseline, 40,284 in regexp code and 2,433 in wrappers, 2.88 MB of its 151.6 MB. The rest lose to the walk, which answers UNKNOWN rather than DEAD where an indirect jump or a call comes before any write to the register. The package corpus has 2,031, and 1,973 of them are Rust's: tail callee is spelled auipc t1 + jr and left that way by the linker where j would reach, the same unrelaxed pairs the call pair reports; Go's 12 are the linker's -tramp0 trampolines. 683,166 of the pairs sit under a conditional branch that skips exactly them, which once the pair is a j is the shape the branch-over-jump entry below reads, so the two compose.

  • call through a scratch register foldable to jal -- the call pair with a register other than the link carrying the address. auipc t4,X + jalr ra,Y(t4) is how SpiderMonkey's Wasm code calls, and where the target is inside +/-1MB one jal ra,target does the same job:

     auipc t4, 0
     jalr ra, 16(t4)                    -> jal ra, 0x1010 (8 -> 4 bytes)
    

    The call pair declines this on purpose and the jump pair would take it if it were a jump; this check is the one with the other's walk. jal ra writes the same link the jalr wrote, so the fold changes one thing: t4 is no longer written. That is sound only where t4 is dead at both places control goes next -- the callee, which may read it as an argument, and the return address, whose code may expect the auipc's value -- and the liveness walk is asked at both. The jalr must not be a branch target, and neither half may be relocated.

    The SpiderMonkey corpus (TODO.md, entry 51) has 203,833 such calls by the miner's count, every one Wasm; 124,953 are outside jal's reach, since a module's code is one segment, and the miner finds t4 dead at both destinations for 44,115 of the rest. The check has not yet been run over it. Over the package corpus it reports nothing: GCC and LLVM call through the link register, auipc ra + jalr ra or jal once the linker has relaxed it, and Go calls with jal or indirectly through a register loaded from a table. The one pair in the corpus that uses another register, ripgrep's auipc t0 + jalr t0,lo(t0), writes its link into that register and is the call pair's. The shape is a JIT's that keeps a scratch register for every far transfer.

  • call through t0 that pops the return-address stack -- jalr ra,lo(t0), or c.jalr t0, the same instruction in two bytes. The return-address stack takes its hints from the registers a jalr names (the unprivileged spec, section 2.5.1, "Unconditional Jumps"): ra and t0 are the link registers, and a jalr naming two different ones pops and then pushes. A call through t0 therefore throws away its caller's return prediction, and every return above it mispredicts until calls refill the stack. This is Go 1.26 calling a closure:

       1a308: ld t0, 0(s10)
       1a30c: ld a1, 8(a0)
       1a310: mv a0, a2
       1a314: jalr t0          -> keep the target written at 0x1a308 out of t0 (4 -> 4 bytes)
    

    Any other register, ra included, only pushes, so the fix is the emitter choosing another one, at the same size. On the K3's X100 a call through t0 cost 11 to 13 cycles for every return after it, and a call through t1, t2 or a5 nothing (TODO.md, entry 55). Pop-then-push is what a coroutine wants -- it returns to t0 and leaves its own continuation in ra -- and t0 holds a return address only after a link or a copy of ra. So the straight line before the call is walked back to t0's writer, at most 16 instructions, and the call is reported only when that writer is an ordinary instruction, a load or an add. A link, a call, a copy of ra, a side entry or a walk that runs out first reports nothing.

    The package corpus has 48,208. 48,207 are Go's closure and interface calls, which Go 1.27 moved off X5 (golang/go#76654), and the other is Firefox's hand-written XPCOM invoke stub, xptcinvoke_asm_riscv64.S, which loads the method into t0. The SpiderMonkey dump has 105,240, 67,594 in Wasm code and 37,646 in Ion's; V8, which calls through t6, has none.

    Others have fixed it. LLVM has kept indirect calls off t0 since 2021 (D105875): GPRJALR, the register class they are allocated from, is GPR without x0-x5. HotSpot used t0 as its main scratch register, and JDK 24 moved its calls and jumps off it (JDK-8340241), up to 16% faster on Renaissance on a VisionFive 2. SpiderMonkey moves its calls to t3 in bug 2091213 (D341209): the check reports none in a JetStream 3 dump of that build, which scores 3.77% higher on the K3.

  • slli + add foldable to shNadd -- slli rd,rs,{1,2,3} + add rd,rd,rs2 computes a scaled-index address in two dependent instructions; Zba's sh1add/sh2add/sh3add does it in one. Reported only when the add writes back the register the slli wrote and reads it exactly once, which makes the shifted value dead by construction.

    Population: 13,418 sites, 13,180 of them in Go binaries -- GCC and LLVM already use the extension. Of the 232 that are not, 163 are uutils and 67 libLLVM. Both halves have compressed spellings, and 41% of the sites are c.slli + c.add, which is four bytes either way: there the rewrite buys an instruction and a dependency rather than space. Across the corpus it is 13,412 instructions and about 23 KB.

    The check reads Tag_RISCV_arch so it never suggests an instruction the target lacks. That gate is three-valued: Go emits no attributes section at all, and Go holds almost the whole population, so a check suppresses itself only on positive evidence of absence -- an arch string that is present and does not name the extension. When the set had to be assumed rather than read, the run says so.

  • li + mul foldable to shNadd -- li rc,{3,5,9} + mul rd,rx,rc multiplies by a small constant in two instructions, one of which exists only to hold the constant. Zba's sh1add/sh2add/sh3add does it in one with both operands naming the multiplicand: sh1add rd,rx,rx is rx + (rx << 1), and sh2add and sh3add give five and nine the same way. Reported only when the constant is dead after the multiply, which it usually is because the multiply overwrites it.

    Population: 416 sites, every one of them Go, worth 1,046 bytes -- 309 at six bytes down to four and 107 at eight. By factor it is 385 threes, 19 fives and 12 nines.

    The six-or-eight split is not a mixture within a binary but a split between builds. All 107 wide ones are gh's 49 and restic's 58, where every site has a four-byte li; the ten golang-1.26-go tools have none, and every site in them is a c.li. Those 107 are also check_c_compressible's findings -- all of them, since a li of 3, 5 or 9 always fits c.li -- which is two checks saying the same two instructions are too long for different reasons. Both stand, and the Zba one subsumes the other by removing the instruction rather than shrinking it.

    The C++ and Rust zeros are not the gate suppressing anything. Forced open with -m zba, the nineteen GCC- and LLVM-built objects hold 343,378 li of a 3, 5 or 9 and exactly two are followed by a multiply that reads the constant once -- both in libxul, both branch targets, so neither folds. Those toolchains do load 3, 5 and 9 by the hundred thousand, and almost never to multiply by one: of the 82,825 pairs corpus-wide where such a constant feeds the instruction after it, 69% feed a conditional branch and 21% a store, against 1% -- 1,099 -- that feed a multiply. GCC and LLVM reduce a multiply by a small constant in the compiler whether or not the target has Zba, so the population belongs to one toolchain rather than to the extension, which is also true of the two shift-add families above.

    Only mul is matched. mulw sign-extends its 32-bit product where shNadd does not, so folding one needs a following sext.w and trades two instructions for two; the corpus holds 387 of that shape. Powers of two are absent for the opposite reason: four dependent pairs load one in 108 million instructions, because a multiply by a power of two is a shift every compiler already emits. Every other factor needs two shifts and an add, which is no better than the two instructions already there.

    The liveness proof is what this check costs. 712 pairs have the shape and 416 survive: in 296 the constant is read again after the multiply, so the li cannot go away. Nothing else rejects a reported site -- no Go site is lost to a relocation, to an sp/gp/tp destination, or to a multiply that does not read the constant exactly once, and the only branch-target rejections anywhere in the corpus are libxul's two.

  • compare-exchange loop foldable to amocas -- the one check here whose window is a loop rather than a straight line, and the one whose replacement is two instructions rather than one. Both follow from amocas tying its destination to its expected-value operand.

    L: lr.d.aq  rt, (ra)
       bne      rt, rexp, fail      <- the comparison, and the whole body
       sc.d.rl  rs, rnew, (ra)
       bnez     rs, L               <- retry on a failed store
    

    becomes mv rt,rexp and then amocas.d.aqrl rt, rnew, (ra), with the comparison left exactly where it is: amocas writes the loaded value to rt just as the loop did, so the bne after it still decides the same thing on both paths. Four instructions and a backward branch become two. The ordering bits are the union of the pair's, which is at least as strong as what it replaces and never weaker.

    Population: 321 sites under -m zacas -- 194 C++, 93 Go, 34 Rust -- worth 1,470 bytes: 106 at (12 -> 8), 122 at (14 -> 10) and 93 at (16 -> 10). 175 are in libxul, 12 in fd, 11 in libQt6Core, 10 in go compile, and 9 in ripgrep, in uutils and in most of the other Go tools. 208 need a mv to place the expected value and 113 a li, the comparison there having been against zero.

    A word-sized loop compared against a register is not reported, which costs 148 sites. On RV64 amocas.w compares the word with the low 32 bits of rt, where the loop's bne compares all 64 bits of the word lr.w sign-extended with the expected value; the two agree only when the expected value is itself sign-extended, which x0 is and which nothing here proves of another register.

    The corpus holds 14,655 LR/SC loops and 14,499 of them are compare-exchanges, so 321 is 2% of the shape. Most of the rest go to one precondition that cannot be relaxed: the store-conditional's result register disappears with the fold, nothing writes it afterwards, and deadness here can only be proved by a redefinition before any read -- which a loop followed by a call or a return does not give. Offering the fold with an added li rs,0 would recover most of them, and TODO.md records that as an option rather than taking it.

    Two things the corpus does not contain, which is the more useful half of the measurement: a plain read-modify-write loop that today's amoadd/amoand/amoor would fold, and a sub-word one that Zabha would. Zero of 14,655, either kind. Whenever an AMO exists, all three toolchains emit it.

    Gated on positive presence like the Zilx and Zibi checks. Zacas is ratified rather than experimental, but it is in no profile and no object declares it, so every figure here is a -m zacas figure.

  • constant loaded for one equality branch -- li rc,K + beq/bne rx,rc,L, which Zibi's beqi/bnei rx,K,L does in one instruction. RV64I has no compare-immediate-and-branch, so every comparison against a constant must materialize it into a register first; this is the shape that forces, and the reason the extension is proposed.

    imm5_zibi is 1 through 31, or -1. Zero is absent deliberately -- beq rs,x0 already compares against it, so the encoding spends what would have been zero on -1 instead. Equality only: Zibi's condition predicate is isIntEqualitySetCC, so it has beqi and bnei and no ordered form.

    Population: 177,581 sites under -m zibi -- 166,378 C++, 5,766 Rust, 5,437 Go -- worth 358,328 bytes. 47,115 are in libxul, 39,641 in debian-libllvm22, 38,997 in ubuntu-libllvm22 and 36,710 in libllvm20. Unlike the two shift-add families, which are Go's almost entirely, this one is 94% C++, and the four largest contributors are three LLVM builds and libxul. What those comparisons are in the source the check cannot see; that they are concentrated in the largest C++ objects is as far as the evidence goes. It would be fourth in the table above if it appeared there, behind base-C compression, the call pair and the stack-pointer restore.

    175,998 of the sites are c.li + beq, six bytes down to four, and 1,583 are a wide li, eight down to four -- so 99% of them save exactly the two bytes the compressed li took. The branch keeps its own displacement and so its reach, and the branch being replaced was never compressed in the first place: c.beqz and c.bnez compare against x0 and these compare two registers.

    The cost is one liveness proof made twice. The constant has to be dead on both successors, and a linear scan sees the fall-through and not the taken path: of 461,300 shapes with an in-range immediate, 280,487 leave it live on one side or the other and 3,232 more have something branching into the comparison. That is 61% of the raw shape gone, and the same proof check_cond_to_branch makes for the same reason.

    Gated on positive presence, as the three indexed loads are and for a sharper version of the same reason: Zibi is in no profile and LLVM carries it as an experimental extension at version 0.1, where Zilx at least has a ratification plan. Capstone cannot decode it either, so like the Zilx entries this check suggests an instruction the disassembler alongside it could not read back. Every figure here is an -m zibi figure.

    Unlike the indexed loads, though, the instruction itself does run on real hardware today: CORE-V ships cv.beqimm and cv.bneimm as a vendor extension, and capstone decodes those. Their immediate range has not been checked against Zibi's, so the figures above are Zibi's alone.

  • constant loaded for a branch against zero -- the ordered half of the shape above, and the half that needs no extension. li rc,{0,1} + blt/bge/bltu/bgeu against it, where the comparison is already a zero test: rx <u 1 is rx == 0, so that pair is beqz rx; rx < 1 is rx <= 0, which is bge x0,rx; and against 0 the signed forms are a plain substitution of x0 for the loaded register.

    Ten of the sixteen combinations of comparison, constant and operand position have such a form. Two are settled rather than folded -- bltu rx,0 is never taken, bgeu rx,0 always is -- and four are K,rx with K of 1, where 1 <u rx and 1 >=u rx are two-value tests with no zero form. Every row was brute-forced over both signed extremes rather than derived twice.

    Population: 281 sites -- 202 Go, 79 C++, 0 Rust -- worth 1,050 bytes. 109 are in gh, 93 in restic, 28 in ubuntu-libllvm22, 26 in libllvm20, 15 in debian-libllvm22, 9 in libxul. 260 become beqz and 17 bnez, the unsigned forms where comparison against 0 or 1 collapses to equality, against 2 blez and 2 bgtz.

    42 of the 281 save more than the li: beqz and bnez compress when the register is one of x8-x15 and the displacement fits CB format, so those give back the branch's two bytes as well. The 34 at (8 -> 2) save six bytes each, the largest single-site saving of any check here. libxul shows both halves of the rule at once -- beqz s1 compresses and beqz s3 does not, s3 being x19.

    This is not the 273,747 the entry above leaves behind, and nothing is. No extension in LLVM's RISC-V backend gives riscv64 an ordered compare-immediate-branch: Zibi is equality-only by design, and the two with a full ordered set -- Qualcomm's Xqcibi, qc.blti through qc.bgeui, and CORE-V's XCVbi -- are both IsRV32. So the ordered half has no one-instruction form on a 64-bit target at all, and what remains foldable is only the slice where the constant is 0 or 1 and no immediate is needed.

    Of 41,929 shapes where a loaded 0 or 1 feeds an ordered branch, 39,596 have no zero form, and 39,523 of those are one thing: K of 1 with the constant as rs1. 1 >=u rx asks whether a value is at most one and 1 <u rx whether it is more than one; neither is a zero test, and the best either gets is a shift plus a zero test, two instructions for two. Which operand holds the constant decides whether a fold exists, because ordered comparison does not commute -- the same blindness that cost the divide check its apparent population, here worth a factor of eighteen.

  • zero loaded for an equality branch -- the equality half of the entry above, at zero: li rc,0 + beq/bne against it is beqz or bnez on the other register. Zibi leaves zero out of beqi's range because x0 already compares against it, so the Zibi check never sees the pair, and the entry above takes only the ordered comparisons.

     2879870: li a7, 0
     2879874: bne a6, a7, 0x287987c   -> bnez a6, 0x287987c (8 -> 4 bytes)
    

    The conditions and the pricing are the entry above's, the zero dead on both successors included. The JetStream corpus (TODO.md, entry 43) has 1,658, every one in TurboFan, worth 8,154 bytes -- 6.8% of its 24,383 adjacent pairs. The rest are declined by those conditions, the liveness proof above all: in a sample part a fifth of the declined pairs reached V8's auipc+jr far jump on the fall-through before anything touched the register, where the walk gave up. It now follows the pair to its target, and over the JetStream dump taken again for entry 54 the check goes from 1,649 to 2,436, still all TurboFan. The walks that follow one stop most often at a deoptimization exit, a call the walk cannot see past.

  • unsigned divide or remainder by a power of two -- li rc,2^k + divu rd,rx,rc is a shift: srli rd,rx,k. divuw divides the low words and sign-extends its 32-bit quotient, which is what srliw does, and remu/remuw by 2^k is the low k bits, which is andi rd,rx,2^k-1. All three replacements are RV64I, so there is no extension gate and the finding stands whatever an object's arch string says. It is also the only check here whose population is zero with no gate to blame: the four others that report nothing under the corpus's own declarations all report plenty under -m, and this one has nothing to force on.

    Unsigned only. div rd,rx,2^k rounds toward zero where srai rounds toward minus infinity, and they disagree for every negative dividend that is not a multiple of the divisor, so folding a signed divide means adding the bias back and is three instructions rather than one. Two further bounds come from the replacement and not the shape: andi's immediate is twelve bits signed, so a remainder folds only up to a mask of 2047, and srliw's shift amount is five bits.

    Population: 0. The corpus holds 1,593,373 li or lui whose immediate alone is a power of two -- a ceiling, since a lui can be the high half of a larger constant -- and 618 of those are immediately followed by an unsigned divide or remainder that depends on the register. 603 of those 618 have the constant as the dividend -- li a0,1024 + divu a0,a0,a4 is 1024 over a variable, which no shift replaces -- leaving 15 real shapes, and all 15 fail a precondition: 13 are branch targets and 2 leave the divisor live.

    The branch-target rejections are correctness, not caution. One of the 13, in golang-1.26-go--go, is

    0x3fa172:  j 0x3fa178          <- jumps over the li
    0x3fa176:  c.li t1, 8
    0x3fa178:  remu t1, a1, t1
    

    where a path reaches the remu without executing the li, so andi t1,a1,7 would compute something else on that path: two instructions adjacent across a control-flow merge rather than a missed peephole. That one was decoded by hand; the other twelve were not. Read with the 603, the conclusion is that all three toolchains in this corpus reduce an unsigned divide by a power of two in the compiler, and what the shape scan saw afterwards is noise.

    The check is kept because it costs nothing to run and the rewrite needs no extension, so anything built by a compiler that does not do this -- or hand-written assembly, or a JIT -- would be reported. On this corpus it is a measured zero rather than an unmeasured guess.

  • not + and/or/xor foldable to andn/orn/xnor -- a complement folded into the logical operation that consumes it. andn rd,rs1,rs2 is rs1 & ~rs2, orn the same with or, and xnor is ~(rs1 ^ rs2), so four shapes collapse:

    not rt,rb     and rd,ra,rt   ->  andn rd,ra,rb
    not rt,rb     or  rd,ra,rt   ->  orn  rd,ra,rb
    not rt,rb     xor rd,ra,rt   ->  xnor rd,ra,rb
    xor rt,ra,rb  not rd,rt      ->  xnor rd,ra,rb
    

    The last two are one instruction because ~a ^ b and ~(a ^ b) are the same value -- which is also why xor is the only one of the three whose two orders both fold.

    Population: 2,521 sites -- 2,518 Go, 2 C++, 1 Rust -- worth 9,152 bytes: 2,057 at (8 -> 4), 462 at (6 -> 4) and 2 at (4 -> 4), where both halves were already compressed and the rewrite buys an instruction rather than space. Of the Go sites, 2,151 are andn, 319 xnor and 48 orn; 345 are in gh, 337 in restic, 333 in go, 273 in compile, 201 in link, 191 in asm.

    It survives its preconditions better than anything else here -- 2,518 of the Go objects' 3,093 shapes, 81% -- and the only losses are to the liveness proof on the complement. Nothing at all is lost to a branch target or a relocation.

    The orders that don't fold are what the direction test is for: or then not is NOR and and then not is NAND, and Zbb has neither. Those are 5,477 dependent pairs against 12,474 that fold.

    not is xori rd,rs,-1, which is why this shape appears in no probe that looks for a li. The Zbb division is the usual one but not absolute: ripgrep and libQt6Core declare Zbb and have no shapes at all, their compilers emitting andn directly, and libgkcodecs declares none and has 63 that only -m zbb reveals -- but three sites do survive in the Zbb-declaring C++ and Rust objects, which is three more than the zext.h and sext entries manage. In the xor-then-not order the not is also check_zcb_compressible's finding -- c.not, two bytes rather than four -- and both stand: Zcb shrinks the instruction and Zbb removes it.

  • slli + srai foldable to sext.b or sext.h -- the arithmetic twin of the two entries below. slli rd,rs,48 + srai rd,rd,48 sign-extends the low halfword and the same pair at 56 the low byte, where Zbb's sext.h and sext.b do either in one instruction. One funct6 bit in the second instruction separates this from the zext pair: whether the sign or a zero is shifted back in.

    Both amounts are Zbb, so this is one check rather than the two the zext family needs, where 32 belongs to Zba and 48 to Zbb.

    Population: 2,562 sites, every one of them Go -- 1,305 sext.h and 1,257 sext.b -- worth 6,450 bytes: 783 at (8 -> 4), 1,659 at (6 -> 4) and 120 at (4 -> 4) where both halves were already compressed. 1,783 are in compile, 323 in asm, 167 in restic, 100 in gh. The same division as the zext.h entry: objects declaring Zbb have none, their compilers emitting the instruction directly, and libgkcodecs's 309 sext.h and 165 sext.b shapes appear only under -m zbb.

    The two shift amounts have to agree with each other, which is the rejection that matters: slli 48 + srai 55 is a signed field extract, and the corpus holds 6,738 of those against 3,660 real sext.h pairs -- nearly twice as many near misses as hits. 32 is absent on purpose, being base-ISA sext.w and one dependent pair corpus-wide.

    rv_decode_extension already decoded the one-instruction forms, so that the redundant-extension check could treat them as guarantees; what was missing was the two-instruction producer of the same value.

  • slli + srli foldable to zext.h -- the same shape as the entry below at 48 instead of 32: slli rd,rs,48 + srli rd,rd,48 clears all but the low halfword, where Zbb's zext.h does it in one. (rs << 48) >> 48 logical is rs & 0xffff, which is what the instruction computes; LLVM has it as ZEXT_H_RV64 under [HasStdExtZbbOrZbkb, IsRV64].

    Population: 9,522 sites, every one of them Go, worth 29,634 bytes -- 5,907 at (8 -> 4), 3,003 at (6 -> 4) and 612 at (4 -> 4) where both halves were already compressed and the rewrite buys an instruction rather than space. 3,746 are in compile, 3,262 in asm, 863 in link, 560 in gh, 362 in restic.

    The division is the same as every other Zb check here. The three LLVM builds and libQt6Core declare Zbb and have no sites at all -- their compilers already emit zext.h -- while the firefox objects and debian-libllvm22 declare no Zbb, so their shapes are suppressed by their own arch string and appear only under -m zbb: 143 of libgkcodecs's 151 and 57 of libmozsqlite3's 63.

    Unlike the 32-bit sibling, an srli writing a register other than the one the slli wrote is accepted on a liveness proof. The sibling can say every site in its corpus overwrites; that is true of all 9,522 here and false of 43 of libgkcodecs's 151, so the arm earns its one query. Zcb's two-byte c.zext.h would make some of these save six bytes rather than four, which the figure does not assume.

  • slli + srli foldable to zext.w -- slli rd,rs,32 + srli rd,rd,32 clears the upper word in two dependent instructions where Zba's zext.w does it in one. Reported only when the srli both reads and overwrites the register the slli wrote, which makes the intermediate dead by construction -- and unlike the shift-add family every site in the corpus is written that way, so the precondition costs nothing.

    Population: 18,125 sites, 18,071 of them in Go, worth about 49 KB and 18,125 instructions. Only 8% are c.slli + c.srli -- far fewer than the shift-add family's 41%, because c.srli is CB-format and can name only x8-x15. sext.w is the same shape with srai and a different rewrite, which the check rejects rather than folds.

  • slli + srli foldable to andi -- the same shape at 53 or more: slli rd,rs,k + srli rd,rd,k keeps the low 64-k bits, eleven or fewer, and andi rd,rs,2^(64-k)-1 keeps them in one base-ISA instruction.

     28417fc: slli s4, s4, 0x3d
     2841800: srli s4, s4, 0x3d        -> andi s4, s4, 7 (8 -> 4 bytes)
    

    An srli writing another register is accepted on a liveness proof, as in the zext.h entry, and the andi is priced as c.andi where both shifts were compressed and the mask fits six bits. The package corpus has 2, its compilers emitting the andi, and TODO.md rejected the shape on that. The JetStream corpus (TODO.md, entry 45) has 17,097, worth 68,388 bytes: 12,011 in baseline and 5,086 in Maglev. V8's DecodeField is ExtractBits, the shift pair wherever the field sits, and 14,135 of the sites keep three bits -- OsrUrgencyBits, decoded at every baseline loop back-edge and in Maglev's OSR code.

  • redundant stack-pointer restore -- addi s0,sp,K in the prologue and addi sp,s0,-K at the exit. When nothing has written sp in between, the frame did not move, so the restore assigns sp the value it already holds and deleting it is free. No liveness query is involved: the instruction's whole effect is already in force, which is what separates it from a dead definition.

    Population: 216,226 sites -- 103,825 of them in ubuntu-libllvm22 and 100,716 in libllvm20, both clang-built, 11,683 Rust, 2 in libgkcodecs.so, and 0 in both libQt6Core and libxul, which is the finding.

    It takes two things to occur, and each zero shows one of them missing. GCC emits an sp-relative epilogue, so Qt6Core has none even though Ubuntu builds it with frame pointers. Debian does not default to -fno-omit-frame-pointer, so libxul has no frame pointers to restore from -- 52 sites in 35.6M instructions, all of them frames that really moved. What produces the finding is Ubuntu's frame-pointer policy and an LLVM-family compiler together; it is not a property of clang alone. Go has none of this shape at all. Every site is a four-byte encoding -- c.addi16sp can only spell sp,sp -- so it is 112,401 instructions and 439 KB, the one check here whose byte count is simply four times its finding count.

    This is the only check that cannot be decided from the instruction under the cursor and what follows it: the prologue that makes the restore redundant sits past every call and branch in the function, and the variable-length encoding makes searching backward unreliable. So it carries the prologue forward in the section state instead. A restore something branches to is skipped, because it can be entered from code the linear scan has not walked and that code may have moved sp -- 17% of the measured population, given up to keep the rest provable.

    It reads as advice to delete one instruction, not to drop the frame pointer. Ubuntu builds with -fno-omit-frame-pointer deliberately, and the frame pointer stays.

  • pushes one stack adjustment would do -- values pushed one at a time, addi sp,sp,-8 + sd r,0(sp) again and again, where one adjustment by the total and the same stores at new offsets leave memory and sp exactly as the run did. V8's Maglev prologue pushes the context, the function, the argument count and then a zero for every tagged stack slot that way:

     2851e80: addi sp, sp, -8
     2851e84: sd s7, 0(sp)
     2851e88: addi sp, sp, -8
     2851e8c: sd a1, 0(sp)
     ...                               -> one addi sp, sp, -88 for 11
     2851ed4: sd zero, 0(sp)              adjustments (88 -> 48 bytes)
    

    The run takes every sp decrement and sp-relative access from the first decrement on, and anything between them that neither reads nor writes sp -- baseline code loads each value through s0 just before pushing it, and those loads stay where they are. It ends at a side entry, a transfer, a release, an access that stores or loads sp itself, or a total one addi cannot subtract, and each access's new offset has to fit its immediate. Memory sees the same stores in the same order; only sp's intermediate values are gone, and nothing in the run could read them.

    The JetStream corpus (TODO.md, entry 40) has 259,684 runs, worth 2,093,116 bytes or 1.4% of its code: 129,227 in baseline, 127,370 in Maglev, 3,020 in regexp code. 148,192 are two adjustments and 19,383 are six or more. Compilers allocate a frame once; the package corpus has 12, one per Go binary, in the runtime's rt0_go entry, which pushes ra and then reserves the rest of its frame.

  • releases one stack adjustment would do -- the push run read backwards: values popped one at a time, ld r,0(sp) + addi sp,sp,8 again and again, where one adjustment by the total where the last release stood, and the same loads at new offsets, leave memory and sp exactly as the run did. SpiderMonkey's Wasm epilogue frees the frame and then the saved pair's slots separately, and its Ion code pops s0 and ra one at a time:

     addi sp, sp, 16
     ld ra, 8(sp)
     ld s0, 0(sp)                       -> one addi sp, sp, 32 for 2
     addi sp, sp, 16                       adjustments (16 -> 12 bytes)
    

    The run takes every release and every sp-relative access from the first release to the last, with anything between them that neither reads nor writes sp, and ends at a side entry, a transfer, a reservation, an access that stores or loads sp itself, or a total one addi cannot add. An access before the last release is re-offset by what had been released ahead of it -- with the releases deferred, sp is lower there by exactly that much -- and the new offset has to fit its immediate. Delaying a release is the safe direction: the memory stays reserved longer and nothing reads below sp, where the push run has to show that bringing a reservation forward changes nothing.

    The SpiderMonkey corpus (TODO.md, entry 48) has 307,725 runs by the miner's count, 1,396,600 bytes, and the check has not yet been run over it. Over the package corpus it reports nothing: GCC, LLVM and Go's assembler each free a frame with one adjustment, and the only releases that follow one another are a frame too large for one addi, freed in two steps -- addi sp,sp,0x7f0 then addi sp,sp,0x680 in libmozsqlite3 -- which the check declines because the total is what one addi cannot add.

  • release followed by a reservation -- addi sp,sp,+a directly followed by addi sp,sp,-b, which is one addi sp,sp,a-b, or nothing at all when the two cancel: nothing between them could see sp's intermediate value. SpiderMonkey's Baseline tier pops one value and pushes the next this way:

     ld a2, 0(sp)
     addi sp, sp, 8                     -> delete both; the adjustments
     addi sp, sp, -8                       cancel (8 bytes)
     sd s1, 0(sp)
    

    The reservation must not be a side entry, which would arrive with sp unreleased. The pair is the seam between the two runs above -- the push run begins only at a reservation and the release run ends at one, so neither takes the pair -- and each run may hold one of its halves. No adjustment is counted twice: a release that ends a run the release-run check reported is left to it, and a reservation that begins a run the push-run check would report is left to that, which the check asks of the push run itself before it reports.

    The SpiderMonkey corpus (TODO.md, entry 49) has 176,685 pairs by the miner's count, 110,244 of them cancelling, 1,147,716 bytes, and the check has not yet been run over it. Over the package corpus it reports 12 pairs, 42 bytes, six in each of the two LLVM 20 and 22 builds and none anywhere else: GCC freeing the stack-argument area of one call and reserving the next call's directly after, addi sp,sp,16 + addi sp,sp,-16 after a jal, nine of them cancelling. Compilers otherwise place sp once per frame, and the JIT shape -- an interpreter's push and pop spelled out -- does not occur.

  • comparison a branch could have made -- slt/sltu/xor/sub writing a condition into a register, then beqz/bnez testing it, where one blt/bgeu/beq/bne would have done both. The flagless analogue of armlint's cmp #0 check: RISC-V has no condition codes, so the comparison is a value and the test is a branch on it.

    seqz and snez fold too, though they are immediate forms -- seqz is sltiu rd,rs,1 and snez is sltu rd,x0,rs, and both compare against zero, which beqz and bnez already do. Everything else with an immediate is out: RISC-V has no compare-immediate-and-branch.

    The fold only removes an instruction if the condition register is dead on both successors, which is why this needs the walk rather than a scan -- the taken path is elsewhere in the section, and about half of the raw population is a difference the code goes on to use. sub rd,a,b; beqz rd is usually a subtraction whose result is wanted, not a comparison.

  • conditional branch over an unconditional jump -- beqz a0,L + j X + L: is bnez a0,X with the jump gone. Every conditional branch inverts: beq/bne, blt/bge and bltu/bgeu are each other with the low bit of funct3 flipped.

     e8254: bne s1, s5, 0xe825c
     e8258: j 0xe91a4               -> beq s1, s5, 0xe91a4
    

    The shape is 128,361 sites in the corpus and almost all of it is the encoding working as designed: the branch reaches +/-4KB and the jump reaches +/-1MB, so an assembler that cannot encode the branch writes this pair instead. 122,999 have a target the branch could not have reached; the 5,362 that do are the findings.

    Two preconditions. The jump must not itself be a branch target, or the paths that reach it lose their transfer -- a bit lookup in the table the driver already builds. And it must be j rather than jal: the second writes a link register that would stop being written.

    The inverted branch is priced at the original's own encoding class. A four-byte branch stays four even where the new displacement would fit c.beqz, because Go leaves compressible branches wide and that saving is the compression check's rather than this one's. Four shapes come out of that: 2,468 sites where both halves are four bytes and the fold saves four, 2,632 where one half is two and it saves two, 189 where both are two and the pair becomes one c.bnez, and 73 where both are two and the new target is outside c.bnez's +/-256, so four bytes become four. Those last are still reported: an instruction and a taken branch go, and the finding says the size did not change.

  • branch over a move foldable to max or min -- an ordered branch over a move into one of the two registers it compared, from the other: rd is kept when it is the greater and replaced otherwise, which is Zbb's max rd,rd,rv, or min when it is kept as the lesser, and maxu and minu for the unsigned comparisons. The move is mv, or li rd,0 with x0 compared, or li rd,K after a li rk,K that the branch compared, which stays:

     2842208: li t2, 1
     284220c: blt t2, a5, 0x2842214
     2842210: li a5, 1    -> li t2, 1; max a5, a5, t2 (12 -> 8 bytes)
    

    No liveness is needed, since rd ends with the same value on both paths, but the move must not be a branch target, nor the branch where a li leads. Gated on Zbb permissively. The JetStream corpus (TODO.md, entry 42) has 28,292, worth 113,168 bytes, all but 55 of them Maglev's: Return clamps the argument count it drops to at least the formal count with a branch against an immediate and a Move, which is this shape with the formal count for K.

  • transfer to the instruction that follows it -- a relative transfer whose target is the next instruction. Control arrives there either way, so it does nothing.

     70c9c: j 0x70c9e
     70c9e: ld a1, -0x50(s0)        -> delete the j
    

    3,674 of the 3,702 are a two-byte c.j, a block-placement leftover in LLVM's output: 2,851 C++ and 831 Rust against 20 in Go. The rest are three four-byte jumps and 25 conditional branches doing the same thing.

    jal rd,next with rd other than x0 is not reported. It writes a link register, which makes it a PC materialization rather than a no-op -- 16 sites, all in Firefox, and the one thing separating this check from a wrong one.

  • conditional branch whose operands fix its outcome -- beq, bge or bgeu of a register with itself, or bgeu r,x0, is always taken, since nothing is below zero unsigned; bne, blt or bltu of a register with itself, or bltu r,x0, never is. The first kind is a jump, which the ISA manual asks to be spelled jal x0 -- j, two bytes within c.j's reach -- and the second does nothing:

     4dfe630: mv s10, s11
     4dfe632: mv a1, s11
     4dfe634: bne s11, s11, 0x4dfe684   -> delete; never taken (4 bytes)
    

    That is Ubuntu's clang-built libLLVM, where the copies before the branch suggest how it arises: a comparison of two registers that a copy made one, and nothing afterwards folded the branch. Both C++ compilers leave them. Of the 1,460 in C++, 1,054 are in clang-built objects -- Ubuntu's libLLVM 540, libllvm20 358, libxul 153, two other Firefox libraries 3 -- and 406 in Debian's GCC-built libLLVM; Rust has 19, Go 23, the SpiderMonkey JetStream dump 9 and V8's none. A branch to the next instruction is the check above's, which deletes it whatever it compares, and c.beqz and c.bnez compare x8-x15 with zero, which no operand fixes.

  • transfer to an unconditional jump -- a conditional branch, j or jal whose target is a j or V8's far jump auipc+jr, and which could go straight to where that jump goes. The chain is followed through up to eight jumps, as far as the transfer reaches:

     2841a5c: beq a0, t3, 0x2841a68
     2841a68: j 0x2841a98            -> beq a0, t3, 0x2841a98 (4 -> 4 bytes)
    

    Nothing is removed: the transfer keeps its encoding, and every path through it executes one taken jump fewer. The jump stays, because deleting it needs every reference to its label, and a table or another code object can hold one. Going around a far jump skips its auipc, so that register must be dead at the new target. A branch over one jump that the branch-over-jump check folds is that check's, and a compressed transfer that would have to widen to reach is not reported. The JetStream corpus (TODO.md, entry 39) has 165,318, 105,721 of them Maglev's, and 28 whose chain leads back to the next instruction, which are reported for deletion. The example is Sparkplug's test for undefined or null: the branch taken on undefined lands on the jump that the branch for null skips.

  • tail every jump to one label repeats -- cross-jumping. A label reached only by unconditional jumps, each preceded by the same k instructions, can hold those instructions once, just before the label, with every jump going there instead: (jumps - 1) x k instructions fewer. Ion's out-of-line bailouts are the shape, each pushing its snapshot's offset and jumping to the script's shared deopt label:

     li t4, 29
     addi sp, sp, -8
     sd t4, 0(sp)                       -> one copy of the 3-instruction
     j deopt                               tail before deopt for 17 jumps
                                           (204 -> 12 bytes)
    

    The jumps are j, c.j, or an auipc + jr veneer, whose tail sits before the auipc. The instruction before the label must not fall through, or the hoisted tail would run on a path that never jumped, and a branch or a call to the label disqualifies it the same way. The tail is compared encoding for encoding across every site and may hold no control transfer and nothing pc-relative, which would compute something else at the label; a branch target below its top, or at the jump itself, ends it, since a path entering there would run only part of it. Each jump has to reach the tail's new place -- a c.j within 2 KiB -- and a relocated instruction anywhere drops the site. The finding is made once per label, at the lowest site, spanning that site's tail and jump.

    This is the one check that needs the section's jumps by target and a map of where each instruction starts, so that a walk can go backwards through a variable-length encoding; both are built when the section is read. An indirect jump to the label cannot be seen, which the check shares with every other use of the side-entry map. The SpiderMonkey corpus (TODO.md, entry 52) has 9,988 such labels by the miner's count, 787,776 bytes, 734,712 of them the bailout tail above, and the check has not yet been run over it. General-purpose compilers merge tails themselves (GCC's -fcrossjumping, LLVM's branch folding), and still the package corpus has 1,584 such labels, 35,132 bytes: C++ 1,035, Go 430, Rust 119. What they missed is the epilogue before a sibling call. GCC's addi sp,s0,-16; ld ra,8(sp); ld s0,0(sp); addi sp,sp,16 precedes every j callee or tail callee out of a function, and in LLVM 20 one callee is reached that way from 103 sites, 1,020 bytes for one label; Clang's restores and the moves of the arguments before its tail calls are libxul's shape, eight instructions before 24 jumps. 1,217 of the labels have two jumps, 151 three, and the two LLVM builds hold the largest. Go's are reloads before a join, ld t0,0xa0(sp); j, and Rust's the same epilogue before a tail veneer.

  • instruction with no architectural effect -- the no-ops that are not nop: an operation whose result is the value it read (mv x,x, addi x,x,0, ori x,x,0, a shift by zero, an and with all ones, fsgnj.d f,f,f), or a write to x0 that is neither the canonical nop nor one of the two hint families the ISA has assigned there, Zicbop's prefetches (ori x0,rs,imm) and Zihintntl's non-temporal hints (add x0,x0,x2..x5). The W forms are not in it: addiw x,x,0 sign-extends, and is the extension check's.

     12e77d0: ebreak
     12e77d4: lui zero, 0x54321        -> delete; a write to x0
     12e77d8: mv sp, sp                -> delete; a move onto itself
    

    nop itself stays unreported, for the reason the compression check's entry in TODO.md gives: alignment padding exists for its width. The forms here have no such alibi. A write to x0 is hint space by the ISA's own reckoning, and a JIT may be using one as a marker it reads back through its own disassembler -- V8's stop code after ebreak and its constant-pool guard are both lui/auipc into x0 -- which the finding cannot know and the processor does not act on. Where the instruction is also compressible the compression check reports it too; deleting it is the larger saving and subsumes the smaller.

    The JetStream corpus (TODO.md, entry 38) has 812,586: 425,026 stop codes, one after every Maglev deferred block, 206,424 mv sp,sp from MultiPush/MultiPop handed an empty register list, and 181,136 ori t6,t6,0 ending V8's fixed-length address load when the low six bits of the address are zero. The check reports all 812,586, 3,250,344 bytes or 2.1% of the corpus's code: 763,931 in Maglev, 27,568 in TurboFan, 18,700 in baseline and 2,250 in regexp code.

    One encoding is gated. auipc x0,imm is Zicfilp's lpad, the landing pad an object built for that extension relies on, so it is reported only where the declared architecture positively lacks Zicfilp -- V8's does, and uses the encoding as its constant-pool guard -- and never where the architecture is unknown.

  • move or zeroing spelled other than mv or li -- a copy of one register into another spelled or rd,rs,x0, xor rd,rs,x0, ori rd,rs,0, slli rd,rs,0 and the like rather than mv (addi rd,rs,0), or a zeroing that reads a register -- xor rd,rs,rs, sub rd,rs,rs, andi rd,rs,0 -- rather than li rd,0. RISE's optimization guide asks for the two canonical spellings because they are what a core recognizes, and the K3's X100 shows the difference: it eliminates most addi rd,rs,0 and c.mv at rename and runs every other move as a one-cycle operation, the four-byte add rd,x0,rs included, and a zeroing that reads a register waits for it, where li rd,0 waits for nothing (TODO.md, entry 56). This is an 8- or 16-bit compare-and-exchange in libxul:

     749b882: lr.w a2, (s5)
     749b886: and a3, a2, a0
     749b88a: bne a3, a1, 0x749be7c
     749b88e: xor a3, a2, zero         -> mv a3, a2 (4 -> 2 bytes)
     749b892: and a3, a3, a0
     749b894: xor a3, a3, a2
     749b896: sc.w.rl a3, a3, (s5)
    

    LLVM expands that loop after register allocation, and the merge's first xor keeps the x0 that a zero being stored arrived in; 591 of libxul's 636 are it. The package corpus has 834 in all -- C++ 799, Rust 23, Go 12 -- and the JIT dumps are where the population is. SpiderMonkey's has 37,944: 27,131 or rd,sp,zero, the copy of sp before a call into C++, in every tier, and 10,500 xor rd,rd,rd, 7,544 of them in Wasm code. V8's has 2,732, all but 28 a slli rd,rs,0 in regexp code.

    A zeroing from x0 alone, or rd,x0,x0 or lui rd,0, waits for nothing and is not reported, which also leaves alone the lui rd,0 opening each of SpiderMonkey's fixed-length patchable constants, 295,108 in its dump. A move onto its own source or a write to x0 is the no-op check's, and add rd,x0,rs, c.mv's own expansion, is the compression check's c.mv where C is available. Where C is available the rewrite is also two bytes shorter, but the reason for it is the cycle.

  • redundant reload -- the same (base, displacement, width, signedness) loaded twice with nothing in between that could have changed it. The second load is a mv from wherever the first put the value.

    This one carries a caveat no binary can resolve: a load from a volatile or device address must be repeated, and nothing in the encoding says which loads those are. The window is otherwise strict: a call, fence, atomic or system instruction ends it, as does a write to either the base or the register holding the value, as does any store that does not provably land elsewhere -- which through this base means a disjoint byte range and through any other base means nothing.

  • load of a just-stored value -- the bytes a store just wrote, read straight back. sd a0,8(sp) then ld a1,8(sp) puts in a1 what a0 already holds, so the load is mv a1,a0; where the two are narrower than a doubleword it is the extension the load's own signedness implies, and zext.w and the halfword forms need Zba or Zbb.

    The cheapest of the seven to decide, because nothing is deleted -- the store stays and the load becomes a register operation, so there is no liveness query at all. It reports one rewrite per site: where a redundant reload of the same address is also available, that check has the nearer source and this one stands down.

    The same window serves it, and the disjointness rule matters more here than it does to the reload check: a spill sequence writes several adjacent slots before reading any of them back, so a rule that ended every claim at any store at all would lose two thirds of this family. Floating point is refused on both sides for a different reason -- the window drops a held value when the register holding it is written, and its write scan cannot see the f registers at all.

  • load of a value the register still holds -- the same shape one step further: the load's destination is the register the value is already in, so there is no move to make and the load itself goes. sd ra,8(sp) at the top of a function and ld ra,8(sp) at the bottom with no call between them is the commonest form of it, and a second ld a0,8(a1) after a beqz on the first is the next.

    The two checks above both refuse this shape, because both rewrite a load into a move and there is no move to make. That leaves it here, and it deletes an instruction rather than shortening one -- 41,232 bytes, which was the largest figure the window's checks produced until the computation table was added below.

    Each of its two shapes has to be exact. The same load again recomputes the same value from the same bytes at any width; a store read back into the register it came from is exact only at the full width, since sw a0,K(sp) then lw a0,K(sp) leaves a0 sign-extended from bit 31, which is a0 again only if it already was. It carries the reload check's volatile caveat for the same reason.

  • dead store to a frame slot -- the same slot stored twice with nothing reading it in between. The store analogue of a dead register definition, limited to sp- and fp-relative slots for the mirror of the reload caveat: a heap address may alias anything.

  • store of a value the slot already holds -- the dead store read from the other end. That check deletes the first of two stores and needs the overwrite to be certain; this deletes the second, and does not, because putting back what is already there is a no-op on every path that reaches it. Same frame-only restriction, for the same reason.

    The two read different flags of the same record, and the flags do not have the same lifetime. Two things take unread away and leave held alone: a conditional branch, since "dead" means the overwrite is certain and on the taken path it does not happen, and a load through a base that cannot be shown to miss the slot, which may be the read that keeps the earlier store alive. Neither disturbs the value in the register, so both are this check's and not the dead store's. What is left over -- two stores of the same register with neither a branch nor a load between them -- is 274 sites, and this check stands down on them.

    5,635 of the 6,765 sites are a slot stored and stored again, and 1,130 are a slot loaded and written back unchanged. The two cohorts sit at opposite ends of that: Go is 5,332 of the first and 9 of the second, C++ and Rust together are 303 and 1,121.

    Unlike its neighbours it compares the record's width and not its kind: they claim something about the register a load produced, where lb and lbu are the same bytes and not the same value, and this claims something about the bytes, which do not record how they were read.

  • run of zero stores one wider store would do -- consecutive stores of x0 to abutting frame slots, where fewer naturally aligned stores cover the same bytes. GCC zeroes a frame buffer one byte at a time:

     f65ca: sb zero, -0x6f(s0)
     f65ce: sb zero, -0x6e(s0)
     ...
     f65e2: sb zero, -0x69(s0)      -> sb -111; sh -110; sw -108
    

    Covering [-111,-104) takes three, so 16 of those 28 bytes go. One finding per run rather than per pair: read as adjacent pairs the same code is 50,755 sites and read as runs it is 30,321, and the pair count cannot tell a run of seven worth 16 bytes from three merges worth four each.

    Only a zero value merges. sd rD in place of two sw rD would write rD's high half to the second slot, and nothing says a register's halves are the two values that were stored. Restricted to sp and fp, where the ABI fixes the base alignment and the offset decides the rest; another 23,973 sites run through a base whose alignment the encoding does not give, four times this population, and there a byte-at-a-time store may be the deliberate choice rather than the missed one.

    Both sides of the byte figure are priced at the best encoding the base C extension offers, rather than at the bytes the binary carries. That is what keeps this off the compression check's ground, and it is visible in Go's output:

     52ff4: sw zero, 48(sp)         -> c.swsp, 2 bytes         (compression)
     52ff8: sw zero, 52(sp)         -> c.swsp, 2 bytes         (compression)
                                    -> one c.sdsp, 2 bytes     (this check)
    

    Eight bytes are there and two survive both rewrites. Priced at what the binary carries this check would claim four of the six and the compression check would claim four as well; priced at the base C best it claims two, the compression check claims four, and the two add up. For a run with no missed compression in it -- most of them, since sb zero and sh zero have no compressed spelling at all -- the two figures are the same and the finding matches the disassembly byte for byte.

  • zero loaded for a store -- li rt,0 and then stores of rt, where each could store x0 and the li go:

     12e7ab4: li a0, 0
     12e7ab8: sd a0, -0x80(s0)        -> sd zero, -128(s0) (8 -> 4 bytes)
     12e7abc: li a0, 1
    

    Every integer store of rt that follows before anything else might name it counts, up to sixteen instructions with no side entry or transfer among them, so a zero stored four times is one finding; rt must be dead after the last store. c.sdsp and c.swsp name x0 as freely as any register, but the quadrant-0 compressed stores cannot, and a site whose store would grow back to four bytes is not reported.

    The JetStream corpus (TODO.md, entry 41) has 31,052 sites rewriting 40,979 stores, worth 124,208 bytes: 18,695 in baseline, whose accumulator is a0, so that a bytecode loading zero and one storing it to a register are exactly this pair; 6,584 in regexp code, 4,743 in Maglev and 969 in TurboFan.

  • constant loaded for an immediate operand -- li rc,K and then register-register operations reading rc where their immediate forms would take K: add, addw, and, or and xor with rc on either side, sub, subw, slt, sltu and the shifts with rc second.

     360bcc: li a1, 1
     360bd0: add t2, s2, a1
     360bd4: addw a1, s2, a1
                   -> addi t2, s2, 1; addiw a1, s2, 1 (12 -> 8 bytes)
    

    The walk is the zero store's -- every such use before anything else might name rc, sixteen instructions at most, no side entry or transfer -- and rc must then be dead, or overwritten by the last use. A compressed use is priced at c.addi, c.addiw or c.andi where its immediate form has one and at four bytes where it does not.

    TODO.md rejected the shape at 942 over the package corpus. The JetStream corpus (TODO.md, entry 44) has 1,738, worth 6,952 bytes, against the miner's 20,743, which are almost all Maglev's overflow-checked arithmetic. riscv64's Maglev takes a constant right input in a register where arm64 and x64 take it as an immediate, but the bne that checks for overflow leaves for an eager deopt exit, whose call into the deoptimizer reads whatever registers the frame state names; the liveness walk cannot see a frame state, so only the 98 whose addw overwrites the constant survive. Most of the rest subtract a small constant in code the dump does not name, or load zero for what is a copy.

  • mask loaded for a zero extension -- a mask of the low n bits, which andi cannot hold and so takes two instructions or more to build, and then only anded with: zext.h does the and alone at 16 bits under Zbb, zext.w at 32 under Zba, and at any other width, or without the extension, the shift pair slli 64-n + srli 64-n does.

     2865148: lui t2, 0x10
     286514c: addiw t2, t2, -1
     2865150: and a0, s1, t2           -> zext.h a0, s1 (12 -> 4 bytes)
    

    The uses are found by the entry above's walk, and the mask must be dead after the last. The JetStream corpus (TODO.md, entry 46) has 1,142, worth 9,024 bytes: 1,100 zext.h, 7 zext.w and 35 shift pairs, for masks of 12 to 31 bits. V8's And with an immediate andi cannot hold loads it into a scratch register whatever it is.

  • constant built in more instructions than li needs -- a chain of lui, li or Zbs's bseti from x0, then steps reading and writing the same register -- addi, addiw, andi, ori, xori, the immediate shifts, and the Zba, Zbb, Zbs and Zcb operations a planner ends a sequence with -- longer than what li needs for the value it ends up holding. What li needs is LLVM's RISCVMatInt, ported and counted rather than emitted, under the object's own extensions: the RV64I recurrence with its retries -- the trailing zeros shifted in by a final slli, the leading zeros shifted out by a final srli, the value inverted by a final xori -- then slli.uw, zext.w and shNadd under Zba, bseti and bclri under Zbs, and rori of a negative twelve-bit immediate under Zbb. One step is not LLVM's: rori of anything a single lui or addi builds, which is how the complement of a mask that wraps bit 63 is two instructions.

     12e77b0: lui t6, 0x156
     12e77b4: addi t6, t6, 866
     12e77b8: slli t6, t6, 0xb
     12e77bc: ori t6, t6, 0x3f0
     12e77c0: slli t6, t6, 0x6
     12e77c4: ori t6, t6, 0x0    -> li t6, 0x2ac6c4fc00 in 3 instructions: lui, addiw, slli
    

    Every plan is a construction, so it is achievable, and that is all a finding saying "more than needed" has to know. It is not proved minimal -- LLVM builds some values in fewer with a second register, which a chain on one register cannot use -- so the check stays conservative. The chain ends at the first instruction that is not such a step or that another path joins, and a relocated instruction anywhere in it drops the site, since in an unlinked object the immediates are placeholders. The replacement names the plan's mnemonics and is priced at the chain's own encoding class, as the branch-over-jump entry prices its branch, so that the saving does not include what the compression check already reports.

    Until the planner, the reference was the plain RV64I recurrence -- lui+addiw for a 32-bit value, otherwise the high part, one slli and an addi -- and it missed shorter spellings even without the extensions: the example above is 0xab1b13f << 10, three instructions where the recurrence counted four.

    Compilers emit the planner's sequences themselves, so over the package corpus the check reports 8,774 sites, 13,944 bytes, where the recurrence reported 2,913 and 4,090. The two baseline builds gain without any extension -- libxul 1,400 to 1,695, Debian's libLLVM 594 to 710 -- from the planner's retries and from chains the recognizer now follows through andi, srli and sext.w. Go's row is 60 to 4,964, and 4,668 of those are Zb sequences, 4,365 of them bseti for li 1; slli k: Go declares no extensions, so every gate opens, and under -m rva20 its row is 296.

    V8 does not emit them: its builtin and code addresses go through a fixed six-instruction sequence that set_target_address can patch any 48-bit value into. Over a JetStream dump taken again for this change (TODO.md, entry 54) the check reports 687,606 sites, 5,579,580 bytes, where the recurrence reported 559,340 and 4,462,244: 463,982 in Maglev, 102,437 in baseline, 97,289 in TurboFan and 23,820 in regexp code. 403,843 of the fixed loads need four instructions and 148,631 three, and 74,632 findings are bseti for values such as 0x100000000, which V8 builds with li 1; slli 32; 53,523 touch a JS dispatch handle's relocation, so V8 may be patching them. SpiderMonkey's patchable li_ptr and li_constant are the same story at 1,469,516 sites, and its other constants rose from 50,817 to 156,287, about 80,000 of them boxed constants such as 0xfffc000000000001, true, built li -1; slli 50; addi 1 where a rotated lui takes two.

  • and/or/xor constant whose complement builds shorter -- a constant built only for and, or or xor whose complement li builds in fewer instructions. Zbb's andn, orn and xnor take the complement where the plain operations took the constant, so only the materialization changes; a constant built for those three is the same case reversed. SpiderMonkey's nursery check prompted it: the GC chunk mask is three instructions however it is built, and its complement is a rotated lui.

     lui  t4, 0x8000
     addiw t4, t4, -1
     slli t4, t4, 20
     and  t4, t4, a2     -> li t4, 0xffff8000000fffff in 2 instructions: lui, rori; andn t4, a2, t4 (16 -> 12 bytes)
    

    The chain is the entry above's and the uses are found by the immediate-operand check's walk; the constant must be dead after the last use or overwritten by it. Both values are planned as the entry above plans them, and the complement is measured against the shorter of the chain and that plan, so where both checks report a site their savings add. A mask of the low bits that is only anded with is left to the mask check, whose rewrite needs no constant at all. The swapped operation is priced at four bytes, since none of the three Zbb operations has a compressed form, so a site whose and was a c.and may not shrink, and is then not reported. A swap to andn, orn or xnor is gated on Zbb permissively; a swap away from one needs nothing.

    The SpiderMonkey corpus (TODO.md, entry 54), which predates the fix, has 67,705, worth 270,824 bytes: 66,596 of them the chunk mask, 42,495 in Baseline code and 24,096 in Ion, and most of the rest 32-bit masks in regexps such as 0xf0f0ffff, lui+addiw where the complement is one lui. V8's JetStream dump has 2,018, all andn and 1,980 of them in regexp code, masks of the same kind whose complement is lui; slli. The package corpus has 139 -- 59 xnor, 48 andn, 32 orn -- and they shrink by instructions more than by bytes, 132 in all, since in compressed code the plain operation was often two bytes and its replacement is four; Go's 58 are behind the gate an object that declares nothing never closes.

  • constant re-materialization -- a constant built into a register while the same value is still live in another, where the constant is too wide for c.li. Inside c.li's range the materialization is two bytes and so is the mv, so the rewrite would trade an instruction that depends on nothing for one that depends on another register.

    The test is the constant's magnitude, not the encoding's width. Those agree wherever the assembler selects RVC, and Go's does not: keyed on width this reported 41,813 sites in the Go corpus whose constants all fit c.li, and on a toolchain that left the li wide to begin with the rewrite saves nothing.

    These all read one structure, filled by riscvlint_state_observe, which the driver calls once per instruction after the checks -- each of them judges the instruction under the cursor against it as it stood before. None can be decided from a pair; the distances cluster at 4-15 instructions, which is why no pair scan ever saw them.

    The first corpus run produced three classes of false positive, each found by reading the disassembly around a finding rather than by any test, and each now a fixture:

    • A load that overwrites its own base. ld a1,0(a1) walks a pointer, so the following ld a2,0(a1) reads somewhere else entirely. 67 of ripgrep's first 151 reload findings.
    • A conditional branch between the two stores. "Dead" means the overwrite is certain, and on the taken path it does not happen. 32 of ripgrep's first 37 dead-store findings.
    • A memory access the decoder cannot place. The vector loads share LOAD-FP with flw and fld and are told apart by a width field the decoder does not model, so a vle64.v through an address taken with addi a0,s0,-272 was read as touching nothing. It reads the frame slot a store just wrote.

    What survives is checked against an independent pass over objdump's output: all 83 of ripgrep's reload findings, and every one of its dead-store findings by hand.

  • computation a live register already holds -- the question above widened from li to everything that writes one register as a function of registers: the same mnemonic over the same sources with the same immediate, where nothing has moved since. It is mv rd,rprev, or a deletion where the register about to be written already holds it.

     6f730: addi a0, s0, -0x70
     6f734: addi s3, s0, -0x70      -> mv s3, a0
    

    Two populations that were sized as separate candidates and turned out to be one check: a frame address, which is most of it, and ordinary arithmetic. Nothing in the check tells them apart -- the probe that measured them told them apart with one boolean, and the check does not need even that.

    29,595 sites and 62,212 bytes, the largest of the window's figures and fourth-largest of any check here by bytes. On C++ it is 21,230 sites, fourth again and within 131 of base-C compression; across C++ and Rust together it passes it. 28,052 become a move and 1,543 delete; the delete is tried first, because it is worth more.

    Eligibility is structural rather than a list of mnemonics, because the match is on the mnemonic anyway: one register written, no memory operand, not a transfer, and not one of the instructions whose result is not a function of its register operands -- csrr and rdtime read state this does not model, the f-prefixed writers of a general register read the other register file, li and lui are the check above, auipc is address re-materialization (measured at 39 and rejected) and mv is move coalescing (192, rejected).

    Two rules were false positives before they were rules. A computation whose destination is one of its own sources -- add a0,a0,a1 -- is not recorded at all, since nothing is left that can name the value it read; without that, every later add rd,a0,a1 matches it. And sp, gp and tp are never reported: addi sp,s0,-K over a frame that never moved is the stack-pointer restore above, which says more, and the other two hold what the ABI says they hold.

    The table this reads is the one place the window's three tables have to be told apart. A memory record is a claim about a place and a computation record is a claim about a register, so an access through an address the decoder cannot name -- a vector load or store -- takes the first kind and leaves the second, as do a fence, an atomic and a CSR read. Written without that distinction the check found 456 of ripgrep's 646 sites instead of 601.

    Where a match is already spelled in two bytes it is not reported: c.addi4spn names the destination and so would c.mv, so the rewrite saves nothing and trades an instruction that depends on nothing for one that depends on another register. That is the same byte rule the constant check applies, and here it removes a quarter of the population rather than 97% of it.

  • bit-cast routed through a frame slot -- a value moved between the two register files by storing it to a slot and loading it back, where one instruction does it and touches no memory.

     fa84: fsw ft6, 256(sp)
     fa88: lw  s1,  256(sp)       -> fmv.x.w s1, ft6
    

    Both widths and both directions: fmv.x.w, fmv.w.x, fmv.x.d, fmv.d.x. The pairing has to be exact on width and on what the load does with the bits -- fmv.x.w sign-extends the 32 it moves and so does lw, but lwu does not, so that pairing is not one of these.

    This is the one check here whose value is not bytes, and the table above says so: none of the four moves has a compressed spelling, so the rewrite breaks even against a four-byte load and would cost two against a two-byte one. It is refused there -- 869 of the 2,380 sites the probe finds are a c.lwsp or a c.ldsp reading the slot back. What the remaining 1,155 remove is a load, a store-to-load dependency through memory, and often the frame slot with it.

    It is also the reason the windowed table records floating-point accesses at all. Before this check they armed nothing, because the table's write scan could not see the f registers and a claim about one would never have been taken away. Now they do, and every other reader skips a record whose register is in the other file -- an f register and an x register with the same number are two registers, and the record's data field alone cannot tell them apart.

  • base add foldable into memory offset -- addi rd,rs,imm1 followed by <load|store> rt,imm2(rd) is one access at imm1+imm2 from rs whenever the sum fits the 12-bit field and nothing goes on to read rd. The direct analogue of armlint's add + ldr check.

    Population: 9,190 sites -- C++ 5,768, Go 2,993, Rust 429.

    This is the check the corpus warned about. Sampling the shapes -- pairs where the access's base really is the addi's destination and the sum fits -- gave 12,530 in libQt6Core alone and 24,705 in one Go binary. Applying the liveness condition leaves 1,393 and 684. A shape count is not a population, and here it overstated by roughly nine times.

    Where the access is a load that overwrites its own base the computed address is dead by construction and no liveness query is needed. That is about two thirds of the findings and it is steady across toolchains -- C++ 67%, Rust 72%, Go 68% -- while varying widely between binaries within one (libQt6Core 80%, gh 25%). So the rest of the check, the liveness walk, earns the remaining third everywhere.

    The byte figure needs the compressed encodings on both sides. addi and the access may each be two or four bytes going in, and what comes out depends on whether some compressed form can hold the folded offset -- which is a different question for the new base than it was for the old one. A fold onto sp is the case worth naming: no quadrant-0 form can name sp, but c.sdsp and c.ldsp can, so those sites still come out at two bytes. rv_mem_encoded_size and rv_decode_mem were checked against clang -march=rv64gc_zba_zbb_zcb over 3,632 loads and stores -- every width, both register files, offsets in and out of each compressed field's range -- and agree with the assembler on all of them.

  • instruction compressible to a base C form -- a four-byte encoding the base C extension spells in two. The sibling of the Zcb check, and the same kind of finding: RVC selection is an assembler pass, so a finding means the instruction was legal to compress and was not.

    Population: 35,027 in C++ and Rust -- 33,792 of it C++ -- and 2,961,593 in Go, 21% of its instructions. Those are two different results wearing one name.

    Go's assembler does not select RVC at all, and the number is what that looks like from the outside: not a list of sites anybody will fix one at a time, but the size of what a compressing assembler would buy, about 5.6 MB.

    The GCC and LLVM residue is smaller and more interesting, because both assemblers do select RVC. What is left is what they could not know at assembly time:

    • addi and ld halves of an auipc pair, whose immediate was a relocation when the assembler saw it and a small number after the linker resolved it.
    • branches and jumps whose final displacement landed inside the compressed field only once relaxation was done -- one of libQt6Core's is a beqz at exactly -256, the furthest c.beqz reaches.

    So on a toolchain that compresses, this is a linker-level finding, the way the auipc+jalr check is. It is also where a fourth spelling-sensitive gap in GNU as turned up: jr a5 compresses and jalr zero, 0(a5), the same instruction, does not.

    A four-byte nop is never reported. It is either alignment padding, which exists for its width and stops working if it shrinks, or it is dead and wants deleting -- and that is 1,621 sites in the GCC/LLVM cohort that would otherwise be noise.

  • instruction compressible to a Zcb form -- a four-byte encoding that Zcb spells in two. Unlike every other check here this one reports an assembler's choice rather than a compiler's: RVC selection happens at assembly time, so a finding means the instruction was legal to compress and was not.

    Population: 30,649 with the gate in force -- 29,762 Go, 705 libQt6Core, 181 uutils, and 1 everywhere else. The baseline objects contribute nothing because they declare no Zcb and the gate is right to stay shut; forcing it reports 320,550 over libxul and 174,980 over debian-libllvm22, which are the two largest things -m has to say about any binary here.

    The two figures answer different questions and should not be added. 30,649 is what the assemblers left on targets that have the extension; the other is what enabling it on a baseline build would buy -- and since the corpus now holds the same libLLVM release built both ways, that second figure has been checked rather than only predicted: 174,980 against the 166,673 Zcb instructions the RVA23 build actually contains, within 5%. See the libllvm22 pair.

    Every Zcb form names its registers with a three-bit field, so x8-x15 only, and the memory forms carry an unsigned two-bit byte offset or a one-bit halfword offset. Those rules were checked against GNU as and clang before being written down. The two agree except on mul rd,rs1,rd: multiplication commutes, so clang swaps the operands and compresses it while GNU as leaves it wide. That single gap is 303 of libQt6Core's 705 findings, and the other 402 are its sibling -- GNU as compresses not rd,rd but not the xori rd,rd,-1 it expands to. Both are binutils gaps rather than anything a compiler chose, and a binary cannot tell the spellings apart because they assemble identically.

  • redundant sign or zero extension -- an extension applied to a value that already has that form: sext.w after lw, andi rd,rd,255 after lbu, sext.h after lb. Where it writes back the register it read, deleting it leaves that register bit-identical, so like the zext.w check and unlike everything else here it needs no liveness query at all; where it writes elsewhere it becomes a mv.

    Population: 10,209 sites -- 8,283 C++, 1,593 Go, 333 Rust. Within C++ it is 3,433 libQt6Core, 2,253 libxul and 815 libLLVM, and libQt6Core against libLLVM is the contrast worth keeping: this is GCC's residue where the stack-restore check is clang's -- the same corpus, the other compiler's habit, and neither would have been visible with one C++ compiler in it.

    Report it as instructions rather than space. sext.w rd,rd after lw assembles to c.addiw rd,0, two bytes, and the assembler picks c.zext.b over the four-byte andi rd,rd,255 whenever the register is in x8-x15 -- so most deletions save two bytes, not four. Capstone prints both spellings with the wide mnemonic, and reading a site as the four-byte form is what made this check come out a fifth short the first time it was measured.

    What a producer guarantees is tracked as a mask per register, with the closures applied when the guarantee is recorded rather than when it is tested: a value that fits 8 bits fits 16 and 32, and one sign-extended from bit 7 is sign-extended from bit 31. The one relation that does not hold is zero-extension to 32 implying sign-extension to 32 -- lwu of 0x80000000 is the counter-example, which is why sext.w after lwu is a real instruction and not a finding. Bounding the value by an andi mask rather than by a load mnemonic is what catches sites like andi a0,a1,1 followed by a zext.b.

  • dead register definition -- an instruction whose only effect is to write a register nothing goes on to read; deleting it is free. Unlike the others this cannot be decided from a pair, so it runs a bounded liveness walk over every path leaving the definition and reports only what that proves dead. The commonest shape is a frame pointer established and never used.

    Population: 22,292 sites -- C++ 14,151, Go 7,876, Rust 265 -- and the first check here that fires meaningfully on C++, where libxul's 5,443 and libQt6Core's 5,203 nearly tie. The walk makes no ABI assumptions: what a call may read and what a return exposes both differ between the C and Go conventions, and riscvlint cannot tell which it is looking at, so both answer "unknown" rather than guessing.

  • copy its only reader could do without -- mv rd,rs whose one reader could name rs instead, with rd gone after that reader: the copy is deleted and the reader rewritten. SpiderMonkey's Wasm GC code sets up one builtin call this way, a copy of t0 stored where t0 itself could have been:

     mv a1, t0
     sd a1, 0(sp)                       -> delete; sd at 0x4 names t0
     ld a1, 8(sp)                          (8 -> 4 bytes)
    

    The reader is the first instruction on the straight line after the copy that reads rd, within 32 instructions, with no side entry before or at it, nothing writing rd on the way (that copy is dead, which is the dead-definition check's) or rs (the reader could no longer name it), and no transfer; a reader that is itself a branch or transfer is declined. After the reader the copy's value has to be gone: rd written by the reader itself, or dead on every path from it by the same liveness walk the dead-definition check runs, so that the reader was the only one. And the reader has to read rd through a register field of its own encoding -- ret reads ra and the sp-based forms read sp with no field to change -- where a compressed three-bit field can only name x8-x15 and a compressed read-modify-write field cannot change its source alone, so in either case the reader takes its four-byte form and the saving is the copy less the widening.

    This is the forward direction of the move coalescing TODO.md rejected for the package corpus (an operation followed by a move of its result), read the other way round. The SpiderMonkey corpus (TODO.md, entry 50) has 137,201 by the miner's count, 124,494 of whose readers are stores, and the check has not yet been run over it. Over the package corpus it reports 9,733 sites, 22,428 bytes: C++ 4,307, Go 4,399, Rust 1,027. The largest shape, 3,698, is a copy of sp stored -- mv a2,sp and later sd a2,0x68(sp), where sd sp,0x68(sp) is a legal instruction -- and another 771 are vector loads and stores through a copy of sp and 417 a sub from one. Go contributes 1,923 loads through a copy of its g register, mv t1,s11; ld t1,0x180(t1), and 729 mv t0,a0; neg t0,t0. libxul holds 2,653 and the Debian LLVM 22 build 1,353 against the Ubuntu build's 96; of Rust's, 1,024 are in coreutils.

  • address computed for one indexed load -- add rd,rb,ri + lw rt,0(rd), which Zilx's indexed loads do in one instruction: lxw rt,(rb),ri.

    Zilx (Indexed Integer Load) is the extension that gives RV64 the addressing mode it has never had. The base ISA has exactly one -- imm12(base) -- which is why a[i] costs a shift, an add and a load where AArch64 writes ldr x0,[x1,x2,lsl #3], and why RISCVMergeBaseOffset and RISCVFoldMemOffset exist at all. The encodings are taken from LLVM's RISCVInstrInfoZilx.td rather than from the ratification plan's prose, for the reason the fli check gives: the assembler is what has to accept the suggestion. They reuse the AMO major opcode with funct5 values that were reserved -- 0b10010 unscaled, 0b11010 scaled, 0b11110 scaled with a zero-extended 32-bit index -- and put the index in rs1 with the base in rs2, the reverse of a normal load.

    Population: 157,829 sites across the corpus under -m zilx, which would place it fourth in the table above if it appeared there: 52,435 in libxul, 38,183 in debian-libllvm22, 18,860 in Ubuntu's libLLVM 22, and 19,741 across the twelve Go objects. Nearly half saves no space: in libxul 24,602 of the 52,435 are a compressed c.add and a compressed load folding to a four-byte lxd, four bytes for four. Those still remove an instruction and an address dependency, and the finding says (4 -> 4 bytes) so a reader can tell; 20,212 save two bytes and 7,621 save four.

    -m zilx is the only extension name here that no profile turns on -- Zilx is in none of RVA20, RVA22, RVA23 or RVB23 as of LLVM's RISCVProfiles.td -- and the three Zilx checks are the only ones that require their extension to be positively present rather than merely un-denied. Every other gated check fires on an object that declares no attributes, because treating "absent" as "no" would silence a check on the very code it exists for. That rule assumes the extension is one some target plausibly has. Zilx is in no profile and no shipping core, so the permissive reading would have put 25,188 findings on the Go objects alone, suggesting an instruction nobody can execute. They fire when an object declares _zilx or when -m zilx asks the what-if, and otherwise not at all -- which is why every figure in these three entries is an -m zilx figure and none of the three appears in the table.

    Loads only, and integer loads only: Zilx has no indexed store and no indexed floating-point load, so a store or an fld through a computed base is not a finding however much it looks like one. Byte loads have no unscaled encoding, but the scaled byte form's scale factor is 1, so lb/lbu fold to lxsb/lxsbu with identical arithmetic.

    The two deeper shapes are the checks below, and none of the three overlap: a scaled or zero-extending finding replaces the unscaled one at the same add rather than standing beside it.

  • address scaled for one indexed load -- slli rt,ri,3 + add rd,rb,rt + ld rt2,0(rd), which Zilx's scaled form does in one: lxsd rt2,(rb),ri. This is what a[i] actually costs on the base ISA, and what AArch64 has spelled ldr x0,[x1,x2,lsl #3] from the beginning.

    The scale factor is log2 of the access size and nothing else, so the shift the code already performs has to agree with the width the load reads. That one condition is the difference between a population and a coincidence: of libxul's 20,881 triples of the right shape, 7,897 shift by an amount no load width matches, and without the test libLLVM reads 78% high. Byte loads scale by 1, so their shift is zero and that site belongs to the unscaled check above.

    Population: 25,222 sites under -m zilx -- 10,565 in debian-libllvm22, 8,450 in libxul, 5,170 across the twelve Go objects. Every one of them saves space, which the unscaled shape cannot say: three instructions is at least six bytes and the fold is four, so there is no (4 -> 4 bytes) row. In libxul 4,664 save two bytes, 2,837 save four, 946 save six and 3 save eight.

    These are not new sites. Each one's add was already an unscaled finding, so the three Zilx columns sum per object to what the unscaled check alone reported before the other two existed: 8,450 + 1,735 + 52,435 = 62,620 in libxul, 10,565 + 2,746 + 38,183 = 51,494 in debian-libllvm22. What the deeper folds add is depth rather than breadth -- libxul's saving at those same 62,620 sites goes from 78,260 bytes to 108,844, because 6,512 of the sites that saved nothing at all now save at least two.

    Two writes disappear here rather than one, the shifted index and the address, so both have to be gone. Each dies by construction wherever a later instruction of the triple overwrites it -- the add over the shift, the load over either -- which is what the common slli a5,a5,3 + add a5,a0,a5 + ld a5,0(a5) is; anything else is proved by the liveness walk or declined. Of libxul's 12,984 width-matching triples that costs 3,092 to the address still being read and 1,345 to the index, and 97 more to something branching into the middle.

    This check is an argument about extensions rather than compilers. Of the 25,222 sites, 77 are in the nine corpus objects that declare Zba and 25,145 are in the twenty-two that do not. Where Zba is available the slli+add is already one sh3add and this triple never forms: ripgrep, libQt6Core and Ubuntu's libLLVM 22 have literally none of it, against 10,565 in Debian's build of that same LLVM release. (Those two libLLVM builds are not a controlled pair -- the toolchains differ too, as the frame-pointer figures in TODO.md show -- but eight other Zba objects say the same thing.) So the sequence has two answers at two prices: Zba halves it and Zilx removes it.

  • address scaled from a zero-extended index -- slli rt,ri,32 + srli rt,rt,29 + add rd,rb,rt + ld rt2,0(rd), which Zilx's third addressing mode does in one: lxsuwd rt2,(rb),ri. That mode is funct5 0b11110 and computes base + (zext32(index) << log2(size)), so it folds the zero-extension as well as the scale. This is what a[i] costs when the index is a 32-bit unsigned value and the array is addressed through a 64-bit base: the RV64 ABI keeps a 32-bit value sign-extended in its register and an unsigned index is not, so the top word has to be cleared first, which the base ISA spells as a shift left and a shift back. Four instructions on rv64gc, two with Zba's shNadd.uw, one with Zilx.

    The slli must be by 32 exactly, since the zero-extension is from bit 31 and nothing else; the srli then carries the scale, and the scale is the access width. A byte load's scale is 1, so its pair is zext.w itself.

    Population: 4,963 sites under -m zilx -- 2,746 in debian-libllvm22, 1,735 in libxul, 277 across Go, 0 in Rust. Every one saves at least four bytes, four instructions being eight at the very least: libxul's are 216 at (8 -> 4), 728 at (10 -> 4) and 791 at (12 -> 4), 11,560 bytes.

    What the width test costs is not uniform, and the two big C++ objects disagree about it by a factor of thirty. In libxul 82 of 3,829 width-tested quads shift by an amount no load width matches -- 2%. In debian-libllvm22 12,799 of 18,411 do -- 70%, and 10,133 of those at srli 28 alone, a stride of 16 this extension cannot address. riscvlint sees the stride and not the type, so read that as one program's data structures showing through rather than as a fact about 16-byte records. Either way the same test is nearly free on one object and decides the number on the other, which is the argument for keeping it rather than reporting the quad on its shape alone.

    Three writes disappear rather than two -- the widened index, the narrowed index and the address -- so the liveness walk can be asked three times. The common case writes one register throughout and needs no walk: slli a5,a5,32 + srli a5,a5,29 + add a5,a0,a5 + ld a5,0(a5). Of libxul's 3,747 width-matching quads the proofs cost 1,352 to the address, 531 to the narrowed index and 100 to the widened one, with 29 more to a branch into the middle. The srli writing a register the slli did not is allowed and is the case needing all three proofs at once; it is 1,194 of libxul's 3,747 width-matching quads and 347 of libLLVM's 5,612, so refusing it to save a query would cost real sites.

    Not one of these is in an object that declares Zba, which is a stronger statement than the scaled shape's 77: Zba's add.uw and shNadd.uw do base + zext32(index) scaled in a single instruction, so the four-instruction sequence does not exist on those targets at all rather than merely being rarer. ripgrep has no slli ...,32 + srli pair anywhere in it.

  • a bit count spelled out longhand -- twelve instructions and four mask constants that compute a population count, which Zbb's cpop does in one. RV64GC has no bit-counting instruction, so llvm.ctpop is expanded inline into the Hacker's Delight sequence; on a target with Zbb it is cpop rd,rs.

    Population: 1,560 sites under -m rva23 -- 933 in libxul, 595 in Debian's baseline libLLVM 22.1.8, 32 across four smaller Firefox objects -- and 0 under any object's own declaration, in every language. The objects that declare Zbb use cpop already (Ubuntu's build of that same libLLVM release does so 2,016 times) and the baseline ones declare no Zbb for the gate to open. So this is the third check whose figure is an answer to "what would rebuilding buy me" rather than a compiler miss, and the only one that reports nothing at all without -m.

    It is matched as dataflow, which nothing else here is. Every other check reads adjacent instructions or a table keyed by address, and neither works on this: the scheduler interleaves the four mask materializations with the arithmetic and reorders the independent halves of the middle stage. So each register carries what it is known to hold -- which stage of the expansion, and which register the sequence started from -- and the finding is reported at the final shift, when one register's history reaches all the way back. A missing link anywhere means no finding, so the match is false-negative-safe by construction rather than by a bound.

    What it costs to be sound: 74%. The sequence computes in place, overwriting the very register the rewrite would name -- sub a1,a1,a2 is how stage one is spelled -- and cpop rd,a1 leaves a1 holding what it held where the sequence left it holding a partial sum. So the source has to be dead, and the bounded ABI-agnostic walk proves that for 595 of 2,312 sequences in libLLVM. The same walk, declining for the same reason, is what made move coalescing a rejection.

    Two other things it will not claim. The byte figure counts only the twelve instructions matched and never the mask materializations, since whether those die with the sequence needs liveness this does not have. And the 32-bit and 64-bit forms are told apart by their masks and their final shift together -- srliw ...,24 against srli ...,56 -- so a sequence mixing them matches neither.

  • floating-point constant fli would have built -- auipc rd,%pcrel_hi(L) + fld frd,%pcrel_lo(L)(rd) where the eight bytes at L hold a value Zfa's fli.d materializes in one instruction. The pair, the load and the pool slot all go. Also the flw/fli.s spelling; the absolute lui %hi one measures zero, because the one place it appears its lui fits c.lui, which pairs with a two-byte c.fld and so is a different pair.

    This is armlint's "ldr literal of an encodable constant" with the two architectures the other way round, and it is the clearest case in either tool of a check whose worth is a property of the ISA rather than of the compiler. AArch64 has fmov #imm8 and movi at baseline, so LLVM materializes every encodable FP constant and armlint's version of this check measured 35 sites in 42,324 pool loads -- 0.08%, and closed. RISC-V has no floating-point immediate at all without Zfa, so on a baseline target the pool is where every constant goes.

    Population: 3,428 sites, which splits on the declaration rather than on the compiler. 3,308 are the nine baseline Firefox objects under -m rva23 (libxul 2,966, libgkcodecs 210, the rest two figures), 120 are Go, whose assembler selects no Zfa, and 0 are the eight objects that declare zfa1p0 -- where the compiler was allowed to use fli it already had, 798 times across the corpus. So this is an -m rva23 finding in the same sense the Zcb check is: an answer to "what would rebuilding for RVA23 buy me", not a peephole anyone missed.

    Whether an entry exists is decided by a port of LLVM's RISCVLoadFPImm::getLoadFPImm, in integer arithmetic rather than through a float, so the answer does not turn on the host's rounding mode or on what a double-to-float conversion does with a NaN payload. The assembler is the oracle that matters -- a finding is only advice if the immediate it names exists -- so the table is transcribed from RISCVBaseInfo.cpp rather than from the spec, for the same reason the census's profile rungs came from RISCVProfiles.td. What libxul's pool actually holds, in order: 1.0 x909, nan x787, 0.5 x664, inf x468, -1.0 x207, then a tail.

    It is the first check that reads anything outside the section being scanned, which the library exposes as riscvlint_state_set_image. Its contract is that only allocated, non-writable contents are served: a constant the program can overwrite is not a constant, and .data.rel.ro is writable at load time precisely so the dynamic linker can relocate into it. A relocatable object is refused outright, since all its sections sit at address 0 and "the section holding this address" names nothing there. Without a provider the check stands down, so a library caller with no image to offer loses findings rather than correctness.

    What the preconditions cost: 3,459 of libxul's 14,992 adjacent pool loads hold an encodable value, 3,441 survive the branch-target and relocation tests, and 2,966 survive the liveness one. That last proof is the expensive one and it is not optional -- the rewrite stops writing the address register, and a pool address is often used again for the slot next door. In Go it costs far more: 84 encodable, 14 reported, because the gc assembler routes pool addresses through t6 and reuses it.

  • floating-point constant built through an integer register -- the same kind of constant, spelled the way V8 spells it: a chain the constant-chain check would follow, li t3,1023; slli t3,t3,52, and directly after it fmv.d.x ft6,t3, or fmv.w.x moving the low 32 bits, where the value is one fli builds. The chain and the move go for one fli. Nothing may branch into the sequence, and the integer register must be provably dead after the move, since the rewrite stops writing it. A pool load into the integer register would be the other spelling, and it measures zero: no entry takes more than three instructions to build, and V8 pools only a constant li takes four for.

    V8's LoadFPRImmediate builds every constant this way unless fli can, and it asks whether fli can only in the overloads that take a float or a double. Maglev calls those, and its code in the JetStream corpus (TODO.md, entry 47) has 1,467 fli. TurboFan passes the bits of its Float64 constants instead, and the check reports 312 sites there, 2,496 bytes, every one li + slli: 1.0 x162, 0.5 x49, the canonical NaN x30, 2.0 x17, then a tail. Over the package corpus it reports 205, all in Go binaries, 1,672 bytes: Go's assembler too builds a floating-point constant in an integer register and moves it across.

Options

Every option has a long name and a one-letter alias, and riscvlint --help prints the table. The letters shared with armlint and x86lint (-v, -i, -c, -m, -a and --json) mean the same thing in all three tools, -r the same as in x86lint, and so do their long names; both of them spell --function -f, which is why the fusion report is -u. A value follows its option as the next argument or joined with = (--assume=rva23), and options are read wherever they stand among the files.

option effect
-v, --verbose print each finding with its disassembly
-q, --quiet the default; kept for the scripts that passed it
-i, --isa an ISA census in place of the lint scan
-r, --registers a register census
-u, --fusion a macro-op fusion report in place of the lint scan
-c, --constants also report the constants the code builds, by cost
--json the findings as a JSON document on stdout
-m EXT, --assume EXT the target has EXT: zba, zbb, zbs, zcb, zfa, zilx, zibi, zacas or c; rva20, rva22 and rva23 name a profile
-a AUDIT, --enable AUDIT also run the imm or const audit
-h, --help print this table

The sections below name each mode by its letter, which is how the examples spell it.

Selecting the target

-m <name> (--assume) pins the extensions the checks may assume, and may be repeated. Names are either extensions (zba, zbb, zbs, zcb, zfa, zilx, zibi, zacas, c) or profiles that bundle them (rva20, rva22, rva23). zilx, zibi and zacas are the three no profile contains, so they only ever arrive by being named -- and the checks behind them are the five that want the extension positively present rather than merely un-denied.

-m replaces what the object declares, in both directions, because both are useful and neither is expressible if the flag merely adds to the declaration:

riscvlint -m rva23 ./app     # what would rebuilding for RVA23 buy me?
riscvlint -m rva20 ./app     # this is going on rv64gc hardware; stay quiet

Every profile from RVA20 up mandates C, so -m rva20 silences the Zb families and the Zcb check but leaves the base C one on -- rv64gc hardware does have the C extension, and an instruction that could be two bytes on it still could be.

rva22 and rva23 do not expand alike. Zcb missed RVA22's ratification window and is mandatory in RVA23U64, so it is the first extension gated here that tells the two profiles apart -- and on the corpus's one baseline build it is by far the largest difference between them. Zfa is mandatory there too, and is the second.

Without -m, the arch string decides, and a file that carries none is reported as such rather than silently assumed permissive.

Audits (-a, --enable)

-a <audit> is a different kind of flag from -m. -m asserts what the target can run, so that a rewrite may use it; -a opts into a report about the code that proposes no rewrite. Every audit finding is a review item rather than a missed fold -- nothing at the site can be respelled -- and the review item is a constant, so the summary tallies the audits by value, most frequent first, and those tables are the report. The two audits are armlint's -a imm and -a const, the two of its three that have a RISC-V shape; its PAC audit has none.

Audit findings count toward the total and the exit status like any other, so a test suite that gates on a clean run should not pass -a. -a may be repeated, and is accepted under --json, where each audit finding carries its tuple as fields.

Immediate-misfit audit (-a imm)

The complement of the constant folds. The immediate-operand check above reports li rc,K whose consumer could have taken K as an immediate; the audit reports the constant whose consumer has an immediate form the value misses: lui a5,1; add a0,a1,a5, where 4096 is one past addi's reach. Four consumer classes, each against its own field:

  • add, addw, sub, subw, slt, sltu against the 12-bit immediate of addi, addiw, slti, sltiu, a subtrahend as addi of its negation (-2047..2048);
  • and, or, xor against andi, ori, xori, where a mask of the low n bits counts as fitting -- zext.h, zext.w or the shift pair takes it, and the mask check reports those sites;
  • beq, bne against Zibi's beqi/bnei imm5 (1..31 and -1), only under -m zibi: without the extension the branch has no immediate form to miss, RV64I having no compare-immediate-and-branch at all;
  • a load or store through a base computed from the constant -- lui + add or lui + sub and then the access, or addi and then the access -- against the access's own 12-bit offset, tallied as the byte offset the access would carry: lui t,1; sub t,s0,t; sd a5,2040(t) is the frame slot at -2056, one step past the field.

The constant is li, lui, or the chain the constant-chain check follows, and the consumer follows it directly. The operand rules are the folds' own: the constant in an immediate-capable slot (sub, slt and sltu take it second only), the other operand neither x0 nor the constant's register. The shifts are left out, since a shift amount is read modulo the width and never misses; zero and all-ones under a logical operation are identities and are skipped.

Nothing at the site can be rewritten -- lui+addiw is already the cheapest spelling of 4095 -- so the finding is informational and the review item is the constant itself. A value the code's author chose (an object-size limit, a sentinel, a field's offset) that lands one step past the field costs an instruction and a register at every use, and choosing it one step differently turns every site into the immediate form. No liveness proof is made: a constant hoisted into a live register amortizes its materialization, but each use still pays for the register operand the immediate form would not need.

The summary adds two tables below the by-type one: the constants within one step of an immediate form -- a magnitude up to 4096 for a 12-bit field or offset, up to 63 for Zibi's imm5 -- which is the renumbering worklist, and then everything beyond reach, whose whole magnitude is the point: tags, hashes, INT64_MIN as an enum niche. A real corpus is dominated by the second kind, which is why they are kept apart. Each row is a count of sites, the consumer class, a width letter (x or w for an operation; the access size b, h, w or d for a load or store), the constant, and what would have encoded:

$ ./riscvlint -a imm -m zibi ./app
...
Immediate misfits by value (-a imm), within one step of an immediate form:
     ...  add/sub imm12  x  4096         addi/slti immediates cover -2048..2047; sub -2047..2048
     ...  branch imm5    x  32           beqi/bnei immediates cover 1..31 and -1
     ...  ld/st offset   d  2056         immediate offsets cover -2048..2047

Immediate misfits by value (-a imm), beyond one step (informational):
     ...  logic imm12    x  65536        0x10000; andi/ori/xori cover -2048..2047; low-bit masks zext

Where AArch64's -a imm has bitmask hints and a shifted add immediate to aim at, RISC-V's field is one signed range, so the hint is the range and the only encodable neighbour of a misfit is the field's edge. Two things are larger here instead. The branch class is a question about the extension rather than the code: TODO.md's entry 30 counted 238,018 equality shapes with a constant outside Zibi's imm5 beside 461,300 inside it, and this table says which values those are. And the load/store class is harsher: base RISC-V has no register-offset addressing, so a field past the 12-bit reach costs lui, add and the access, three instructions for one, at every width.

To find the sites of one value, -v prints each finding as ... (imm audit) at offset: 0x...: -> 4096; addi/slti ..., so a grep for the constant lists them with their functions.

Constant audit (-a const)

The misfit audit's twin, for the constants that fit: the same four consumers under the same operand rules, where the consumer's immediate form would have held the value -- li a5,5; add a0,a1,a5 where addi a0,a1,5 was available. The folds report this shape as a two-for-one once the liveness walk proves the constant's register dead, since their rewrite deletes the materialization; the audit reports every site with no proof, since the immediate form is a valid rewrite with the materialization kept, and renders it: -> addi a0, a1, 5; -> addi a0, a1, -5 for a subtraction; -> zext.h a0, a1 for a mask; -> beqi a4, 17, 0x100a under -m zibi; -> ld a1, 24(a0) for an access through a computed base. A site the fold proves is reported under both names.

Why no proof: in compiler output the deletion proof fails for reasons unrelated to the site -- the walk stops at a call, or the allocator keeps the register for a second use -- and a JIT whose register allocator materializes every constant input produces the shape at every compare, with a deoptimization exit the walk cannot see past. That is TODO.md's entry 44 exactly: riscv64's Maglev takes a constant right input in a register where arm64's takes an immediate, the miner counted 20,743 of the shape and the fold proves 1,738. The fold's count is what a peephole could delete; the audit's is the population an instruction-selection change reaches, which riscvlint could until now only cite from a miner.

The summary's third table tallies the audit by value, with the form that takes each constant as its hint.

Over the corpus the two audits report 657,596 misfits and 685,744 constants with a form; TODO.md's entry 53 has the tables. The constant audit's branch class, 461,307 sites under -m zibi, is entry 30's in-range shape count to within seven sites, measured by the tool itself this time, and the fold reports 177,581 of it. The misfit audit's answer to the Zibi question is that imm5 covers 59% of the corpus's equality comparisons against a constant, one more bit would reach 69%, and a 12-bit immediate 87%; the leading out-of-range constants are LLVM's DenseMap empty key, rustc's enum niche and SpiderMonkey's shifted JS::Value tags, none of which a renumbering reaches.

ISA census (-i, --isa)

riscvlint -i replaces the lint scan with a census: every instruction in the binary's executable sections, attributed to the extensions it needs. AArch64 versions its architecture, so armlint reads a ladder off Armv8.x; RISC-V names its extensions instead, and the rung here is the RVA profile that made each one mandatory -- Zba/Zbb/Zbs and Zfhmin at RVA22U64, V and Zicond and Zcb and Zfa and Zawrs at RVA23U64. The question is the same one: what was this binary compiled for. -m pins what the checks may assume and so has nothing to say here; passing both says so rather than quietly ignoring the flag.

$ ./riscvlint -i corpus/cpp/firefox-esr--libxul.so
ISA census of corpus/cpp/firefox-esr--libxul.so: 35581433 instructions, 0 undecodable halfwords skipped
  RV64I baseline: 15279008
  RVA20U64: C (18752804), F (1062316), M (220322), D (176508), A (140873)
  RVA22U64: none
  RVA23U64: none
  outside the RVA profiles: none
  hint space: Zihintpause (646)
  vendor: none
  minimum profile implied: RVA20U64
  declared: rv64i2p1_m2p0_a2p1_f2p2_d2p2_c2p0_ziccamoa1p0_..._zca1p0_zcd1p0
  used but not declared: Zihintpause

The rungs are transcribed from llvm/lib/Target/RISCV/RISCVProfiles.td rather than from memory, because the membership is not what anyone guesses: Zifencei is mandated by RVA20S64 and by no RVA U-mode profile at all, Zicbop is in RVA22U64, and Zbc, Zacas and Zfh are in none of them.

Three lines never raise the level. Zihintpause's pause, Zihintntl's ntl.* and Zicbop's prefetch.* are hints -- their encodings are a FENCE, an add x0,x0,x5 and an ori x0,... that a core without the extension executes as written and ignores -- so they get a line of their own, exactly as armlint's hint-space PAC and BTI do. libxul's 646 are a backoff spin loop in mozglue, and they are why that binary is reported as RVA20U64 despite using an RVA22 extension: it runs on rv64gc hardware. Everything no RVA profile mandates gets the other line, since a single -march= token bolts any of it onto an older target; vendor extensions get a third, being outside the standard encoding space entirely.

The attribution is capstone's own, read from the feature groups its RISC-V module generates out of LLVM's instruction predicates, and matched by group name -- the numbers are generated content with no assigned values past the first, so they move whenever capstone regenerates against a newer LLVM. This is the second thing riscvlint trusts capstone for, and it is sound where the operand model is not: a predicate says which extension defines an encoding, which is exactly what a census asks. The exceptions are the CSR instructions, fence.i and the two uncompressed hints, which carry no feature group at all and are picked out of the encoding instead -- otherwise csrr a0,cycle would be reported as base RV64I, which is what it is not.

An instruction can need two extensions at once: c.zext.w needs Zcb for the encoding and Zba for the instruction, c.fld needs C and D. Each is counted under both, so the per-extension counts sum past the instruction total by exactly the instructions that do. The baseline line does not overlap them -- it counts what needed nothing beyond RV64I.

Since RISC-V objects say what they were built for, the census also reports Tag_RISCV_arch and names anything used that the string does not declare. Only the Z* and X* extensions are cross-checked: the single-letter ones live in the base token, which a producer may spell rv64i2p1_m2p0_a2p1_f2p2_d2p2_c2p0 or rv64gc as it likes, and reading the second as declaring nothing would report six extensions undeclared on every object built that way.

Read the census as presence, not requirement: an extension reached only through a runtime dispatch counts the same as one on every path. An undecodable halfword may be data in text or an extension this capstone cannot decode, so the skipped count bounds what the census could have missed -- and treat a small exotic tally in a binary with many skipped halfwords with suspicion. With -v the census prints up to four sample addresses per extension, which is what checking one in a disassembler takes.

Three results from the corpus. Firefox is a plain rv64gc build throughout -- no Zba, no Zbb, no Zbs anywhere in 35.5 million instructions -- which is why the extension-gated checks find so much in it. Debian's libLLVM, libQt6Core and all six Rust binaries are the opposite, every one of them RVA23U64 with Zba, Zbb, Zbs, V, Zcb and Zicond woven through, and all eight declare a matching arch string.

The twelve Go binaries declare nothing at all, and every one of them still reports RVA23U64 -- off a tally of a couple of hundred instructions, which is where the difference between presence and requirement stops being abstract. Go 1.26's own toolchain binaries carry the same 208 vector instructions each, a compare loop the runtime reaches only through a byte-sized HasV flag: they run on rv64gc hardware and never execute it, exactly as glibc's outline-atomics LSE does on AArch64. gh and restic carry a different twelve, an inlined 48-byte copy in the cgo glue beside a getpwnam_r call, compiled by Debian's GCC for a V-capable target with no guard at all -- that one faults. The census counts both the same way, because from the encodings they are the same thing; the sample addresses are what tells them apart.

Register census (-r, --registers)

riscvlint -r replaces the lint scan with a census of registers: which architectural registers the code names, in what role and in which encoding width, and how many bytes the choice of register number cost. It is x86lint's -r with the axis RISC-V has. x86-64 numbers a register with three bits and takes the fourth from a REX prefix, so r8-r15 cost a byte per use; the compressed CL, CS, CA and CB formats name a register with three bits and nothing else, so an operand outside x8-x15 costs the whole two-byte form and the instruction is spelled in four. It sweeps the same bytes as -i and combines with it.

$ ./riscvlint -r corpus/rust/ripgrep--rg
register census of corpus/rust/ripgrep--rg: 819303 instructions, 0 undecodable halfwords skipped
  general-purpose registers: references by role and by encoding width;
  * marks x8-x15, the eight a three-bit compressed field can name
    reg       insns  share   operand      base    2-byte    4-byte   blocked
    zero      17979   2.2%     18154         0         6     18148      1847
    ra       107676  13.1%    107698        14     15851     91861        64
    sp       114174  13.9%     49198     81489    114852     15835       200
    ...
    s0       120636  14.7%     58857     61779     22550     98086         0  *
    s1        74267   9.1%     62623     17067     45920     33770         0  *
    a0       215330  26.3%    221978     26889     99164    149703         0  *
    ...
    a6         8371   1.0%      8346       526      2126      6746      1075
    a7         6830   0.8%      6914       338      1534      5718       906
    s2        38916   4.7%     31959      7866     20488     19337      8237
    s3        34095   4.2%     27871      6991     16302     18560      7494
    ...
  vector registers: 19129 references in 17580 instructions
  implicit ra: 931 links write it and 6644 returns read it without showing it
  encoding cost of register numbering: 89734 bytes
    base C forms kept at four bytes by a register outside x8-x15 alone: 44867 sites
      c.ld 23491 (base 19549, data 7018), c.sd 11584 (base 8498, data 5585),
      c.beqz 2783, c.sw 1275 (base 753, data 785), c.or 1215, c.and 1077,
      c.bnez 921, c.lw 848 (base 602, data 418), c.sub 775, c.xor 647,
      c.addi4spn 178, c.subw 40, c.srli 16, c.addw 10, c.andi 7
    the blocking register: s2-s11 44041, t0-t6 and a6-a7 5029, zero/ra/sp/gp/tp 2111, f-registers outside f8-f15 0
    Zcb forms, counted apart because the target may lack them: 3892 sites, 7784 bytes
      c.lbu 2281 (base 1720, data 870), c.sb 1265 (base 573, data 849),
      c.mul 165, c.sh 123 (base 96, data 60), c.lhu 24 (base 5, data 19),
      c.sext.h 12, c.lh 8, c.zext.b 7, c.zext.w 7
    accesses through s0: 61779, 61740 at a negative offset -- frame-pointer locals, below the reach of the unsigned compressed offset

References are counted per operand, so add a0,a0,a1 names a0 twice, and insns counts each instruction once; operand is a register the disassembly shows and base the address register of a load or store. The disassembler expands compressed instructions, so c.add a0,a1 counts as add a0,a0,a1, and the 2-byte and 4-byte columns say which spelling each reference sat in. The table is read from capstone's operand model -- the question is what the rendering names, and the rendering is capstone's -- and the one thing that model leaves out, the ra a jal, a jalr rs or a ret uses without showing it, is counted on its own line by raw decode rather than folded into ra's row. Floating-point rows print only when used, and vector registers as a total, since no compressed form names one.

The cost section is the reason the census exists. Every four-byte instruction is put to the same predicates the compressibility checks use, asked a second question with the same code: would a compressed form hold it if the registers it names were in x8-x15. Every other condition is still tested -- an ld at offset 256 or a sub that is not in place is not counted -- so what remains is the sites a register alone kept at four bytes, two bytes each. Each is attributed to the registers that blocked it in the blocked column and grouped by what they are:

  • s2-s11 hold values that live across a call, and only two callee-saved registers, s0 and s1, are nameable -- one of them taken by the frame pointer where there is one -- so this share has no alternative within the ABI. It is 44,041 of ripgrep's 51,181 blocking registers.
  • t0-t6, a6 and a7 are caller-saved like a0-a5 and could have been a0-a5 whenever those were free. This is the share an allocator could move, and the one LLVM's compressible-register allocation hints exist to shrink.
  • zero, ra, sp, gp and tp are fixed: sd zero,0(a0) has no two-byte spelling because no three-bit field names x0.

Zcb's forms are counted on their own line, since the base figure has to hold on an rv64gc target where they do not exist; on an RVA23 target, add the two. The s0 line is the frame pointer's cost in this axis: ripgrep addresses 61,779 locals through s0 and 61,740 of them sit below it, where the unsigned compressed offset cannot reach, while the sp-based forms take any register and reach 504 bytes. That is the compression side of the frame-pointer cost the redundant stack-pointer restore check reports.

The total is what register numbering cost, not what a better allocation would save: most registers outside x8-x15 are in use because the eight were occupied. It is 3.5% of ripgrep's code bytes and 5.6% of libmozsqlite3's, against the 2.2-2.9% x86lint measures for REX bytes. Offsets are the other axis -- past 248 a load costs the same two bytes, and a probe over ripgrep's disassembly counts 33,409 ld kept wide by their offset against the 23,491 kept wide by a register -- and that one is the audit TODO.md sketches rather than this census's. Relocated sites are counted as the bytes stand, which the compressibility checks exclude, so the two can disagree by that much. With -v the census prints up to four sample addresses per form.

Macro-op fusion (-u, --fusion)

riscvlint -u replaces the lint scan with a fusion report: the adjacent instruction pairs a fusing core would issue as one operation, and the pairs that would fuse after one small rewrite. Fusion is a property of a core rather than of the ISA, so the report has one block per core. The cores and pairs come from LLVM, not from memory or from the papers: llvm/lib/Target/RISCV/RISCVMacroFusion.td defines each pair as a predicate on two instructions, and RISCVProcessors.td says which processors enable which. Three families enable any:

core pairs
spacemit-x100 and/or/xor + and/or/xor, + andi/ori/xori, andi/ori/xori + and/or/xor; mul+add; add+load/store; slli+srli/srai (LLVM b10d6a501e0, from SpacemiT)
sifive-p450 to p870 a branch over one c.mv; lui+addi; auipc+addi
xiangshan-nanhu, -kunminghu slli 32+srli 32, slli 32+srli <32, slli 48+srli 48

GCC's riscv-fusion.cc has a similar list but enables less of it. Its spacemit-x100 tuning fuses nothing. LLVM also defines some pairs that no in-tree processor enables: Ventana's add+load family, and Qualcomm's RV32 Xqci pairs. Those are left out, because a count that no core realizes is not a fact about the binary.

The register rule is where an eyeballed pair goes wrong. Every pair except add+load/store is a SimpleFusion: the second instruction reads the first one's destination as its first operand and writes it back, so the fused operation writes one register. slli t0,a0,32 + srli a1,t0,32 computes the same thing as the fusible spelling and does not fuse. add+load/store asks the opposite of its add, a destination that is neither source, and asks the access for offset 0 from that destination. Pairs are taken greedily in address order, as a decoder takes them: an instruction already fused with the one before it cannot also fuse with the one after it.

Three kinds of near miss are counted next to the fused pairs. Each one is a single rewrite away from fusing:

  • split: the pair meets its predicate, but up to seven instructions sit between its halves. None of them is a branch target or a transfer, and either the first half can move down or the second half can move up past all of them without changing what any of them reads or writes. A scheduler that knew about the pair would have made it adjacent.
  • rename: the pair is adjacent and dependent and fails only the same-destination rule, and the liveness walk proves the first destination dead after the second instruction.
  • swap: the second instruction commutes and reads the first one's result as its second operand.
$ ./riscvlint -u out/rv/d8
Fusion report of out/rv/d8: 8477352 instructions
  spacemit-x100: 13557 pairs fuse, 0.2% fewer macro-ops; near misses 8047 split, 1570 rename, 111 swap
    pair                      fused      split     rename       swap
    logic + logic              2964       4575        168         67
    logic + logic imm           556         78         49          -
    logic imm + logic           278        325         16         44
    mul + add                   578        440         41          0
    add + load/store           4383       1691          -          -
    slli + srli/srai           4798        938       1296          -
  sifive-p450/p470/p550/p670/p870: 51101 pairs fuse, 0.6% fewer macro-ops; ...

What the X100 does on the bench

LLVM's tables say what the vendor told the compiler, not what the silicon does. The X100 is the core in the SpacemiT K3, and a K3 (marchid 0x8000000058000002, mimpid 0x33d8a600, the IDs LLVM's spacemit-x100 entry carries) ran each pair two ways. In a latency test, a repeated pair forms a dependency chain. In a throughput test, eight chains are interleaved. Each pair was timed against a control with the same dependency shape that breaks the fusion predicate, usually by giving the second instruction its own destination. Figures are cycles per pair from perf stat, minimum of three, and tools/fusion_bench.py reproduces them on any riscv64 host:

pair fusible control
and+or latency 1.01 2.03 fuses; the same for every logic pair, compressed or not
and+or throughput 0.52 0.69 3.9 instructions per cycle against 3.0
and a0,a0,a1 + or a0,a2,a0 (commuted) 1.52 2.03 partial
and a0,a1,a0 + or a0,a2,a0 (commuted) 2.03 2.03 no gain
mul+add latency 3.01 4.01 fuses, mulw+addw too; mul+addw does not
mul a0,a0,a1 + add a0,a2,a0 4.01 4.01 the commuted add does not fuse
add t0,a1,a0 + ld a0,0(t0) 3.01 4.01 the add costs nothing
add t0,a0,a1 + ld a0,0(t0) 7.01 4.01 fused and three cycles slower
slli+srli latency, any amounts 2.03 2.03 no measurable effect
slli+srli throughput, also mixed with loads or nops 0.69 0.69 no measurable effect
add+sd 0 throughput 1.02 1.02 no measurable effect

So the report departs from LLVM in one place. LLVM marks the logic pairs commutable and counts their commuted spelling as fused. On the X100 that spelling is reported as a swap, because swapping the operands is free and runs faster. The add+load row matters for pointer-chasing code. The fused pair reaches the loaded value three cycles sooner than unfused code through the add's second operand, and three cycles later through its first. A static report cannot tell which operand arrives late, so it counts the pair as fused and says so here. The shift pairs and stores are counted because LLVM says they fuse. Nothing above could tell what fusing them buys, if anything: perhaps physical registers or ROB entries, which these tests do not exhaust.

Results

Static counts, with "fewer macro-ops" the fused pairs as a share of the instructions:

binary instructions x100 fused x100 near misses sifive-p fused xiangshan fused
V8 JetStream JIT dump (34 parts) 37,896,111 105,122 (0.28%) 6,627 867,832 (2.29%) 2,517
d8, clang 21, RVA23 8,477,352 13,557 (0.16%) 9,728 51,101 (0.60%) 52
libLLVM.so.21.1, Bianbu 17,193,468 33,445 (0.19%) 21,743 91,625 (0.53%) 4
python3.14, GCC 15, RVA23 984,085 1,271 (0.13%) 1,396 8,953 (0.91%) 0
libc.so.6, GCC 15, RVA23 318,238 648 (0.20%) 570 6,200 (1.95%) 0

The X100's pairs are rare in all of them. Under 0.3% of the instructions would go away, and the two pairs that measurably help, logic+logic and mul+add, are under 0.1% everywhere. In the V8 dump, 79,847 of the 105,122 are add+load, and 75,166 of those are irregexp's current-character load, add s3,s6,s4; lbu s5,0(s3). The position, which changes every iteration, is the add's second operand, which is the fast case in the table above. 4,926 more are add+store, and 19,735 are slli 61+srli 61, a DecodeField of the OSR urgency bits. 4,557 of the dump's 5,786 split logic pairs are V8's overflow check sub t5,s1,t3; xor t2,s1,t5; xor t3,s1,t3; and t2,t2,t3. Swapping the two xors would make the pair fuse. SiFive's pairs are the common ones, because V8 loads every constant as lui+addi(w), which is 836,602 adjacent pairs. XiangShan's three are the shift spellings of zext.w and zext.h, and an RVA23 build spells those with Zba and Zbb instead.

The report (-v, --verbose)

By default riscvlint prints only the summary: the opportunities grouped by type and sorted by prevalence, then a total and the instruction count. A large binary has hundreds of thousands of them -- libxul alone has 567,706 -- so the per-opportunity detail is suppressed unless asked for:

$ ./riscvlint corpus/rust/ripgrep--rg
Optimization opportunities by type:
   31420  call pair foldable to jal
    5200  redundant stack-pointer restore
     604  computation a live register already holds
     259  transfer to the instruction that follows it
     179  instruction compressible to a base C form
     ...
       1  dead store to a frame slot

38295 optimization opportunities in 819303 instructions

Pass -v to print each opportunity ahead of that summary -- its one-line rewrite plus the instructions it covers, disassembled fresh from the file so the report shows exactly what is in it:

$ ./riscvlint -v corpus/rust/ripgrep--rg
instruction compressible to a base C form at offset: 0x6da7c: -> c.jr (4 -> 2 bytes) (1 instructions)
  jr t3

call pair foldable to jal at offset: 0x6e382: -> jal ra, 0xf2e72 (2 instructions)
  auipc ra, 0x85
  jalr -0x510(ra)
...

The <...> names the containing function, from the ELF symbol table where there is one and from Go's own function table otherwise -- see Attribution. A Debian C++ or Rust binary has neither and prints the unannotated form.

This is armlint's and x86lint's polarity, and riscvlint had the opposite one until it was flipped: every finding printed unless -q said otherwise, which made a bare invocation on a real binary unusable and the flag a thing you had to know. -q (--quiet) still asks for what is now the default and is still accepted, silently, so the corpus-scale invocations that passed it keep working -- and those are the last place to add a line of noise. -v is also what adds the sample addresses to the -i census, which is that report's own per-finding detail.

Every fixture under fixtures/ passes -v, since what they snapshot is the per-finding text; make driver-test is what covers the default.

--json

riscvlint --json replaces the human report with the findings as a document, one per input file, keyed by absolute address:

$ ./riscvlint --json corpus/rust/ripgrep--rg
{"file": "corpus/rust/ripgrep--rg", "arch": "rv64i2p1_m2p0_a2p1_...", "extensions": "declared",
  "findings": [
    {"vaddr": 451458, "check": "call pair foldable to jal", "detail": "jal ra, 0xf2e72", "section": ".text", "text": ["auipc ra, 0x85", "jalr -0x510(ra)"], "length": 8, "bytes": "97500800e78000af"},
    ...
  ],
  "instructions": 819303, "skipped": 0, "opportunities": 38295}

vaddr is the finding's absolute address, and a number rather than a hex string so that it composes with arithmetic. That is the point of the mode: findings become joinable against anything else keyed by address, and the join worth making is an execution profile. How often a compiler emits a suboptimal encoding is a poor proxy for what it costs -- one inside a hot loop outweighs thousands in cold initialization code, and only a profile tells the two apart.

It is x86lint's and armlint's shape, with the differences RISC-V forces. A finding spans a window of whole instructions, so text is an array of its disassembled lines rather than one string, and length is a sum of 2- and 4-byte encodings rather than a multiple of four. bytes is the window's encoding, and is omitted rather than truncated for a finding longer than 256 bytes -- a run of zero stores has no fixed bound, and a consumer must never read a short encoding as the whole finding; length stays exact either way. function and function_offset appear when the object kept a symbol table to attribute against, which a Debian binary has not.

Two fields armlint has no counterpart for. arch is the object's Tag_RISCV_arch string, or null where it declares none, and extensions is how the gate was decided -- declared, forced (-m was given), or unrestricted (no attributes and no -m). These carry what the human report's note: lines say, and a gated finding means nothing without them: a Zcb finding against an object that declares no Zcb is the answer to "what would rebuilding buy me", not a defect.

An audit finding (-a) carries four more: audit (imm or const), class (the consumer class as the by-value tables name it), width (the table's letter) and value, the constant as the consumer read it, a number like vaddr. The by-value tables can be rebuilt from them, or joined against a profile, which is what a constant's cost needs.

Findings are written as they are found rather than collected first, so libxul's 567,706 stream instead of accumulating in memory; the totals close the document because the scan only knows them then. Section and symbol names are copied from the file verbatim, so a binary whose string tables are not UTF-8 yields strings that are not either. Several files give several documents in argument order, each reporting its own file's share, which is a stream of JSON values rather than one -- jq reads it unadorned, json.JSONDecoder().raw_decode in a loop in Python. A file the driver rejects leaves stdout empty rather than half a document, and the exit status is unchanged by the mode.

-i, -r, -u and -v are separate reports whose output would interleave with the document, so those combinations are refused rather than chosen for the caller. -q asks for what --json already does and is accepted, so a script that passed it still gets a document.

The library side is what the mode is built on:

typedef void (*riscvlint_finding_fn)(void *ctx, const riscvlint_finding *f);

size_t riscvlint_scan(riscvlint_state *state, csh handle,
                      const uint8_t *code, size_t len, uint64_t vaddr,
                      riscvlint_finding_fn on_finding, void *ctx,
                      uint64_t *instructions, uint64_t *skipped);

riscvlint_scan runs every check over a prepared state, in the order the checks need -- each judges its instruction against the window as it stood before it -- and calls back once per finding. Where a by-type tally answers "how many of each kind", the callback answers "which instructions, at what address". A compiler test suite can assert the return value is zero over a function it just emitted; *skipped reports the bytes stepped over without linting, so an incomplete sweep is not mistaken for a clean one.

Attribution

A finding is worth more with a function name on it than without, and which name is available depends entirely on what the toolchain left behind. It buys two things: the <name+0x..> on each -v line, and the by-function block in the summary, which is what turns a whole-binary count into "and here is where to start":

$ ./riscvlint corpus/go/golang-1.26-go--gofmt
Optimization opportunities by type:
   ...
Optimization opportunities by function:
     229  go/ast.Walk
     164  go/parser.(*resolver).Visit
     114  time.parse
      98  fmt.(*pp).printValue
      94  internal/fmtsort.compare
      94  runtime.selectgo
     ...
   22205  in 3124 more functions

The ten holding the most, the tail summed into a residue line, and -- where there are any -- an outside every function range row for the findings no name covers: code before a section's first symbol, past the end of a sized one, or past the end of what Go's table describes. Counted apart rather than charged to the nearest neighbour, which would be a guess dressed as a fact. It is tallied at the finding sink with the same lookup the annotation uses, in every mode and not only under -v, so the two cannot disagree about where a finding is. An object with nothing to attribute against leaves the block out rather than printing one row saying so.

Two sources are tried, in this order:

  • the ELF symbol table's STT_FUNC entries, bounded by st_size where the symbol carries one. This is what a locally built object has, and it is the case that matters for a compiler test suite;
  • Go's .gopclntab, the runtime's own function table. It survives strip, because traceback needs it, and it is the only thing a Go binary offers: golang-1.26-go--compile has zero STT_FUNC symbols and no corpus object has a .symtab at all. With it, every one of the Go cohort's 3,066,703 findings is named -- 12 of the corpus's 29 objects, and its largest population by a wide margin.

The layout parsed is runtime.pcHeader (runtime/symtab.go) plus two of the regions its offsets name: the functab, an array of nfunc+1 {uint32 entryoff, uint32 funcoff} pairs sorted by entryoff, and funcnametab, which the _func record at each funcoff indexes with its second field. Magic 0xfffffff0 (Go 1.18, 1.19) and 0xfffffff1 (Go 1.20 and later) share that layout; an older binary is refused rather than misread.

Two things it has to get right that reading the struct does not give you.

The text base is not in the header. pcHeader.textStart is what entryoff is nominally relative to, and in this corpus it is zero in gofmt and compile and correct in gh -- so trusting it would put every function in two thirds of the Go objects at the bottom of the address space. The base is instead tried from the header and then from the .text section address, and whichever the whole table validates against is the one used. entryoff 0 is the first function either way.

Validation is all-or-nothing. Every entry is walked once before the table is believed: the entryoffs must be sorted, since the runtime binary-searches them; every funcoff must address a record inside the region; every name must be NUL-terminated inside funcnametab; and the whole covered text range must fall inside one executable section, which is what catches a wrong base. A table that fails any of these is dropped whole and the findings print unannotated, because a wrong function name on every finding in a file is worse than no name -- being trusted is the entire value of the annotation. make gopclntab-test covers a mutant per field, each of which must cost the names and leave the scan untouched.

One RISC-V-specific wrinkle. Go's riscv64 linker emits a $x<arch string> functab entry beside each cgo function -- the ISA mapping symbol, sharing the function's address and sorting after it: 12 of gh's 32,233 entries and 12 of restic's, none in a pure-Go binary. A lookup that takes the last entry at an address would name findings after those, so it steps back off them to the function they mark.

Not done: finding the header by scanning the data sections, which is what a binary whose section names were stripped would need. Every Go object here names .gopclntab, so that is a measurement away rather than written on spec. Nor is .dynsym consulted as a fallback for the C++ and Rust half -- Debian keeps only exports there, 43,176 of them in libLLVM covering 16.9 MB of a 51.9 MB .text, so it would name about a third of the findings and leave the rest looking like they belong to whichever export preceded them.

Constant chains (-c, --constants)

riscvlint -c adds a second report to the scan: every constant the code materializes, tallied by value and ranked by the instructions it costs. armlint's -c with the axis RISC-V forces -- there a chain is movz/movn plus movks and its length is the value's width in halfwords, here it is whatever RISCVMatInt chose, so "how much does this constant cost" has an answer per value rather than per width.

A chain is an instruction that builds a value out of x0 and an immediate -- li, lui, c.li, c.lui -- followed by however many addi/addiw/slli steps read only its own result. That is what RISCVMatInt emits and what GNU as emits for li. A branch into the middle ends it, since the instructions after the target are then reached without the ones before.

The steps need not be adjacent. One chain is tracked per register and it ends when its value is consumed -- the first instruction to read the register closes it, so a later addi on the same register begins a new chain rather than extending a finished one. A step may also write a register other than the one it reads, because the allocator puts the finished constant elsewhere whenever the partial value is still live.

That costs something and buys more. The cost: instructions shared between a value and a value derived from it are counted under each. The purchase, measured against an oracle that needs no chain recognizer at all -- lui rd,imm20 is one word per rd, so the encoding can simply be counted -- is that the census now agrees with it to within 1.3% on the four SWAR popcount masks, across libxul and both libllvm22 builds. An adjacency rule put libxul's 0x0f0f0f0f at 27 against a true 3,972, because of sequences like this one at 0x3267b2a:

lui  a1,0x55555      four luis together, so an adjacency rule closes
lui  a2,0x33333      each after one instruction at 0x55555000 and
lui  a3,0xf0f1       friends, and bins all four as untallied
lui  a4,0x1010       one-instruction values
srai s0,s6,0x3f      unrelated work in the middle
addi s1,a1,1365      a1's chain completes into *s1*, not a1
addi a2,a2,819       this one completes in place

Composition through a register-register add or or is followed too, which is how RISCVMatInt joins the halves of a 64-bit value. There is no ambiguity about what that does -- the sum or union of two known constants is a constant whatever else is true -- so both sources are closed without being counted and their instructions are charged to the value they were built for, taking the larger rather than the sum where the two halves grew from the same root. That is what makes a 64-bit constant visible as itself: libxul's 2,867 0x5555555555555555 chains used to report as 0x5555555500000000, the shifted half.

Still not followed: anything else that combines two known values -- sub, xor, and, a shift by a register. Those barely appear in RISCVMatInt's output, and each one added is another chance to absorb an instruction that was using a constant rather than building one.

$ ./riscvlint -c -q corpus/cpp/firefox-esr--libxul.so
Constant chains in corpus/cpp/firefox-esr--libxul.so: 2697870 materializations, 3171535 instructions
  one instruction: 2318741
  two or more: 379129 chains, 852794 instructions, 29031 distinct values
    of which addresses: 13611 chains, 27236 instructions
    of which constants: 365518 chains, 825558 instructions
  costliest values:
       56386 insns  0x8000000000000000 (-9223372036854775808) 27952 chains
       37256 insns  0xfff9800000000000 (-1829587348619264) 18628 chains
       27476 insns  0xfffe000000000000 (-562949953421312) 13738 chains
       24970 insns  0x2000100000000 (562954248388608) 12485 chains
       23946 insns  0x8000000000000001 (-9223372036854775807) 7973 chains
       20796 insns  0x101010101010101 (72340172838076673) 5199 chains
       ...
  rebuilt inside one function: not counted, nothing named the functions
```Read off that one run: the sign bit 18,757 times, then four values of
the form `0xfff?800000000000`, which are SpiderMonkey's NaN-boxed JSVal
tags -- 30,000 materializations of a handful of type tags -- and
further down `0xffffffff80004005`, which is `NS_ERROR_FAILURE`, 2,569
times. libLLVM's list is led by `0xaaaaaaab` 1,346 times and
`0xcccccccd` 425: the divide-by-3 and divide-by-5 magic numbers, one
chain per inlined division.

Three things the report does that a by-value tally alone would not.

**Single-instruction values are counted and not tallied.** `li a0,0`
has no cheaper spelling, and libxul materializes something in one
instruction 2,318,741 times, so ranking those by cost would make the
report a list of "build zero". The totals keep them; the ranked list
starts at two.

**Addresses are told from literals.** In a linked object `lui`+`addi`
of a symbol's `%hi`/`%lo` is indistinguishable from arithmetic on a
literal, and conflating them buries the constants: libxul reports
13,611 address chains against 365,518 constant ones, where the naive
test -- any allocated section -- put a large part of the second column
in the first. Two
conditions, both principled. The value must land in a section holding
*program* data -- `SHT_PROGBITS` or `SHT_NOBITS`, not the linker's own
tables, which in a shared object are everything at the low addresses a
small literal collides with (libLLVM's first `PROGBITS` section is at
0xe5ef80 and the nine below it are notes, symbol and version tables,
hashes, strings and relocations, which is why `0xffff` and `0xc00` used
to read as addresses). And the chain must be exactly two instructions,
since `lui` sets bits 31:12 and the `addi` the low twelve: the
`%hi`/`%lo` idiom is two and anything longer is arithmetic. What
remains is irreducible -- libLLVM builds `0x7ffffff` 696 times, which
is 2^27-1 and a mask, and it falls inside a loaded section anyway.
Nothing in the bytes tells the two apart once the linker has consumed
the relocation that did.

**Rebuilds are reported per function.** A value its own function
already built is the difference between a constant that is expensive
and one that is expensive repeatedly: `golang-1.26-go--compile` rebuilds
`0x15c5` 458 times out of 730 builds. This needs function boundaries,
so it reads them from the same place the annotation does -- and says
`not counted, nothing named the functions` rather than `none` on an
object that has no symbols, which is every C++ and Rust binary here.
Note what a rebuild is not: it is not necessarily a miss. Telling those
apart needs dominance and liveness, which this does not have.

`-v` adds up to four sample addresses per value, which is what checking
one in a disassembler takes. `--json` describes the lint scan alone, so
the combination is refused.

## Exit status

The grep convention, so riscvlint can gate a test suite and CI can tell
a dirty scan from a broken run:

* **0** -- a clean scan, no opportunities found;
* **1** -- at least one opportunity found;
* **2** -- a tool failure: a bad invocation, an unknown `-m` name, an
  unreadable or malformed file, an allocation failure.

A tool failure outranks a dirty scan, so a run over five binaries one of
which could not be read exits 2 whatever the other four reported: what
they found is not the answer to the question that was asked. The `-i`
census is a description of the file rather than a verdict on it and so
never returns 1 -- nothing in it is a finding -- but a file it could not
read is still a 2. The `-r` register census and the `-u` fusion report
are the same.

An `-a` audit's findings count toward the total like any other, so a
run that passes it exits 1 whenever the audit found anything to review;
a suite that gates on a clean run should not pass it.

`make driver-test` covers all three; the snapshot suite cannot, because
it compares stdout and discards the status.

## Building

Requires Capstone 6. Capstone 5.0.x decodes RISC-V too thinly to be
useful here -- it lacks the extension mode flags that let a disassembler
see Zba/Zbb/Zbs and the vector encodings a current distro binary
contains, and 5.0.6 is what most systems still ship.

```sh
git clone https://github.com/capstone-engine/capstone   # branch: next
cd capstone && cmake -B build -G Ninja \
    -DCMAKE_BUILD_TYPE=Release \
    -DCAPSTONE_ARCHITECTURE_DEFAULT=OFF -DCAPSTONE_RISCV_SUPPORT=ON \
    -DBUILD_SHARED_LIBS=OFF -DCMAKE_INSTALL_PREFIX=$PWD/install
ninja -C build && ninja -C build install

Then make, or make CAPSTONE_PREFIX=/path/to/install. The link is static on purpose: with a shared link the system's Capstone 5 wins at run time and reports subtly wrong output rather than failing.

make test runs the unit suite, make integration-test the snapshot fixtures under fixtures/, make driver-test the driver's exit statuses and verbosity default, make json-test the --json document, make gopclntab-test the Go function-table parser, and make tools the mining utilities. scripts/check_table.py regenerates the per-check table above from a corpus scan, and --check makes it say whether the committed one is stale. Every shell suite exits 2 rather than 0 when it cannot find a clang that targets riscv64 -- and, for the linked fixtures, an lld that can link it -- so a missing toolchain cannot pass by testing nothing.

CI (.github/workflows/ci.yml) runs those suites on x86-64 and arm64 Ubuntu and in a Fedora container, and the decoder sweep below, none of which needs RISC-V hardware. tools/rwfuzz does, and GitHub hosts no RISC-V runners, so CI cross-builds it and runs make rwfuzz-test under qemu-user:

make CC=riscv64-linux-gnu-gcc AR=riscv64-linux-gnu-ar \
    CAPSTONE_PREFIX=/path/to/riscv64/install tools/rwfuzz
QEMU_LD_PREFIX=/usr/riscv64-linux-gnu \
    RWFUZZ_EXEC="qemu-riscv64 -cpu max" make rwfuzz-test

scripts/build_capstone.sh builds the pinned Capstone as the start of this section does, for the host or, given cmake cross arguments, riscv64.

The exhaustive decoder sweep

riscvlint's checks decode raw encodings; capstone decodes the same bytes from LLVM's tables. Where the two disagree one of them is wrong, and on the properties below it is riscvlint that would be wrong in a way that costs a user something -- check_dead_def deletes an instruction on rv_pure_def's word, so a "pure def" that is not pure is a deleted side effect.

Unlike armlint there is no liveness classifier to sweep: riscvlint_liveness reads cs_regs_access directly, with two documented corrections. What is riscvlint's own is the raw decoding, and the sweep checks three claims against capstone over every encoding there is:

  • rv_insn_len must agree about how long an instruction is. A skew here desynchronizes every scan.
  • rv_pure_def claims the instruction's only effect is writing rd. Capstone must report no other register written, no memory operand, and no control transfer. Capstone reporting no write at all is its own under-reporting, counted rather than failed, because riscvlint corrects for that elsewhere.
  • rv_decode_mem says an instruction touches memory. Capstone must agree there is a memory operand.

The compressed half runs in every make test: 2^16 words, milliseconds, and it is where the implicit operands are -- c.jalr writes ra, c.addi4spn reads sp -- which is where a hand decode goes wrong. The four-byte half is opt-in, since it is 2^30 decodes:

RISCVLINT_SWEEP=1 RISCVLINT_SWEEP_THREADS="$(nproc)" make test

384,410,780 four-byte encodings decode, 96,507,712 of them claimed as pure definitions, and all three properties hold on every one. 24 seconds of wall time across 16 workers. That is the argument for rv_pure_def being written as a rule over whole opcode spaces rather than a list of mnemonics: the rule is checkable, and checked.

The compressibility audit

check_c_compressible and check_zcb_compressible are between them 59% of the corpus's findings, and both rest on one judgement: would the assembler have spelled this four-byte instruction in two? riscvlint answers from a hand decode. LLVM answers from its CompressPat records, which is what its assembler actually applies -- so those are the oracle, and tools/tblgen_audit.py diffs the two:

make tools && tools/tblgen_audit.py --llvm ~/work/llvm-project
LLVM CompressPat records: 147, naming 57 compressed forms
riscvlint names 48 forms over the whole four-byte space

rules riscvlint declines on purpose:
  c.nop          riscvlint does not report `nop` at all; see TODO.md
  c.sspopchk     Zicfiss, which RISCVLINT_CS_MODE does not enable
  c.sspush       Zicfiss, which RISCVLINT_CS_MODE does not enable
  c.unimp        a trap, with no cheaper spelling to suggest

rv32-only rules, not a gap for an rv64 tool: c.flw c.flwsp c.fsw c.fswsp c.jal

Every rule LLVM has for rv64, riscvlint models; every form riscvlint names, LLVM has a rule for.

48 modelled, 5 rv32-only, 4 declined: the accounting is exact, and a rule that stops being declined has to be fixed or moved rather than quietly dropped. The two directions fail differently -- a form LLVM can produce that riscvlint never names is a finding quietly missing, which no corpus run reveals because the shape simply never reports; a form riscvlint names that LLVM has no rule for is advice that will not assemble, which is worse.

riscvlint's side is enumerated by tools/tblgen_probe, which asks rv_c_form and rv_zcb_form about all 2^30 four-byte words in two seconds. Reading the source would not do: the claims live in C control flow, not in a table.

It earned its keep on the first run. c.not came back as a form riscvlint never names -- while TODO.md records c.not as most of the Zcb residue it actually reports on the corpus. The decoder was right and the probe was wrong: the exclusive end of the four-byte space is 2^32, a uint32_t holds that as 0, and the last worker's range was therefore empty. A sixteenth of the space went unread while both the probe and the sweep reported a clean pass, and c.not's encodings all live at 0xfff4_4413 and up.

Mining tools

tools/ holds the research utilities that feed the check backlog. They are ports of armlint's, and the port is not mechanical: AArch64 instructions are 4 bytes, RISC-V mixes 2 and 4, so the branch-target bitsets are halfword-granular and filled by a Capstone pre-pass instead of hand-decoded branch immediates. RISC-V also has no condition flags, so the categories built around them have flagless replacements.

  • tools/pairscan counts adjacent-instruction pairs by normalized shape (registers collapsed to ABI classes, immediates to #0/#i) across the executable sections of riscv64 ELF files, surfacing frequent patterns worth a new check. -e SUBSTR prints example sites for shapes matching a substring.

    Two RISC-V-specific additions. Capstone prints c.mv as mv and c.addi as addi, so a :c suffix on the mnemonic marks a 2-byte encoding; without it the most RISC-V-specific question there is -- did this instruction take the compressed form it was entitled to? -- cannot be asked of the pair data at all. And -x keeps small immediates verbatim instead of collapsing them, which is the difference between an upper bound and a population: the collapsed counts overstate the foldable shift-add family by 2.4x and the collapsible call family by 26x.

    -1 counts single instructions by shape rather than pairs. A pair table cannot answer "how many instructions of shape X are there" -- each instruction appears in up to two pairs, and region boundaries drop some entirely -- and that census is what sizing missed compression needs.

  • tools/defuse profiles block-local def-to-use distances (how far a value's sole consumer sits from its producer) and the multi-instruction redundancies no pair statistic can see: dead definitions, redundant reloads of the same address, re-materialized constants, and -- replacing armlint's cmp #0 category, which has no meaning without flags -- conditions materialized into a GPR by slt/xor/sub and then tested with beqz/bnez, where one compare-branch would have done both.

  • tools/candscan sizes a candidate check by counting the shapes it would fire on with the check's own preconditions applied -- decoded operands, immediate ranges, encodability -- and running the same bounded liveness walk where a fold needs one. pairscan and defuse answer "is there something here?"; this answers "how many findings would the check report?", and the two have differed by an order of magnitude every time both were measured.

    Two splits it reports that a fold count alone would misstate. Sites with a conditional branch between the def and its use are counted apart (xbr), because the intermediate may escape on the taken path and no walk starting after the use can see it. And every probe whose verdict depends on a call or a return is run twice, once with the LP64D convention asserted, so a candidate can be told from one whose population only exists because the ABI-agnostic walk said UNKNOWN -- move coalescing turned out to be the latter, 73,017 shapes of which 69,611 come back live once the ABI is named.

    Probes that measured zero stay in the tool. A candidate rejected on evidence is worth as much as one accepted, and leaving the probe there is what stops the shape being re-derived from intuition later.

  • tools/tblgen_probe and tools/tblgen_audit.py are the compressibility audit, documented under Building: the probe enumerates every compressed form riscvlint's decoders will name, and the script diffs that against LLVM's CompressPat records. They and tools/rwfuzz are the tools here that check riscvlint against an oracle rather than measure a corpus, and the ones whose failure is a defect rather than a number.

  • tools/rwfuzz checks a check's advice by running it. It generates random riscv64 programs with the shapes a group of checks looks for planted in them, applies each rewrite riscvlint suggests to a copy, and runs original and rewrite natively from the same random registers and memory: any difference in the registers, the frame, the stack or the scratch buffer is a soundness bug. What it applies is the replacement text, through an assembler of its own, so a rendering that names the wrong register fails as surely as a proof that misses a write. A control arm applies the same kind of rewrite where riscvlint refused to, so a harness that stopped seeing differences would show it. Modes cover the redundant extension, dead definition, value reuse, memory window, constant, stack adjustment, floating-point, pair fold, control-flow and copy checks (tools/rwfuzz -n 100000 ext), the Zilx, Zibi and Zacas checks through base-ISA expansions of what they suggest, which the K3 cannot run, and self checks rwfuzz's own encoders; a new rewrite gets a mode, or a shape in one. It is armlint's tools/rwfuzz with a program made of slots rather than words, laid out again after each rewrite, since a RISC-V rewrite changes sizes as often as not. Needs a riscv64 host with Zba, Zbb and Zbs, or qemu-user, since the programs run natively, and links libriscvlint.a. make rwfuzz-test runs every mode.

  • tools/rank.py groups pairscan output into candidate-check families and prints each family's population, because raw frequency ranking puts the by-design majority (prologue stores, argument moves) on top and buries what a check could act on. Families that depend on an immediate are only honest against pairscan -x output; run against a plain file, rank.py says so rather than reporting the upper bound as a number.

  • tools/v8dump2elf.py turns a V8 code dump (d8 --print-opt-code --print-maglev-code --print-code --print-regexp-code on a build with v8_enable_disassembler=true) into ELF objects the checker can scan: one executable section per contiguous run of instructions, a symbol per section naming the tier and the function (TF_foo, ML_foo, BL_foo, RE_<pattern>, ...; a recompile gets .2, .3), and two sidecars, --map (section, size, JIT address) and --relocs (every object's RelocInfo entries by offset). V8 prints every instruction as an 8-digit word, a compressed one zero-extended, so the bytes are sliced by the encoding's own length bits and cross-checked against the next line's address. Constant pools and jump tables split the section rather than staying in it, since the checker has no mode that steps over them. Sections get unique synthetic addresses rather than their JIT addresses, because V8 frees code and reuses addresses: over a JetStream run a third of the objects share an address with an earlier one, and nothing keyed by address could tell them apart. --arch declares the host's ISA string (in the assembler's spelling, rv64i2p1_..._c2p0_zba1p0...) so the extension gate reads declared rather than unrestricted. The output is split into ELFs of 2,000 sections by default, which is the unit the runs divide into. The split was first needed because the checker attributed each finding by a linear scan of the symbol table; it now searches a sorted index, and the ELF limit of 65,535 sections is the only hard one.

    tools/v8_analyze_findings.py then joins riscvlint --json output for those ELFs with the two sidecars, attributing by symbol and offset rather than address: findings by check and tier, the share that repeat an earlier copy of the same function (a JIT recompiles after every deopt; copies are matched on name, code size, offset and bytes), the share containing a relocated instruction (toolchain-forced rather than a missed fold; deopt entries, which only annotate call return addresses, do not count), and samples per check. tools/v8_jetstream_dump.sh runs JetStream 3 under d8 with the printers on, and tools/v8_analyze.sh runs the whole chain over a dump. The run script leaves out the Wasm workloads: --print-code also prints every Wasm function from the background compile threads, which interleaves with and corrupts the JS listing, and bomb-workers, whose Worker isolates do the same to stdout. tools/v8_corpus_mine.py is the dump's pairscan: objdump over the converted parts, a set of shape detectors and an abstracted-trigram census per tier, in parallel across the parts. Its output is the JetStream section of TODO.md.

  • The tools/sm_* scripts do the same for SpiderMonkey, which has no code printer to read, so the shell writes the bytes out itself. tools/sm_code_dump.patch adds a JS_CODE_DUMP hook to a Firefox checkout: every JitCode the linker makes (Baseline, Ion, RegExp, and the trampolines and stubs of kind Other) and every Wasm code segment is appended raw to <prefix>.<pid>.bin. tools/sm_jetstream_dump.sh runs each JetStream 3 test in its own shell, natively on riscv64 or under --enable-simulator=riscv64 elsewhere; natively on a SpacemiT K3 the whole suite takes six minutes at four jobs. tools/smdump2elf.py makes one section per blob, named ION_, BL_, RE_, TR_ or WA_ plus the test and an index, since raw bytes carry no function name. The section never has to be split as V8's are: the riscv64 backend emits no compressed instructions and no constant pools, and its veneer pools are code. --dedupe-startup keeps one copy of the trampolines and Wasm builtin thunks that every process links first. tools/sm_analyze.sh runs the chain over a run directory: riscvlint per part, tools/sm_analyze_findings.py for the checks by tier, tools/sm_census.py for the words taken by the fixed-shape sequences the assembler emits whatever the operand (the six-instruction patchable li_ptr, the eight-instruction li_constant, the breakpoint code word, and auipc + jr veneers, with which veneer slots any branch still targets), and tools/sm_constants.py for what each patchable load holds and what reads it. tools/sm_context.py disassembles around sample findings and tools/sm_li_context.py around sample patchable loads of one tier and use. tools/sm_corpus_mine.py sized the five checks of entries 48 to 52 in TODO.md, before they were written, over the parts with one probe each, the way tools/v8_corpus_mine.py mines V8's. It reads each blob's name with readelf, since llvm-objdump labels every blob of a part <.text>.

The checks in riscvlint.c decode raw encodings rather than reading Capstone's operand model, and the reason is not stylistic. Capstone reports auipc's operand as the raw imm20 field rather than the sign-extended addend, so a range test written against it silently drops every backward call -- which is how the call family was first sized at 30,175 instead of 89,860. The mining tools do lean on that model, and correct it where they must: jal <imm> and jalr <rs> are the aliases of jal ra, <imm> and jalr ra, 0(<rs>) and report no write, and ret reports no read of ra. Left alone, a reloaded ra looks like a dead definition. This mirrors armlint's correction for the AArch64 compare aliases, and the lesson is the same: the mining tools lean on Capstone's model, and the checker itself should decode raw encodings.

Corpus

The figures in TODO.md come from 108,165,211 instructions of riscv64 code -- three toolchains, so a finding can be attributed to one rather than assumed universal:

language binaries source packages
C++ 13 libllvm22 (twice), libllvm20, libqt6core6t64, firefox-esr
Rust 6 ripgrep, fd-find, bat, hyperfine, rust-coreutils
Go 12 golang-1.26-go, gh, restic

Which distro a package comes from is the most important thing about it, and it is surveyed rather than assumed. Over the 100 most-installed packages of each (popcon order), unpacked and read:

riscv64 ELFs distinct Tag_RISCV_arch Zba/Zbb/Zbs/Zcb/Zfa/V
Ubuntu 26.10 (stonking) 407 1 all of them, in all 407
Debian sid 494 3 none, in any

So Ubuntu riscv64 is uniformly RVA23 and Debian riscv64 is uniformly rv64gc baseline, with no per-package variation on either side worth hunting for. Read every extension-gated figure in TODO.md with that in mind: a Zba result from an Ubuntu object is a compiler miss on a target that has the instructions, and the same check against a Debian object is a question about what rebuilding would buy.

The libllvm22 pair

libllvm22 is in the corpus twice, from both distros, at the same upstream release (22.1.8) and the same Debian packaging lineage:

instructions RVA22 RVA23
debian-libllvm22 17,409,506 none none
ubuntu-libllvm22 17,616,540 Zba 297,616, Zbb 56,930, Zbs 53,217 V 380,719, Zcb 166,673, Zicond 118,139, Zfa 381

It was added to be the control every "what would rebuilding for RVA23 buy me" figure lacks -- those are all predictions about an object nobody rebuilt. It is not a clean control, and the reason is worth more than the pair was. The two builds differ in compiler as well as in -march: Ubuntu's has 140,895 addi sp,s0,-K frame-pointer teardowns and Debian's has 1, which is the idiom TODO.md already attributes to clang against GCC. Both binaries are stripped of .comment, so that inference is from codegen rather than from a producer string, but a 140,000-to-1 ratio in one idiom is not a -march effect.

So read the pair as two baseline-versus-RVA23 builds of the same source, not as one variable changed. What it establishes anyway:

  • riscvlint predicts 174,980 Zcb-compressible instructions in the baseline build under -m rva23; the RVA23 build of the same release contains 166,673 actual Zcb instructions. Within 5%, across two compilers -- suggestive, and confounded, and the first time any such prediction has been held against a real rebuild at all;
  • the Zba checks predict 39,460 (21,627 shift-add plus 17,833 zext.w) against 297,616 Zba instructions realized, which is the honest shape of a subset predictor: riscvlint checks two Zba idioms and the compiler uses add.uw, slli.uw and the sh*add.uw family besides;
  • and it overturned a rejection this project had already recorded, by exposing a 147-fold undercount in the -c census rather than by disagreeing with libxul. TODO.md's popcount entry has it.

libxul.so remains the other baseline C++ member, and at 35,581,433 instructions it is still the largest single object from one source. It was never the problem, though -- the lesson the pair taught is about the tool, not the corpus. A check about counting bits measured 27 sites against libxul and looked dead; the real figure is 3,972, and the -c census had undercounted it 147-fold because LLVM's scheduler splits the lui from its addi. A second object is what made that visible.

corpus/ is not checked in. Fetch it with tools/fetch_corpus.py, then:

make
./tools/pairscan -x corpus/*/* > results/pairsx-all.txt
./tools/defuse       corpus/*/* > results/defuse-all.txt
python3 tools/rank.py results/pairsx-all.txt

References

About

Examine RISC-V machine code to find suboptimal instruction sequences

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages