From 941fc129e2f059a5fb9f5ab77f5cb12aedecd145 Mon Sep 17 00:00:00 2001 From: Austin Clements Date: Thu, 11 Jan 2018 14:23:01 -0500 Subject: cmd/compile: derive unsigned limits from signed limits in prove MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This adds a few simple deductions to the prove pass' fact table to derive unsigned concrete limits from signed concrete limits where possible. This tweak lets the pass prove 70 additional branch conditions in std and cmd. This is based on a comment from the recently-deleted factsTable.get: "// TODO: also use signed data if lim.min >= 0". Change-Id: Ib4340249e7733070f004a0aa31254adf5df8a392 Reviewed-on: https://go-review.googlesource.com/87479 Reviewed-by: Alexandru Moșoi Reviewed-by: Keith Randall --- test/prove.go | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) (limited to 'test/prove.go') diff --git a/test/prove.go b/test/prove.go index 2f4fa5d308..13e18cd728 100644 --- a/test/prove.go +++ b/test/prove.go @@ -479,12 +479,33 @@ func sm1(b []int, x int) { // Test constant argument to slicemask. useSlice(b[2:8]) // ERROR "Proved slicemask not needed$" // Test non-constant argument with known limits. - // Right now prove only uses the unsigned limit. - if uint(cap(b)) > 10 { + if cap(b) > 10 { useSlice(b[2:]) // ERROR "Proved slicemask not needed$" } } +func lim1(x, y, z int) { + // Test relations between signed and unsigned limits. + if x > 5 { + if uint(x) > 5 { // ERROR "Proved Greater64U$" + return + } + } + if y >= 0 && y < 4 { + if uint(y) > 4 { // ERROR "Disproved Greater64U$" + return + } + if uint(y) < 5 { // ERROR "Proved Less64U$" + return + } + } + if z < 4 { + if uint(z) > 4 { // Not provable without disjunctions. + return + } + } +} + //go:noinline func useInt(a int) { } -- cgit v1.2.1