Skip to content

Commit 29162ec

Browse files
committed
cmd/compile: in prove, infer unsigned relations while branching
When a branch is followed, we apply the relation as described in the domain relation table. In case the relation is in the positive domain, we can also infer an unsigned relation if, by that point, we know that both operands are non-negative. Fixes #20393 Change-Id: Ieaf0c81558b36d96616abae3eb834c788dd278d5 Reviewed-on: https://go-review.googlesource.com/100278 Run-TryBot: Giovanni Bajo <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Giovanni Bajo <[email protected]> Reviewed-by: David Chase <[email protected]>
1 parent 5c40210 commit 29162ec

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

src/cmd/compile/internal/ssa/prove.go

+3
Original file line numberDiff line numberDiff line change
@@ -704,6 +704,9 @@ func addBranchRestrictions(ft *factsTable, b *Block, br branch) {
704704
// When we branched from parent we learned a new set of
705705
// restrictions. Update the factsTable accordingly.
706706
d := tr.d
707+
if d == signed && ft.isNonNegative(c.Args[0]) && ft.isNonNegative(c.Args[1]) {
708+
d |= unsigned
709+
}
707710
switch br {
708711
case negative:
709712
switch b.Control.Op { // Special cases

test/prove.go

+9
Original file line numberDiff line numberDiff line change
@@ -605,6 +605,15 @@ func trans2(a, b []int, i int) {
605605
_ = b[i] // ERROR "Proved IsInBounds$"
606606
}
607607

608+
func trans3(a, b []int, i int) {
609+
if len(a) > len(b) {
610+
return
611+
}
612+
613+
_ = a[i]
614+
_ = b[i] // ERROR "Proved IsInBounds$"
615+
}
616+
608617
//go:noinline
609618
func useInt(a int) {
610619
}

0 commit comments

Comments
 (0)