summaryrefslogtreecommitdiff
path: root/src/cmd
diff options
context:
space:
mode:
authorTodd Neal <todd@tneal.org>2017-09-14 19:47:18 -0500
committerTodd Neal <todd@tneal.org>2017-09-15 03:07:43 +0000
commitaf860838123548e67232373d86453cdc4838e9d6 (patch)
treec73c1df667aa818811b2177fd2e58ffaad16b146 /src/cmd
parent5a986eca869773c4459b36dad434b97287d5d4f3 (diff)
downloadgo-git-af860838123548e67232373d86453cdc4838e9d6.tar.gz
cmd/compile: fix typo in floating point rule
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>
Diffstat (limited to 'src/cmd')
-rw-r--r--src/cmd/compile/internal/gc/float_test.go13
-rw-r--r--src/cmd/compile/internal/ssa/gen/generic.rules2
-rw-r--r--src/cmd/compile/internal/ssa/rewritegeneric.go4
3 files changed, 16 insertions, 3 deletions
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
}