]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: fix 32-bit unsigned division on 64-bit machines
authorKeith Randall <khr@golang.org>
Fri, 17 Feb 2017 19:36:08 +0000 (11:36 -0800)
committerKeith Randall <khr@golang.org>
Fri, 17 Feb 2017 22:21:04 +0000 (22:21 +0000)
The type of an intermediate multiply was wrong.  When that
intermediate multiply was spilled, the top 32 bits were lost.

Fixes #19153

Change-Id: Ib29350a4351efa405935b7f7ee3c112668e64108
Reviewed-on: https://go-review.googlesource.com/37212
Run-TryBot: Keith Randall <khr@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
src/cmd/compile/internal/ssa/gen/generic.rules
src/cmd/compile/internal/ssa/rewritegeneric.go

index b8028b84432fcc7399ab67cfcd8511e1b8870817..91e53ea2a35b8af73f6210294a87adca586699a2 100644 (file)
     (Rsh64Ux64 <config.fe.TypeUInt64()>
       (Avg64u
         (Lsh64x64 <config.fe.TypeUInt64()> (ZeroExt32to64 x) (Const64 <config.fe.TypeUInt64()> [32]))
-        (Mul64 <config.fe.TypeUInt32()>
+        (Mul64 <config.fe.TypeUInt64()>
           (Const64 <config.fe.TypeUInt32()> [int64(umagic(32,c).m)])
           (ZeroExt32to64 x)))
       (Const64 <config.fe.TypeUInt64()> [32+umagic(32,c).s-1])))
index d24ceff40717edf8c9a4543e69b2daa1ee4fc9fc..05eeeb80d0945880228a5d6086baa6b9e37568ab 100644 (file)
@@ -2813,7 +2813,7 @@ func rewriteValuegeneric_OpDiv32u(v *Value, config *Config) bool {
        }
        // match: (Div32u x (Const32 [c]))
        // cond: umagicOK(32, c) && config.RegSize == 8
-       // result: (Trunc64to32     (Rsh64Ux64 <config.fe.TypeUInt64()>       (Avg64u         (Lsh64x64 <config.fe.TypeUInt64()> (ZeroExt32to64 x) (Const64 <config.fe.TypeUInt64()> [32]))         (Mul64 <config.fe.TypeUInt32()>           (Const64 <config.fe.TypeUInt32()> [int64(umagic(32,c).m)])           (ZeroExt32to64 x)))       (Const64 <config.fe.TypeUInt64()> [32+umagic(32,c).s-1])))
+       // result: (Trunc64to32     (Rsh64Ux64 <config.fe.TypeUInt64()>       (Avg64u         (Lsh64x64 <config.fe.TypeUInt64()> (ZeroExt32to64 x) (Const64 <config.fe.TypeUInt64()> [32]))         (Mul64 <config.fe.TypeUInt64()>           (Const64 <config.fe.TypeUInt32()> [int64(umagic(32,c).m)])           (ZeroExt32to64 x)))       (Const64 <config.fe.TypeUInt64()> [32+umagic(32,c).s-1])))
        for {
                x := v.Args[0]
                v_1 := v.Args[1]
@@ -2835,7 +2835,7 @@ func rewriteValuegeneric_OpDiv32u(v *Value, config *Config) bool {
                v4.AuxInt = 32
                v2.AddArg(v4)
                v1.AddArg(v2)
-               v5 := b.NewValue0(v.Pos, OpMul64, config.fe.TypeUInt32())
+               v5 := b.NewValue0(v.Pos, OpMul64, config.fe.TypeUInt64())
                v6 := b.NewValue0(v.Pos, OpConst64, config.fe.TypeUInt32())
                v6.AuxInt = int64(umagic(32, c).m)
                v5.AddArg(v6)