]> Cypherpunks repositories - gostls13.git/commit
cmd/compile: add fence-post implications to prove
authorAustin Clements <austin@google.com>
Thu, 11 Jan 2018 21:32:02 +0000 (16:32 -0500)
committerAustin Clements <austin@google.com>
Thu, 8 Mar 2018 22:25:28 +0000 (22:25 +0000)
commit6436270dadb232e3ef1afc0d4cf714bcb9434910
tree143f097abbe291268925934ccc1a77b0bf5ff89f
parent941fc129e2f059a5fb9f5ab77f5cb12aedecd145
cmd/compile: add fence-post implications to prove

This adds four new deductions to the prove pass, all related to adding
or subtracting one from a value. This is the first hint of actual
arithmetic relations in the prove pass.

The most effective of these is

   x-1 >= w && x > min  ⇒  x > w

This helps eliminate bounds checks in code like

  if x > 0 {
    // do something with s[x-1]
  }

Altogether, these deductions prove an additional 260 branches in std
and cmd. Furthermore, they will let us eliminate some tricky
compiler-inserted panics in the runtime that are interfering with
static analysis.

Fixes #23354.

Change-Id: I7088223e0e0cd6ff062a75c127eb4bb60e6dce02
Reviewed-on: https://go-review.googlesource.com/87480
Reviewed-by: Keith Randall <khr@golang.org>
Reviewed-by: Alexandru Moșoi <alexandru@mosoi.ro>
src/cmd/compile/internal/ssa/prove.go
test/prove.go