-
Notifications
You must be signed in to change notification settings - Fork 858
Fuzz wide arithmetic instructions #8661
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
stevenfontanella
wants to merge
6
commits into
main
Choose a base branch
from
wide-arithmetic-fuzzer
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
c0a9e8f
Fuzzer
stevenfontanella 2cd2140
Try reducing seed file size
stevenfontanella cbd24dd
WIP
stevenfontanella 64be00f
Revert some unneeded changes
stevenfontanella e63a6d5
Update test
stevenfontanella 7245fc0
Generate a new seed for fuzz import test
stevenfontanella File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2813,7 +2813,11 @@ Expression* TranslateToFuzzReader::_makeConcrete(Type type) { | |
| &Self::makeStringGet); | ||
| } | ||
| if (type.isTuple()) { | ||
| options.add(FeatureSet::Multivalue, &Self::makeTupleMake); | ||
| if (type == Types::getI64Pair() && oneIn(2)) { | ||
| options.add(FeatureSet::WideArithmetic, &Self::makeWideIntExpression); | ||
| } else { | ||
| options.add(FeatureSet::Multivalue, &Self::makeTupleMake); | ||
| } | ||
| } | ||
| if (type.isRef()) { | ||
| auto heapType = type.getHeapType(); | ||
|
|
@@ -3496,6 +3500,30 @@ Expression* TranslateToFuzzReader::makeTupleMake(Type type) { | |
| return builder.makeTupleMake(std::move(elements)); | ||
| } | ||
|
|
||
| Expression* TranslateToFuzzReader::makeWideIntAddSub(Type type) { | ||
| assert(wasm.features.hasWideArithmetic()); | ||
| assert(type == Types::getI64Pair()); | ||
| auto op = oneIn(2) ? AddInt128 : SubInt128; | ||
| auto* leftLow = make(Type::i64); | ||
| auto* leftHigh = make(Type::i64); | ||
| auto* rightLow = make(Type::i64); | ||
| auto* rightHigh = make(Type::i64); | ||
| return builder.makeWideIntAddSub(op, leftLow, leftHigh, rightLow, rightHigh); | ||
| } | ||
|
|
||
| Expression* TranslateToFuzzReader::makeWideIntMul(Type type) { | ||
| assert(wasm.features.hasWideArithmetic()); | ||
| assert(type == Types::getI64Pair()); | ||
| auto op = oneIn(2) ? MulWideSInt64 : MulWideUInt64; | ||
| auto* left = make(Type::i64); | ||
| auto* right = make(Type::i64); | ||
| return builder.makeWideIntMul(op, left, right); | ||
| } | ||
|
|
||
| Expression* TranslateToFuzzReader::makeWideIntExpression(Type type) { | ||
| return oneIn(2) ? makeWideIntAddSub(type) : makeWideIntMul(type); | ||
| } | ||
|
|
||
| Expression* TranslateToFuzzReader::makeTupleExtract(Type type) { | ||
| // Tuples can require locals in binary format conversions. | ||
| if (!type.isDefaultable()) { | ||
|
|
@@ -6426,9 +6454,13 @@ Type TranslateToFuzzReader::getMVPType() { | |
| } | ||
|
|
||
| Type TranslateToFuzzReader::getTupleType() { | ||
| if (wasm.features.hasWideArithmetic() && oneIn(2)) { | ||
| return Types::getI64Pair(); | ||
| } | ||
|
|
||
| std::vector<Type> elements; | ||
| size_t maxElements = 2 + upTo(fuzzParams->MAX_TUPLE_SIZE - 1); | ||
| for (size_t i = 0; i < maxElements; ++i) { | ||
| size_t numElements = 2 + upTo(fuzzParams->MAX_TUPLE_SIZE - 2); | ||
|
stevenfontanella marked this conversation as resolved.
|
||
| for (size_t i = 0; i < numElements; ++i) { | ||
| auto type = getSingleConcreteType(); | ||
| // Don't add a non-defaultable type into a tuple, as currently we can't | ||
| // spill them into locals (that would require a "let"). | ||
|
|
@@ -6443,7 +6475,7 @@ Type TranslateToFuzzReader::getTupleType() { | |
| } | ||
|
|
||
| Type TranslateToFuzzReader::getConcreteType() { | ||
| if (wasm.features.hasMultivalue() && oneIn(5)) { | ||
| if (wasm.features.hasMultivalue() && oneIn(2)) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think we want this, or if we do, let's put it in a separate PR? In general tuples matter less than single types, because they are used far more rarely in the wild. |
||
| return getTupleType(); | ||
| } else { | ||
| return getSingleConcreteType(); | ||
|
|
||
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
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
Binary file not shown.
94 changes: 49 additions & 45 deletions
94
test/passes/translate-to-fuzz_all-features_metrics_noprint.txt
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,55 +1,59 @@ | ||
| Metrics | ||
| total | ||
| [exports] : 10 | ||
| [funcs] : 5 | ||
| [exports] : 16 | ||
| [funcs] : 21 | ||
| [globals] : 2 | ||
| [imports] : 13 | ||
| [imports] : 14 | ||
| [memories] : 1 | ||
| [memory-data] : 16 | ||
| [table-data] : 2 | ||
| [table-data] : 3 | ||
| [tables] : 2 | ||
| [tags] : 3 | ||
| [total] : 704 | ||
| [vars] : 26 | ||
| ArrayNewFixed : 6 | ||
| AtomicFence : 3 | ||
| Binary : 30 | ||
| Block : 130 | ||
| BrOn : 6 | ||
| Break : 23 | ||
| Call : 30 | ||
| CallRef : 2 | ||
| Const : 103 | ||
| Drop : 10 | ||
| GlobalGet : 44 | ||
| GlobalSet : 42 | ||
| I31Get : 3 | ||
| If : 39 | ||
| Load : 6 | ||
| LocalGet : 25 | ||
| LocalSet : 27 | ||
| Loop : 16 | ||
| [tags] : 2 | ||
| [total] : 694 | ||
| [vars] : 70 | ||
| ArrayNewFixed : 4 | ||
| AtomicFence : 1 | ||
| AtomicNotify : 3 | ||
| Binary : 34 | ||
| Block : 122 | ||
| BrOn : 1 | ||
| Break : 9 | ||
| Call : 32 | ||
| CallIndirect : 2 | ||
| Const : 144 | ||
| Drop : 18 | ||
| GlobalGet : 54 | ||
| GlobalSet : 54 | ||
| I31Get : 1 | ||
| If : 38 | ||
| Load : 2 | ||
| LocalGet : 12 | ||
| LocalSet : 8 | ||
| Loop : 6 | ||
| MemoryInit : 1 | ||
| Nop : 7 | ||
| Pop : 6 | ||
| RefEq : 1 | ||
| RefFunc : 11 | ||
| RefI31 : 10 | ||
| RefNull : 10 | ||
| RefTest : 7 | ||
| Return : 3 | ||
| Nop : 10 | ||
| Pop : 3 | ||
| RefAs : 2 | ||
| RefEq : 3 | ||
| RefFunc : 5 | ||
| RefI31 : 12 | ||
| RefIsNull : 1 | ||
| RefNull : 1 | ||
| RefTest : 1 | ||
| Return : 4 | ||
| SIMDExtract : 2 | ||
| Select : 1 | ||
| Store : 2 | ||
| StringConst : 7 | ||
| StringEq : 1 | ||
| StringMeasure : 2 | ||
| StringWTF16Get : 2 | ||
| StructNew : 8 | ||
| TableSet : 2 | ||
| Throw : 2 | ||
| Try : 6 | ||
| TryTable : 6 | ||
| StringConst : 8 | ||
| StringMeasure : 1 | ||
| StructNew : 3 | ||
| Switch : 1 | ||
| TableSet : 1 | ||
| Throw : 3 | ||
| ThrowRef : 1 | ||
| Try : 4 | ||
| TryTable : 5 | ||
| TupleExtract : 3 | ||
| TupleMake : 5 | ||
| Unary : 35 | ||
| Unreachable : 21 | ||
| TupleMake : 6 | ||
| Unary : 37 | ||
| Unreachable : 28 |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One in 2 seems very high, purely subjectively.