diff --git a/src/tools/fuzzing.h b/src/tools/fuzzing.h index 3c47d2ed0d9..2bd3d7761c3 100644 --- a/src/tools/fuzzing.h +++ b/src/tools/fuzzing.h @@ -528,6 +528,7 @@ class TranslateToFuzzReader { Expression* makeSIMDTernary(); Expression* makeSIMDShift(); Expression* makeSIMDLoad(); + Expression* makeSIMDLoadStoreLane(Type type); Expression* makeBulkMemory(Type type); Expression* makeTableGet(Type type); Expression* makeTableSet(Type type); diff --git a/src/tools/fuzzing/fuzzing.cpp b/src/tools/fuzzing/fuzzing.cpp index 7c67a3bfb56..c202c210d7e 100644 --- a/src/tools/fuzzing/fuzzing.cpp +++ b/src/tools/fuzzing/fuzzing.cpp @@ -3047,6 +3047,7 @@ Expression* TranslateToFuzzReader::_makenone() { &Self::makeNop, &Self::makeGlobalSet) .add(FeatureSet::BulkMemory, &Self::makeBulkMemory) + .add(FeatureSet::SIMD, &Self::makeSIMD) .add(FeatureSet::Atomics, &Self::makeAtomic) .add(FeatureSet::ReferenceTypes, &Self::makeTableSet) .add(FeatureSet::ExceptionHandling, &Self::makeTry) @@ -3802,9 +3803,6 @@ Expression* TranslateToFuzzReader::makeNonAtomicLoad(Type type) { 8, false, offset, pick(1, 2, 4, 8), ptr, type, wasm.memories[0]->name); } case Type::v128: { - if (!wasm.features.hasSIMD()) { - return makeTrivial(type); - } return builder.makeLoad(16, false, offset, @@ -3919,9 +3917,6 @@ Expression* TranslateToFuzzReader::makeNonAtomicStore(Type type) { 8, offset, pick(1, 2, 4, 8), ptr, value, type, wasm.memories[0]->name); } case Type::v128: { - if (!wasm.features.hasSIMD()) { - return makeTrivial(type); - } return builder.makeStore(16, offset, pick(1, 2, 4, 8, 16), @@ -5443,11 +5438,13 @@ Expression* TranslateToFuzzReader::makeSIMD(Type type) { if (type.isRef()) { return makeTrivial(type); } + if (type == Type::none) { + return makeSIMDLoadStoreLane(Type::none); + } if (type != Type::v128) { return makeSIMDExtract(type); } - // TODO: Add SIMDLoadStoreLane once it is generally available - switch (upTo(7)) { + switch (upTo(8)) { case 0: return makeUnary(Type::v128); case 1: @@ -5462,6 +5459,8 @@ Expression* TranslateToFuzzReader::makeSIMD(Type type) { return makeSIMDShift(); case 6: return makeSIMDLoad(); + case 7: + return makeSIMDLoadStoreLane(Type::v128); } WASM_UNREACHABLE("invalid value"); } @@ -5616,6 +5615,9 @@ Expression* TranslateToFuzzReader::makeSIMDShift() { } Expression* TranslateToFuzzReader::makeSIMDLoad() { + if (!allowMemory) { + return makeTrivial(Type::v128); + } SIMDLoadOp op = pick(Load8SplatVec128, Load16SplatVec128, Load32SplatVec128, @@ -5660,6 +5662,54 @@ Expression* TranslateToFuzzReader::makeSIMDLoad() { return builder.makeSIMDLoad(op, offset, align, ptr, wasm.memories[0]->name); } +Expression* TranslateToFuzzReader::makeSIMDLoadStoreLane(Type type) { + if (!allowMemory) { + return makeTrivial(type); + } + SIMDLoadStoreLaneOp op; + if (type == Type::v128) { + op = pick( + Load8LaneVec128, Load16LaneVec128, Load32LaneVec128, Load64LaneVec128); + } else if (type == Type::none) { + op = pick(Store8LaneVec128, + Store16LaneVec128, + Store32LaneVec128, + Store64LaneVec128); + } else { + WASM_UNREACHABLE("unexpected type"); + } + Address offset = logify(get()); + Address align; + uint8_t lanes; + switch (op) { + case Load8LaneVec128: + case Store8LaneVec128: + align = 1; + lanes = 16; + break; + case Load16LaneVec128: + case Store16LaneVec128: + align = pick(1, 2); + lanes = 8; + break; + case Load32LaneVec128: + case Store32LaneVec128: + align = pick(1, 2, 4); + lanes = 4; + break; + case Load64LaneVec128: + case Store64LaneVec128: + align = pick(1, 2, 4, 8); + lanes = 2; + break; + } + uint8_t index = upTo(lanes); + Expression* ptr = makePointer(); + Expression* vec = make(Type::v128); + return builder.makeSIMDLoadStoreLane( + op, offset, align, index, ptr, vec, wasm.memories[0]->name); +} + Expression* TranslateToFuzzReader::makeBulkMemory(Type type) { assert(wasm.features.hasBulkMemory()); assert(type == Type::none); diff --git a/test/lit/fuzz-import.wast b/test/lit/fuzz-import.wast index 5d5cd529cac..b4ee662705d 100644 --- a/test/lit/fuzz-import.wast +++ b/test/lit/fuzz-import.wast @@ -2,7 +2,7 @@ ;; Generate fuzz output using this wat as initial contents, and importing the ;; side file. -;; RUN: wasm-opt %s.dat --initial-fuzz=%s -all -ttf --fuzz-import=%s.import \ +;; RUN: wasm-opt %s --initial-fuzz=%s -all -ttf --fuzz-import=%s.import \ ;; RUN: -S -o - | filecheck %s (module diff --git a/test/lit/fuzz-import.wast.dat b/test/lit/fuzz-import.wast.dat deleted file mode 100644 index 172f50c7db9..00000000000 Binary files a/test/lit/fuzz-import.wast.dat and /dev/null differ 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 d8d1217447b..fd25a01a8d3 100644 --- a/test/passes/translate-to-fuzz_all-features_metrics_noprint.txt +++ b/test/passes/translate-to-fuzz_all-features_metrics_noprint.txt @@ -1,99 +1,100 @@ Metrics total - [exports] : 48 - [funcs] : 109 + [exports] : 95 + [funcs] : 185 [globals] : 13 [imports] : 13 [memories] : 1 [memory-data] : 31 - [table-data] : 21 + [table-data] : 62 [tables] : 2 [tags] : 2 - [total] : 97338 - [vars] : 3397 - ArrayCmpxchg : 27 - ArrayCopy : 35 - ArrayFill : 42 - ArrayGet : 391 - ArrayLen : 581 - ArrayNew : 1137 - ArrayNewFixed : 340 - ArrayRMW : 21 - ArraySet : 79 - AtomicCmpxchg : 44 - AtomicFence : 76 - AtomicNotify : 24 - AtomicRMW : 37 - AtomicWait : 13 - Binary : 3631 - Block : 6694 - BrOn : 632 - Break : 964 - Call : 649 - CallIndirect : 130 - CallRef : 206 - Const : 12510 - ContBind : 1 - ContNew : 110 - DataDrop : 10 - Drop : 895 - ElemDrop : 12 - GlobalGet : 4805 - GlobalSet : 1896 - I31Get : 77 - If : 2348 - Load : 307 - LocalGet : 12016 - LocalSet : 3847 - Loop : 834 - MemoryCopy : 18 - MemoryFill : 21 - MemoryGrow : 39 - MemoryInit : 17 - MemorySize : 36 - Nop : 674 - Pop : 189 - RefAs : 9740 - RefCast : 704 - RefEq : 277 - RefFunc : 1822 - RefGetDesc : 53 - RefI31 : 625 - RefIsNull : 62 - RefNull : 9738 - RefTest : 62 - Return : 362 - SIMDExtract : 113 - SIMDReplace : 2 + [total] : 84922 + [vars] : 4130 + ArrayCmpxchg : 22 + ArrayCopy : 38 + ArrayFill : 24 + ArrayGet : 354 + ArrayLen : 512 + ArrayNew : 920 + ArrayNewFixed : 314 + ArrayRMW : 17 + ArraySet : 69 + AtomicCmpxchg : 28 + AtomicFence : 61 + AtomicNotify : 19 + AtomicRMW : 29 + AtomicWait : 14 + Binary : 3224 + Block : 6159 + BrOn : 549 + Break : 850 + Call : 805 + CallIndirect : 173 + CallRef : 179 + Const : 11095 + ContNew : 107 + DataDrop : 7 + Drop : 754 + ElemDrop : 16 + GlobalGet : 4189 + GlobalSet : 1867 + I31Get : 52 + If : 2179 + Load : 262 + LocalGet : 9178 + LocalSet : 3531 + Loop : 738 + MemoryCopy : 12 + MemoryFill : 6 + MemoryGrow : 33 + MemoryInit : 15 + MemorySize : 34 + Nop : 570 + Pop : 163 + RefAs : 7978 + RefCast : 614 + RefEq : 213 + RefFunc : 1551 + RefGetDesc : 57 + RefI31 : 620 + RefIsNull : 53 + RefNull : 8785 + RefTest : 56 + Return : 385 + SIMDExtract : 111 + SIMDLoad : 3 + SIMDLoadStoreLane: 52 + SIMDReplace : 8 SIMDShift : 1 - SIMDShuffle : 3 + SIMDShuffle : 1 SIMDTernary : 2 - Select : 321 - Store : 159 - StringConst : 400 - StringEncode : 51 - StringEq : 75 - StringMeasure : 78 - StringNew : 4 - StringSliceWTF : 3 - StringWTF16Get : 60 - StructCmpxchg : 40 - StructGet : 384 - StructNew : 11028 - StructRMW : 49 - StructSet : 71 - Switch : 3 + Select : 284 + Store : 117 + StringConst : 349 + StringEncode : 60 + StringEq : 62 + StringMeasure : 54 + StringNew : 3 + StringSliceWTF : 1 + StringWTF16Get : 47 + StructCmpxchg : 36 + StructGet : 408 + StructNew : 9381 + StructRMW : 37 + StructSet : 61 + Switch : 10 TableGet : 1 - TableGrow : 94 - TableSet : 77 - TableSize : 107 - Throw : 114 - ThrowRef : 6 - Try : 375 - TryTable : 478 - TupleExtract : 205 - TupleMake : 331 - Unary : 1834 - Unreachable : 975 - WideIntAddSub : 23 - WideIntMul : 11 + TableGrow : 67 + TableSet : 65 + TableSize : 77 + Throw : 111 + ThrowRef : 8 + Try : 332 + TryTable : 441 + TupleExtract : 246 + TupleMake : 241 + Unary : 1770 + Unreachable : 961 + WideIntAddSub : 20 + WideIntMul : 14