Commit 5c3edc46 authored by Josh Bleecher Snyder's avatar Josh Bleecher Snyder

cmd/compile: add Trunc-of-Ext simplifications

This is a follow-up to the discussion
in CL 27853.

During make.bash, trigger count:

24 rewrite generic.rules:57
22 rewrite generic.rules:69
10 rewrite generic.rules:54
10 rewrite generic.rules:58
10 rewrite generic.rules:67
 7 rewrite generic.rules:66
 4 rewrite generic.rules:59
 3 rewrite generic.rules:50
 3 rewrite generic.rules:51
 3 rewrite generic.rules:52
 1 rewrite generic.rules:64

Change-Id: Id96cb6a707a4a564831f763c2d4d0e180c94bbef
Reviewed-on: https://go-review.googlesource.com/28088
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
Reviewed-by: 's avatarMartin Möhrmann <martisch@uos.de>
parent 74a00b24
......@@ -47,6 +47,27 @@
(Cvt64Fto32F (Const64F [c])) -> (Const32F [f2i(float64(i2f32(c)))])
(Cvt32Fto64F (Const32F [c])) -> (Const64F [c]) // c is already a 64 bit float
(Trunc16to8 (ZeroExt8to16 x)) -> x
(Trunc32to8 (ZeroExt8to32 x)) -> x
(Trunc32to16 (ZeroExt8to32 x)) -> (ZeroExt8to16 x)
(Trunc32to16 (ZeroExt16to32 x)) -> x
(Trunc64to8 (ZeroExt8to64 x)) -> x
(Trunc64to16 (ZeroExt8to64 x)) -> (ZeroExt8to16 x)
(Trunc64to16 (ZeroExt16to64 x)) -> x
(Trunc64to32 (ZeroExt8to64 x)) -> (ZeroExt8to32 x)
(Trunc64to32 (ZeroExt16to64 x)) -> (ZeroExt16to32 x)
(Trunc64to32 (ZeroExt32to64 x)) -> x
(Trunc16to8 (SignExt8to16 x)) -> x
(Trunc32to8 (SignExt8to32 x)) -> x
(Trunc32to16 (SignExt8to32 x)) -> (SignExt8to16 x)
(Trunc32to16 (SignExt16to32 x)) -> x
(Trunc64to8 (SignExt8to64 x)) -> x
(Trunc64to16 (SignExt8to64 x)) -> (SignExt8to16 x)
(Trunc64to16 (SignExt16to64 x)) -> x
(Trunc64to32 (SignExt8to64 x)) -> (SignExt8to32 x)
(Trunc64to32 (SignExt16to64 x)) -> (SignExt16to32 x)
(Trunc64to32 (SignExt32to64 x)) -> x
// const negation is currently handled by frontend
//(Neg8 (Const8 [c])) -> (Const8 [-c])
//(Neg16 (Const16 [c])) -> (Const16 [-c])
......
......@@ -9971,6 +9971,34 @@ func rewriteValuegeneric_OpTrunc16to8(v *Value, config *Config) bool {
v.AuxInt = int64(int8(c))
return true
}
// match: (Trunc16to8 (ZeroExt8to16 x))
// cond:
// result: x
for {
v_0 := v.Args[0]
if v_0.Op != OpZeroExt8to16 {
break
}
x := v_0.Args[0]
v.reset(OpCopy)
v.Type = x.Type
v.AddArg(x)
return true
}
// match: (Trunc16to8 (SignExt8to16 x))
// cond:
// result: x
for {
v_0 := v.Args[0]
if v_0.Op != OpSignExt8to16 {
break
}
x := v_0.Args[0]
v.reset(OpCopy)
v.Type = x.Type
v.AddArg(x)
return true
}
// match: (Trunc16to8 (And16 (Const16 [y]) x))
// cond: y&0xFF == 0xFF
// result: (Trunc16to8 x)
......@@ -10010,6 +10038,60 @@ func rewriteValuegeneric_OpTrunc32to16(v *Value, config *Config) bool {
v.AuxInt = int64(int16(c))
return true
}
// match: (Trunc32to16 (ZeroExt8to32 x))
// cond:
// result: (ZeroExt8to16 x)
for {
v_0 := v.Args[0]
if v_0.Op != OpZeroExt8to32 {
break
}
x := v_0.Args[0]
v.reset(OpZeroExt8to16)
v.AddArg(x)
return true
}
// match: (Trunc32to16 (ZeroExt16to32 x))
// cond:
// result: x
for {
v_0 := v.Args[0]
if v_0.Op != OpZeroExt16to32 {
break
}
x := v_0.Args[0]
v.reset(OpCopy)
v.Type = x.Type
v.AddArg(x)
return true
}
// match: (Trunc32to16 (SignExt8to32 x))
// cond:
// result: (SignExt8to16 x)
for {
v_0 := v.Args[0]
if v_0.Op != OpSignExt8to32 {
break
}
x := v_0.Args[0]
v.reset(OpSignExt8to16)
v.AddArg(x)
return true
}
// match: (Trunc32to16 (SignExt16to32 x))
// cond:
// result: x
for {
v_0 := v.Args[0]
if v_0.Op != OpSignExt16to32 {
break
}
x := v_0.Args[0]
v.reset(OpCopy)
v.Type = x.Type
v.AddArg(x)
return true
}
// match: (Trunc32to16 (And32 (Const32 [y]) x))
// cond: y&0xFFFF == 0xFFFF
// result: (Trunc32to16 x)
......@@ -10049,6 +10131,34 @@ func rewriteValuegeneric_OpTrunc32to8(v *Value, config *Config) bool {
v.AuxInt = int64(int8(c))
return true
}
// match: (Trunc32to8 (ZeroExt8to32 x))
// cond:
// result: x
for {
v_0 := v.Args[0]
if v_0.Op != OpZeroExt8to32 {
break
}
x := v_0.Args[0]
v.reset(OpCopy)
v.Type = x.Type
v.AddArg(x)
return true
}
// match: (Trunc32to8 (SignExt8to32 x))
// cond:
// result: x
for {
v_0 := v.Args[0]
if v_0.Op != OpSignExt8to32 {
break
}
x := v_0.Args[0]
v.reset(OpCopy)
v.Type = x.Type
v.AddArg(x)
return true
}
// match: (Trunc32to8 (And32 (Const32 [y]) x))
// cond: y&0xFF == 0xFF
// result: (Trunc32to8 x)
......@@ -10088,6 +10198,60 @@ func rewriteValuegeneric_OpTrunc64to16(v *Value, config *Config) bool {
v.AuxInt = int64(int16(c))
return true
}
// match: (Trunc64to16 (ZeroExt8to64 x))
// cond:
// result: (ZeroExt8to16 x)
for {
v_0 := v.Args[0]
if v_0.Op != OpZeroExt8to64 {
break
}
x := v_0.Args[0]
v.reset(OpZeroExt8to16)
v.AddArg(x)
return true
}
// match: (Trunc64to16 (ZeroExt16to64 x))
// cond:
// result: x
for {
v_0 := v.Args[0]
if v_0.Op != OpZeroExt16to64 {
break
}
x := v_0.Args[0]
v.reset(OpCopy)
v.Type = x.Type
v.AddArg(x)
return true
}
// match: (Trunc64to16 (SignExt8to64 x))
// cond:
// result: (SignExt8to16 x)
for {
v_0 := v.Args[0]
if v_0.Op != OpSignExt8to64 {
break
}
x := v_0.Args[0]
v.reset(OpSignExt8to16)
v.AddArg(x)
return true
}
// match: (Trunc64to16 (SignExt16to64 x))
// cond:
// result: x
for {
v_0 := v.Args[0]
if v_0.Op != OpSignExt16to64 {
break
}
x := v_0.Args[0]
v.reset(OpCopy)
v.Type = x.Type
v.AddArg(x)
return true
}
// match: (Trunc64to16 (And64 (Const64 [y]) x))
// cond: y&0xFFFF == 0xFFFF
// result: (Trunc64to16 x)
......@@ -10127,6 +10291,86 @@ func rewriteValuegeneric_OpTrunc64to32(v *Value, config *Config) bool {
v.AuxInt = int64(int32(c))
return true
}
// match: (Trunc64to32 (ZeroExt8to64 x))
// cond:
// result: (ZeroExt8to32 x)
for {
v_0 := v.Args[0]
if v_0.Op != OpZeroExt8to64 {
break
}
x := v_0.Args[0]
v.reset(OpZeroExt8to32)
v.AddArg(x)
return true
}
// match: (Trunc64to32 (ZeroExt16to64 x))
// cond:
// result: (ZeroExt16to32 x)
for {
v_0 := v.Args[0]
if v_0.Op != OpZeroExt16to64 {
break
}
x := v_0.Args[0]
v.reset(OpZeroExt16to32)
v.AddArg(x)
return true
}
// match: (Trunc64to32 (ZeroExt32to64 x))
// cond:
// result: x
for {
v_0 := v.Args[0]
if v_0.Op != OpZeroExt32to64 {
break
}
x := v_0.Args[0]
v.reset(OpCopy)
v.Type = x.Type
v.AddArg(x)
return true
}
// match: (Trunc64to32 (SignExt8to64 x))
// cond:
// result: (SignExt8to32 x)
for {
v_0 := v.Args[0]
if v_0.Op != OpSignExt8to64 {
break
}
x := v_0.Args[0]
v.reset(OpSignExt8to32)
v.AddArg(x)
return true
}
// match: (Trunc64to32 (SignExt16to64 x))
// cond:
// result: (SignExt16to32 x)
for {
v_0 := v.Args[0]
if v_0.Op != OpSignExt16to64 {
break
}
x := v_0.Args[0]
v.reset(OpSignExt16to32)
v.AddArg(x)
return true
}
// match: (Trunc64to32 (SignExt32to64 x))
// cond:
// result: x
for {
v_0 := v.Args[0]
if v_0.Op != OpSignExt32to64 {
break
}
x := v_0.Args[0]
v.reset(OpCopy)
v.Type = x.Type
v.AddArg(x)
return true
}
// match: (Trunc64to32 (And64 (Const64 [y]) x))
// cond: y&0xFFFFFFFF == 0xFFFFFFFF
// result: (Trunc64to32 x)
......@@ -10166,6 +10410,34 @@ func rewriteValuegeneric_OpTrunc64to8(v *Value, config *Config) bool {
v.AuxInt = int64(int8(c))
return true
}
// match: (Trunc64to8 (ZeroExt8to64 x))
// cond:
// result: x
for {
v_0 := v.Args[0]
if v_0.Op != OpZeroExt8to64 {
break
}
x := v_0.Args[0]
v.reset(OpCopy)
v.Type = x.Type
v.AddArg(x)
return true
}
// match: (Trunc64to8 (SignExt8to64 x))
// cond:
// result: x
for {
v_0 := v.Args[0]
if v_0.Op != OpSignExt8to64 {
break
}
x := v_0.Args[0]
v.reset(OpCopy)
v.Type = x.Type
v.AddArg(x)
return true
}
// match: (Trunc64to8 (And64 (Const64 [y]) x))
// cond: y&0xFF == 0xFF
// result: (Trunc64to8 x)
......
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