diff --git a/src/tools/fuzzing.h b/src/tools/fuzzing.h index 78057877031..98a5407d013 100644 --- a/src/tools/fuzzing.h +++ b/src/tools/fuzzing.h @@ -464,6 +464,8 @@ class TranslateToFuzzReader { Expression* makeGlobalGet(Type type); Expression* makeGlobalSet(Type type); Expression* makeTupleMake(Type type); + Expression* makeWideIntAddSub(Type type); + Expression* makeWideIntMul(Type type); Expression* makeTupleExtract(Type type); Expression* makePointer(); Expression* makeNonAtomicLoad(Type type); diff --git a/src/tools/fuzzing/fuzzing.cpp b/src/tools/fuzzing/fuzzing.cpp index e7696532472..9bc7cce8852 100644 --- a/src/tools/fuzzing/fuzzing.cpp +++ b/src/tools/fuzzing/fuzzing.cpp @@ -2564,6 +2564,10 @@ Expression* TranslateToFuzzReader::_makeConcrete(Type type) { } if (type.isTuple()) { options.add(FeatureSet::Multivalue, &Self::makeTupleMake); + if (type == Types::getI64Pair()) { + options.add(FeatureSet::WideArithmetic, &Self::makeWideIntAddSub); + options.add(FeatureSet::WideArithmetic, &Self::makeWideIntMul); + } } if (type.isRef()) { auto heapType = type.getHeapType(); @@ -3246,6 +3250,26 @@ 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::makeTupleExtract(Type type) { // Tuples can require locals in binary format conversions. if (!type.isDefaultable()) { @@ -6156,9 +6180,15 @@ Type TranslateToFuzzReader::getMVPType() { } Type TranslateToFuzzReader::getTupleType() { + if (wasm.features.hasWideArithmetic() && oneIn(4)) { + return Types::getI64Pair(); + } + std::vector 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 - 1); + ; + 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"). diff --git a/test/passes/translate-to-fuzz_all-features_metrics_noprint.txt b/test/passes/translate-to-fuzz_all-features_metrics_noprint.txt index 7f56b028dc0..e190c20491e 100644 --- a/test/passes/translate-to-fuzz_all-features_metrics_noprint.txt +++ b/test/passes/translate-to-fuzz_all-features_metrics_noprint.txt @@ -1,50 +1,53 @@ Metrics total - [exports] : 13 - [funcs] : 18 + [exports] : 5 + [funcs] : 9 [globals] : 2 - [imports] : 13 + [imports] : 11 [memories] : 1 [memory-data] : 16 [table-data] : 3 [tables] : 2 - [tags] : 2 - [total] : 525 - [vars] : 51 - ArrayNewFixed : 2 - AtomicFence : 1 - Binary : 27 - Block : 97 - Break : 9 - Call : 17 - CallRef : 1 - Const : 101 - Drop : 8 - GlobalGet : 48 - GlobalSet : 44 - If : 29 - LocalGet : 15 - LocalSet : 10 - Loop : 4 - MemoryInit : 1 - Nop : 7 - RefAs : 1 + [tags] : 3 + [total] : 432 + [vars] : 26 + ArrayNewFixed : 1 + AtomicCmpxchg : 1 + AtomicRMW : 1 + Binary : 25 + Block : 77 + Break : 5 + Call : 11 + Const : 79 + Drop : 3 + GlobalGet : 33 + GlobalSet : 32 + If : 23 + Load : 3 + LocalGet : 9 + LocalSet : 11 + Loop : 7 + Nop : 10 + Pop : 4 + RefAs : 5 + RefCast : 1 RefEq : 2 - RefFunc : 7 - RefI31 : 6 - RefNull : 5 + RefFunc : 4 + RefI31 : 5 + RefIsNull : 1 + RefNull : 9 Return : 4 - SIMDExtract : 2 Select : 2 - Store : 1 - StringConst : 5 - StringEncode : 1 - StringEq : 1 - StringMeasure : 1 - StructNew : 7 + Store : 2 + StringConst : 1 + StringEncode : 2 + StructNew : 3 TableSet : 1 + Throw : 2 + ThrowRef : 1 + Try : 3 TryTable : 2 - TupleExtract : 1 - TupleMake : 3 - Unary : 29 - Unreachable : 23 + TupleExtract : 5 + TupleMake : 6 + Unary : 20 + Unreachable : 16