From: Todd Neal Date: Fri, 15 Sep 2017 00:47:18 +0000 (-0500) Subject: cmd/compile: fix typo in floating point rule X-Git-Tag: go1.10beta1~1096 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=af860838123548e67232373d86453cdc4838e9d6;p=gostls13.git cmd/compile: fix typo in floating point rule Change-Id: Idfb64fcb26f48d5b70bab872f9a3d96a036be681 Reviewed-on: https://go-review.googlesource.com/63950 Run-TryBot: Todd Neal TryBot-Result: Gobot Gobot Reviewed-by: Keith Randall --- diff --git a/src/cmd/compile/internal/gc/float_test.go b/src/cmd/compile/internal/gc/float_test.go index 601158b6db..67aadedcc4 100644 --- a/src/cmd/compile/internal/gc/float_test.go +++ b/src/cmd/compile/internal/gc/float_test.go @@ -197,6 +197,16 @@ func cvt12(a float32) uint { return uint(a) } +//go:noinline +func f2i64p(v float64) *int64 { + return ip64(int64(v / 0.1)) +} + +//go:noinline +func ip64(v int64) *int64 { + return &v +} + func TestFloatConvert(t *testing.T) { if got := cvt1(3.5); got != 3 { t.Errorf("cvt1 got %d, wanted 3", got) @@ -234,6 +244,9 @@ func TestFloatConvert(t *testing.T) { if got := cvt12(3.5); got != 3 { t.Errorf("cvt12 got %d, wanted 3", got) } + if got := *f2i64p(10); got != 100 { + t.Errorf("f2i64p got %d, wanted 100", got) + } } var sinkFloat float64 diff --git a/src/cmd/compile/internal/ssa/gen/generic.rules b/src/cmd/compile/internal/ssa/gen/generic.rules index 93974ade1b..9ad99277f3 100644 --- a/src/cmd/compile/internal/ssa/gen/generic.rules +++ b/src/cmd/compile/internal/ssa/gen/generic.rules @@ -53,7 +53,7 @@ (Cvt32Fto32 (Const32F [c])) -> (Const32 [int64(int32(i2f(c)))]) (Cvt32Fto64 (Const32F [c])) -> (Const64 [int64(i2f(c))]) (Cvt64Fto32 (Const64F [c])) -> (Const32 [int64(int32(i2f(c)))]) -(Cvt64Fto64 (Const64F [c])) -> (Const32 [int64(i2f(c))]) +(Cvt64Fto64 (Const64F [c])) -> (Const64 [int64(i2f(c))]) (Round32F x:(Const32F)) -> x (Round64F x:(Const64F)) -> x diff --git a/src/cmd/compile/internal/ssa/rewritegeneric.go b/src/cmd/compile/internal/ssa/rewritegeneric.go index b1b3661d44..8b261e5eb5 100644 --- a/src/cmd/compile/internal/ssa/rewritegeneric.go +++ b/src/cmd/compile/internal/ssa/rewritegeneric.go @@ -7194,14 +7194,14 @@ func rewriteValuegeneric_OpCvt64Fto32F_0(v *Value) bool { func rewriteValuegeneric_OpCvt64Fto64_0(v *Value) bool { // match: (Cvt64Fto64 (Const64F [c])) // cond: - // result: (Const32 [int64(i2f(c))]) + // result: (Const64 [int64(i2f(c))]) for { v_0 := v.Args[0] if v_0.Op != OpConst64F { break } c := v_0.AuxInt - v.reset(OpConst32) + v.reset(OpConst64) v.AuxInt = int64(i2f(c)) return true }