Skip to content

Fuzzer: Emit SIMD lane load and store instructions - #9206

Merged
tlively merged 44 commits into
mainfrom
fuzzer-simd-load-store-lane
Oct 14, 2026
Merged

tlively merged 44 commits into
mainfrom
fuzzer-simd-load-store-lane

Conversation

@tlively

@tlively tlively commented Oct 3, 2026

Copy link
Copy Markdown
Member

Add makeSIMDLoadStoreLane and call it from _makenone, makeSIMD,
makeNonAtomicLoad, and makeNonAtomicStore. Also guard makeSIMDLoad with
allowMemory.

…ructions

Previously, br_on_cast_desc_eq and br_on_cast_desc_eq_fail were rarely emitted
(~0.2 per module) because:
1. makeBrOn had low selection weight despite covering 6 instructions.
2. breakableStack searches stopped immediately on Type::none targets (forcing
   br_on_null) and often lacked reference targets.
3. Descriptor casts were only emitted when getSubType happened by chance to pick
   a struct with a descriptor.

Fix this by:
- Tracking described struct types by Shareability in describedTypes and adding
  hasDescribedSubType / getDescribedSubType helpers.
- Increasing makeBrOn weight to Important.
- Preferring reference targets (especially those with described subtypes) with
  randomness when searching breakableStack, and wrapping in a new target block
  when makeBrOn is called for a reference type without a suitable target.
- Selecting BrOnCastDescEq and BrOnCastDescEqFail directly when described
  subtypes are available instead of upgrading BrOnCast / BrOnCastFail.

Across 200 fuzzer modules, this increases br_on_cast_desc_eq from 0.20 to 2.69
per module (16.0% -> 48.0% of modules) and br_on_cast_desc_eq_fail from 0.18 to
2.88 per module (11.5% -> 50.0% of modules), while also increasing br_on_null
from 27.40 to 34.46 per module.
For i64 pair tuples in _makeConcrete, add makeWideIntExpression with
VeryImportant weight (requiring Multivalue as well as WideArithmetic)
alongside makeTupleMake instead of replacing it half the time with
default weight. This increases generation of unextracted (i64, i64)
wide arithmetic expressions by ~4.2x.
Add try-delegate generation to TranslateToFuzzReader::makeTry and update
fixAfterChanges to preserve DELEGATE_CALLER_TARGET on try-delegates.

Also fix three bugs uncovered by fuzzing delegate and add regression tests:
- Preserve concrete stack types on StackInst::Delegate in StackIRGenerator.
- Increment controlFlowDepth after printing the condition in
  PrintSExpression::visitIf and pop catchIndexStack on StackInst::Delegate in
  printStackIR.
- Use dynCast<Try>() instead of cast<Try>() when walking tryStack in
  CFGWalker.
Add makeElemDrop and call it from makeBulkMemory.
Generate extern.convert_any in makeBasicRef for HeapType::ext when GC is enabled.
Add makeMemorySize and makeMemoryGrow and include them in _makeConcrete when
generating an integer matching the memory address type.
Add makeSIMDLoadStoreLane and call it from _makenone, makeSIMD,
makeNonAtomicLoad, and makeNonAtomicStore. Also guard makeSIMDLoad with
allowMemory.
Add makeTableSize and makeTableGrow and include them in _makeConcrete when
generating an integer matching any table's address type. Also cap table->max
at ReasonableMaxTableSize instead of kUnlimitedSize in finalizeTable so
table.grow cannot allocate unbounded memory during fuzzing.
@tlively
tlively requested a review from a team as a code owner October 3, 2026 18:43
@tlively
tlively requested review from kripken and removed request for a team October 3, 2026 18:43
Comment thread src/tools/fuzzing/fuzzing.cpp Outdated
if (type == Type::v128) {
assert(wasm.features.hasSIMD());
if (oneIn(2)) {
return makeSIMDLoadStoreLane(type);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is the main code path to that function not enough?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function can already emit normal SIMD loads when type == Type::v128, so it seems reasonable to let it emit other kinds of SIMD loads as well.

I'm not tied to this, though. Putting SIMDLoadStoreLane only behind makeSIMD also seems reasonable. It will just make it much less likely to be generated, but I guess that's no different from any other SIMD instruction.

I'll make this change.

Comment thread src/tools/fuzzing/fuzzing.cpp Outdated
&Self::makeNop,
&Self::makeGlobalSet)
.add(FeatureSet::BulkMemory, &Self::makeBulkMemory)
.add(FeatureSet::SIMD, &Self::makeSIMDLoadStoreLane)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like in general we put all SIMD instructions behind makeSIMD()?

tlively added 17 commits October 7, 2026 14:41
# Conflicts:
#	src/tools/fuzzing/fuzzing.cpp
#	test/passes/translate-to-fuzz_all-features_metrics_noprint.txt
# Conflicts:
#	test/passes/translate-to-fuzz_all-features_metrics_noprint.txt
# Conflicts:
#	test/passes/translate-to-fuzz_all-features_metrics_noprint.txt
# Conflicts:
#	test/passes/translate-to-fuzz_all-features_metrics_noprint.txt
# Conflicts:
#	test/passes/translate-to-fuzz_all-features_metrics_noprint.txt
# Conflicts:
#	test/passes/translate-to-fuzz_all-features_metrics_noprint.txt
# Conflicts:
#	test/passes/translate-to-fuzz_all-features_metrics_noprint.txt
# Conflicts:
#	test/passes/translate-to-fuzz_all-features_metrics_noprint.txt
# Conflicts:
#	test/passes/translate-to-fuzz_all-features_metrics_noprint.txt
# Conflicts:
#	test/passes/translate-to-fuzz_all-features_metrics_noprint.txt
# Conflicts:
#	test/passes/translate-to-fuzz_all-features_metrics_noprint.txt
# Conflicts:
#	test/passes/translate-to-fuzz_all-features_metrics_noprint.txt
# Conflicts:
#	test/passes/translate-to-fuzz_all-features_metrics_noprint.txt
# Conflicts:
#	test/passes/translate-to-fuzz_all-features_metrics_noprint.txt
# Conflicts:
#	test/passes/translate-to-fuzz_all-features_metrics_noprint.txt
# Conflicts:
#	test/passes/translate-to-fuzz_all-features_metrics_noprint.txt
Base automatically changed from fuzzer-table-size-grow to main October 14, 2026 01:50

@tlively tlively left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kripken, this is ready for another look.

Comment on lines -3805 to -3807
if (!wasm.features.hasSIMD()) {
return makeTrivial(type);
}

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These were dead code; we don't generate v128s if SIMD is not enabled.

@tlively
tlively requested a review from kripken October 14, 2026 20:25
@tlively
tlively enabled auto-merge (squash) October 14, 2026 21:52
@tlively
tlively merged commit 57ee991 into main Oct 14, 2026
16 checks passed
@tlively
tlively deleted the fuzzer-simd-load-store-lane branch October 14, 2026 22:14
@kripken

kripken commented Oct 15, 2026

Copy link
Copy Markdown
Member

@tlively
I see fuzzer errors after this landed,

wasm-opt: src/tools/fuzzing/fuzzing.cpp:4900: wasm::Expression* wasm::TranslateToFuzzReader::makeUnary(wasm::Type): Assertion `wasm.features.hasSIMD()' failed.

Context:

c28dd3c3e (Thomas Lively     2021-10-26 11:50:56 -0700 4899)     case Type::v128: {
c28dd3c3e (Thomas Lively     2021-10-26 11:50:56 -0700 4900)       assert(wasm.features.hasSIMD());

If that isn't enough to figure out the issue I can get the input.dat command etc., but hopefully it is?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants