]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: fix typo in floating point rule
authorTodd Neal <todd@tneal.org>
Fri, 15 Sep 2017 00:47:18 +0000 (19:47 -0500)
committerTodd Neal <todd@tneal.org>
Fri, 15 Sep 2017 03:07:43 +0000 (03:07 +0000)
Change-Id: Idfb64fcb26f48d5b70bab872f9a3d96a036be681
Reviewed-on: https://go-review.googlesource.com/63950
Run-TryBot: Todd Neal <todd@tneal.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
src/cmd/compile/internal/gc/float_test.go
src/cmd/compile/internal/ssa/gen/generic.rules
src/cmd/compile/internal/ssa/rewritegeneric.go

index 601158b6db9cacdfadfa6f4452a917847c31dde1..67aadedcc4c1c6c480bb1af862495cb449b3daa8 100644 (file)
@@ -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
index 93974ade1bc58fadfb8aac0cef5122fc187fb622..9ad99277f320d8da9c81aad503ad793e80d39631 100644 (file)
@@ -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
 
index b1b3661d44c3d126539ae395f07ea6f69d499e3f..8b261e5eb53cbd95889300544181a534e7473f74 100644 (file)
@@ -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
        }