Skip to content

Commit

Permalink
return 0 is compare function of sortBlocks when blocks are equal (#2026)
Browse files Browse the repository at this point in the history
Signed-off-by: Achille Roussel <[email protected]>
  • Loading branch information
achille-roussel authored Feb 8, 2024
1 parent 8cf0fc3 commit 0dc51ae
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions internal/engine/wazevo/ssa/basic_block_sort.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,27 @@ import (

func sortBlocks(blocks []*basicBlock) {
slices.SortFunc(blocks, func(i, j *basicBlock) int {
if j.ReturnBlock() {
jIsReturn := j.ReturnBlock()
iIsReturn := i.ReturnBlock()
if iIsReturn && jIsReturn {
return 0
}
if jIsReturn {
return 1
}
if i.ReturnBlock() {
if iIsReturn {
return -1
}
iRoot, jRoot := i.rootInstr, j.rootInstr
if iRoot == nil || jRoot == nil { // For testing.
if iRoot == nil && jRoot == nil { // For testing.
return 0
}
if jRoot == nil {
return 1
}
if iRoot == nil {
return -1
}
return i.rootInstr.id - j.rootInstr.id
})
}

0 comments on commit 0dc51ae

Please sign in to comment.