Skip to content

Commit

Permalink
offby1
Browse files Browse the repository at this point in the history
  • Loading branch information
ashleynh committed Jan 17, 2025
1 parent 1be536e commit 0d961b8
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/passes/hash-stringify-walker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ std::vector<SuffixTree::RepeatedSubstring> StringifyProcessor::removeOverlaps(
for (auto startIdx : substring.StartIndices) {
auto interval =
Interval(startIdx,
startIdx + substring.Length,
startIdx + substring.Length - 1,
substring.Length * substring.StartIndices.size());
intervals.push_back(interval);
intervalMap[std::move(interval)] = i;
Expand All @@ -173,7 +173,7 @@ std::vector<SuffixTree::RepeatedSubstring> StringifyProcessor::removeOverlaps(
doNotInclude.insert(intervalMap[interval]);
}

// Only include non-overlapping substrings
// Add the substrings that don't overlap to the result
std::vector<SuffixTree::RepeatedSubstring> result;
for (Index i = 0; i < substrings.size(); i++) {
if (doNotInclude.find(i) != doNotInclude.end()) {
Expand Down
2 changes: 1 addition & 1 deletion src/support/intervals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ IntervalProcessor::getOverlaps(std::vector<Interval>& intervals) {
continue;
}

// Keep the interval with the higher score
// Keep the interval with the higher weight
if (nextInterval.weight > firstInterval.weight) {
overlaps.insert(firstInterval);
firstInterval = nextInterval;
Expand Down
6 changes: 2 additions & 4 deletions src/support/intervals.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@

namespace wasm {

// The weight determines the value of the
// interval when comparing against another interval, higher is better.
struct Interval {
unsigned start;
unsigned end;
// The weight is used to determine which interval to keep when two overlap,
// higher is better
unsigned weight;
Interval(unsigned start, unsigned end, unsigned weight)
: start(start), end(end), weight(weight) {}
Expand All @@ -43,8 +43,6 @@ struct Interval {
};

struct IntervalProcessor {
// Given a vector of intervals, returns a new vector. To resolve overlapping
// intervals, the interval with the highest weight is kept.
static std::set<Interval> getOverlaps(std::vector<Interval>&);
};

Expand Down
54 changes: 54 additions & 0 deletions test/lit/passes/outlining.wast
Original file line number Diff line number Diff line change
Expand Up @@ -1006,3 +1006,57 @@
(loop (nop))
)
)

;; Test that no attempt is made to outline overlapping repeat substrings
(module
(func $a
(drop (i32.add
(i32.const 0)
(i32.const 1)
))
(drop (i32.sub
(i32.const 2)
(i32.const 3)
))
(drop (i32.mul
(i32.const 4)
(i32.const 5)
))
(drop (i32.div_u
(i32.const 6)
(i32.const 7)
))
(drop (i32.add
(i32.const 0)
(i32.const 1)
))
(drop (i32.sub
(i32.const 2)
(i32.const 3)
))
(drop (i32.mul
(i32.const 4)
(i32.const 5)
))
(drop (i32.div_u
(i32.const 6)
(i32.const 7)
))
(drop (i32.sub
(i32.const 2)
(i32.const 3)
))
(drop (i32.mul
(i32.const 4)
(i32.const 5)
))
(drop (i32.sub
(i32.const 2)
(i32.const 3)
))
(drop (i32.mul
(i32.const 4)
(i32.const 5)
))
)
)

0 comments on commit 0d961b8

Please sign in to comment.