feat: add reduced-width memory load/store words#54
Conversation
tetsuo-cpp
left a comment
There was a problem hiding this comment.
Code Review: Add reduced-width memory load/store words
Overview
Adds 24 new Forth operations for reduced-width memory access across 6 types (i8, i16, i32, f16, bf16, f32) × load/store × global/shared. The implementation cleanly generalizes the existing MemoryLoadOpConversion/MemoryStoreOpConversion templates by replacing the bool IsFloat parameter with a MemType enum, then instantiates all 24 variants as type aliases. Well-structured change with good test coverage at all three layers.
Issues
Summary/description mismatch in ODS definitions (bug)
All six integer load op summaries say "zero-extend" but the descriptions say "sign-extends" and the implementation uses arith::ExtSIOp (sign-extend). The summaries need to say "sign-extend" to match:
Forth_LoadI8Op:"Load i8 value from memory, zero-extend to i64"→ should be "sign-extend"Forth_SharedLoadI8Op: sameForth_LoadI16Op: sameForth_SharedLoadI16Op: sameForth_LoadI32Op: sameForth_SharedLoadI32Op: same
The descriptions within the [{ }] blocks are correct — only the let summary strings are wrong.
Suggestions
-
Conversion test coverage:
test/Conversion/ForthToMemRef/reduced-width-memory.mlironly tests shared memory for i8. Since the template is identical, this is low-risk, but adding even one shared-memory check for a float type (e.g.shared_load_f16with!llvm.ptr<3>) would catch any future AddressSpace regression without much cost. -
Pipeline test: Similarly only tests a subset (I8, I32, HF, F32) — covers both reduced-int and reduced-float code paths, which is sufficient. Could optionally add I16 or BF16 to be thorough, but not strictly necessary.
Positive Notes
- Template generalization is clean: The
MemTypeenum +isReducedInt/isReducedFloatconstexpr helpers +getMemElemTypeis a nice pattern. Theconstexpr ifbranching covers all cases exhaustively. - Follows project conventions: CamelCase naming, stack effect comments, consistent assembly format via
Forth_StackOpBase. - CLAUDE.md updated: Both the supported words list and the new "Reduced-Width Memory" section are correct and consistent with the implementation.
Verdict
One documentation bug (summary says zero-extend, should say sign-extend) that should be fixed before merge. Otherwise the code is correct and well-organized.
Summary
MemoryLoadOpConversion/MemoryStoreOpConversiontemplates withMemTypeenumCloses #52
Test plan
forth.*opsgpu.binary