Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/passes/ConstraintAnalysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -655,13 +655,17 @@ struct ConstraintAnalysis
if (branch.constraint.op == Abstract::LtS ||
branch.constraint.op == Abstract::LeS) {
constraints.set(branch.local, branch.constraint);
constraints.approximateAnd(branch.local, {GeS, {*N}});
if (!constraints.unreachable) {
constraints.approximateAnd(branch.local, {GeS, {*N}});
}
return true;
}
if (branch.constraint.op == Abstract::LtU ||
branch.constraint.op == Abstract::LeU) {
constraints.set(branch.local, branch.constraint);
constraints.approximateAnd(branch.local, {GeU, {*N}});
if (!constraints.unreachable) {
constraints.approximateAnd(branch.local, {GeU, {*N}});
}
return true;
}

Expand Down
53 changes: 53 additions & 0 deletions test/lit/passes/constraint-analysis-loops.wast
Original file line number Diff line number Diff line change
Expand Up @@ -1520,4 +1520,57 @@
)
)
)

;; CHECK: (func $impossible-branch (type $0)
;; CHECK-NEXT: (local $x i32)
;; CHECK-NEXT: (local $y i32)
;; CHECK-NEXT: (loop $loop
;; CHECK-NEXT: (br_if $loop
;; CHECK-NEXT: (i32.lt_s
;; CHECK-NEXT: (local.get $x)
;; CHECK-NEXT: (local.get $y)
;; CHECK-NEXT: )
;; CHECK-NEXT: )
;; CHECK-NEXT: )
;; CHECK-NEXT: )
(func $impossible-branch
(local $x i32)
(local $y i32)
(loop $loop
;; x == y == 0, so x < y leads to a contradiction, and we never branch
;; back up to the loop. We should not error here.
(br_if $loop
(i32.lt_s
(local.get $x)
(local.get $y)
)
)
)
)

;; CHECK: (func $impossible-branch-unsigned (type $0)
;; CHECK-NEXT: (local $x i32)
;; CHECK-NEXT: (local $y i32)
;; CHECK-NEXT: (loop $loop
;; CHECK-NEXT: (br_if $loop
;; CHECK-NEXT: (i32.lt_u
;; CHECK-NEXT: (local.get $x)
;; CHECK-NEXT: (local.get $y)
;; CHECK-NEXT: )
;; CHECK-NEXT: )
;; CHECK-NEXT: )
;; CHECK-NEXT: )
(func $impossible-branch-unsigned
(local $x i32)
(local $y i32)
;; As above, but unsigned.
(loop $loop
(br_if $loop
(i32.lt_u
(local.get $x)
(local.get $y)
)
)
)
)
)
Loading