golang编译器是否使用常量折叠?

just wondering if "go" compiler uses any sort of optimization such as constant folding.

https://en.wikipedia.org/wiki/Constant_folding

searched through google but couldn't find the answer i'm looking for.

Try to write a simple program: eg.

package main

import "fmt"

func main() {
    fmt.Println(12345*1000)
}

And now compile it to assembly

go tool compile -S examle.go

And now find 12345 in the result and you will have an answer.

Constant folding - Wikipedia

Constant folding is the process of recognizing and evaluating constant expressions at compile time rather than computing them at runtime.


The Go Programming Language Specification

Constant expressions

Constant expressions may contain only constant operands and are evaluated at compile time.


Package big

import "math/big"

Package big implements arbitrary-precision arithmetic (big numbers).


Go constant expressions are evaluated at compile time. The Go gc compiler, written in Go, uses package big to evaluate numeric constant expressions.