Commit a9292b83 authored by Keith Randall's avatar Keith Randall

cmd/compile: fix 32-bit unsigned division on 64-bit machines

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: default avatarCherry Zhang <cherryyz@google.com>
parent 4498b683
......@@ -1013,7 +1013,7 @@
(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])))
......
......@@ -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)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment