mirror of
https://github.com/golang/go
synced 2024-09-04 23:44:16 +00:00
![Jorropo](/assets/img/avatar_default.png)
It is hit ~70k times building go.
This make the go binary, 0.04% smaller.
I didn't included benchmarks because this is just constant foldings
and is hard to mesure objectively.
For example, this enable rewriting things like:
if x == 20 {
return x + 30 + z
}
Into:
if x == 20 {
return 50 + z
}
It's not just fixing programer's code,
the ssa generator generate code like this sometimes.
Change-Id: I0861f342b27f7227b5f1c34d8267fa0057b1bbbc
GitHub-Last-Rev: 4c2f9b5216
GitHub-Pull-Request: golang/go#52669
Reviewed-on: https://go-review.googlesource.com/c/go/+/403735
Reviewed-by: Keith Randall <khr@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Keith Randall <khr@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
Reviewed-by: David Chase <drchase@google.com>
33 lines
602 B
Go
33 lines
602 B
Go
// +build amd64
|
|
// errorcheck -0 -d=ssa/prove/debug=2
|
|
|
|
// Copyright 2022 The Go Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package main
|
|
|
|
func f0i(x int) int {
|
|
if x == 20 {
|
|
return x // ERROR "Proved.+is constant 20$"
|
|
}
|
|
|
|
if (x + 20) == 20 {
|
|
return x + 5 // ERROR "Proved.+is constant 0$"
|
|
}
|
|
|
|
return x / 2
|
|
}
|
|
|
|
func f0u(x uint) uint {
|
|
if x == 20 {
|
|
return x // ERROR "Proved.+is constant 20$"
|
|
}
|
|
|
|
if (x + 20) == 20 {
|
|
return x + 5 // ERROR "Proved.+is constant 0$"
|
|
}
|
|
|
|
return x / 2
|
|
}
|