Backport More constant folding.

(cherry picked from commit b8cdbcaca569f1e14e1b05e1e9494fd97412473f)