You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Real benchmark zero-hit cases are retained. li is treated as a pseudo-instruction, so source assembly reductions are not presented as machine-code or runtime wins. Machine instruction count, .text size, and execution equality remain N/A when a RISC-V toolchain is unavailable.
Validation
pytest -q: 430 passed, 4 skipped, 0 failed
4 skips require optional onnxruntime
10,000 randomized RV32 programs passed semantic-equivalence, textual-idempotence, and change-count invariants
compileall: passed
git diff --check: passed
Known environment limitation
The current environment does not provide GNU RISC-V binutils or Spike, so the documented three-sample external toolchain execution check is still pending and is not represented as completed.
🔴 Missing import: Optional — BenchResult uses Optional[int] and Optional[bool] on lines 61–67 but Optional is not imported. Add from typing import Optional at the top.
🔴 asm_line_count now counts optimized asm — Line 199 overwrites asm_str with the merged output, then result.asm_line_count = len(asm_str.splitlines()) on line 246 records the optimized line count. This breaks the metric’s original meaning (codegen output size) and makes RISC-V results incomparable with other backends. Keep the original line count or add a separate field.
🟡 Inconsistent import placement — merge_constants_detailed is imported inside run_benchmark (line 202). Move to the top of the file unless there’s a circular‑import reason. It’s a minor style issue but harms readability.
🟡 Unused fields in BenchResult — machine_instructions_before/after, code_size_before/after, and output_equal are never assigned (always None). Remove them or add a comment explaining they are reserved for future toolchain integration.
💭 Column header RedLUI is ambiguous — The table prints RedLUI for redundant_lui_removed. Consider Redund.LUI or RedLUI seems fine, but be consistent with the field name for clarity.
💭 print_summary hardcodes “N/A without toolchain” — The message at line 310 is fine, but consider printing the actual values if they ever become non‑None (e.g., if r.machine_instructions_before is not None: ...).
🔴 Bug: 冗余 LUI 删除中,立即数解析失败的 LUI 未清除寄存器状态
当 _parse_lui_imm(inst.operands[1]) 返回 None 时,代码仅 result.append(inst) 并 continue,未更新 lui_state。这导致该 LUI 写入的寄存器仍保留之前的已知值,后续相同寄存器的 LUI 可能被错误删除。例如:
lui x5, 0x100000 # 无效立即数,但实际写入 x5
lui x5, 0x12345 # 由于 state 仍为旧值,此条可能被误删
💭 合成的 li 指令丢失原始行号上下文
合并后的 ParsedAsmLine 使用了 lui.lineno,但后续的中间注释行(insts[i+1:j])保留了它们自己的行号。如果调试或反汇编依赖行号映射,可能产生偏差。不过对于纯优化场景影响较小。
📁 scratchv/compiler.py
🟡 Potential AttributeError if merge_constants_detailed returns None — Line 454: stats = merge_constants_detailed(asm_text) then stats.total_changes. If the function can return None (e.g., on error), accessing .total_changes will crash. Consider adding a guard or ensuring the function always returns a valid stats object.
🟡 Missing type hint for stats — The returned object's shape is implicit. Adding a typed NamedTuple or dataclass for stats would improve clarity and catch attribute errors early.
💭 F-string cross‑line formatting — The warning message spans multiple lines inside parentheses. Consider using implicit string concatenation (e.g., f"Const merge: {stats.total_changes} changes " f"({stats.merged_pairs} pairs, " f"{stats.redundant_lui_removed} redundant lui)") to avoid the extra indentation and make it easier to read.
The reason will be displayed to describe this comment to others. Learn more.
确认这里的改动是什么需求还是bug引起的
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
lui+addipairs and remove redundantluionly within basic blocksStatistics semantics
candidate_pairs: structural same-blocklui/addicandidates before safety checksmerged_pairs: candidates that pass register and immediate validation and are transformedredundant_lui_removed: safely removed duplicate high-immediate loadsReal benchmark zero-hit cases are retained.
liis treated as a pseudo-instruction, so source assembly reductions are not presented as machine-code or runtime wins. Machine instruction count,.textsize, and execution equality remainN/Awhen a RISC-V toolchain is unavailable.Validation
pytest -q: 430 passed, 4 skipped, 0 failedonnxruntimecompileall: passedgit diff --check: passedKnown environment limitation
The current environment does not provide GNU RISC-V binutils or Spike, so the documented three-sample external toolchain execution check is still pending and is not represented as completed.