Commit 17396575 authored by Keith Randall's avatar Keith Randall

cmd/compile: shift tests, fix triple-shift rules

Add a bunch of tests for shifts.

Fix triple-shift rules to always take constant shifts as 64 bits.
(Earlier rules always promote shift amounts to 64 bits.)
Add overflow checks.

Increases generic rule coverage to 91%

Change-Id: I6b42d368d19d36ac482dbb8e0d4f67e30ad7145d
Reviewed-on: https://go-review.googlesource.com/23555Reviewed-by: default avatarTodd Neal <todd@tneal.org>
parent 79f7ccf2
This diff is collapsed.
......@@ -246,17 +246,53 @@
// zero shifted.
(Lsh64x64 (Const64 [0]) _) -> (Const64 [0])
(Lsh64x32 (Const64 [0]) _) -> (Const64 [0])
(Lsh64x16 (Const64 [0]) _) -> (Const64 [0])
(Lsh64x8 (Const64 [0]) _) -> (Const64 [0])
(Rsh64x64 (Const64 [0]) _) -> (Const64 [0])
(Rsh64x32 (Const64 [0]) _) -> (Const64 [0])
(Rsh64x16 (Const64 [0]) _) -> (Const64 [0])
(Rsh64x8 (Const64 [0]) _) -> (Const64 [0])
(Rsh64Ux64 (Const64 [0]) _) -> (Const64 [0])
(Lsh32x64 (Const64 [0]) _) -> (Const32 [0])
(Rsh32x64 (Const64 [0]) _) -> (Const32 [0])
(Rsh32Ux64 (Const64 [0]) _) -> (Const32 [0])
(Lsh16x64 (Const64 [0]) _) -> (Const16 [0])
(Rsh16x64 (Const64 [0]) _) -> (Const16 [0])
(Rsh16Ux64 (Const64 [0]) _) -> (Const16 [0])
(Lsh8x64 (Const64 [0]) _) -> (Const8 [0])
(Rsh8x64 (Const64 [0]) _) -> (Const8 [0])
(Rsh8Ux64 (Const64 [0]) _) -> (Const8 [0])
(Rsh64Ux32 (Const64 [0]) _) -> (Const64 [0])
(Rsh64Ux16 (Const64 [0]) _) -> (Const64 [0])
(Rsh64Ux8 (Const64 [0]) _) -> (Const64 [0])
(Lsh32x64 (Const32 [0]) _) -> (Const32 [0])
(Lsh32x32 (Const32 [0]) _) -> (Const32 [0])
(Lsh32x16 (Const32 [0]) _) -> (Const32 [0])
(Lsh32x8 (Const32 [0]) _) -> (Const32 [0])
(Rsh32x64 (Const32 [0]) _) -> (Const32 [0])
(Rsh32x32 (Const32 [0]) _) -> (Const32 [0])
(Rsh32x16 (Const32 [0]) _) -> (Const32 [0])
(Rsh32x8 (Const32 [0]) _) -> (Const32 [0])
(Rsh32Ux64 (Const32 [0]) _) -> (Const32 [0])
(Rsh32Ux32 (Const32 [0]) _) -> (Const32 [0])
(Rsh32Ux16 (Const32 [0]) _) -> (Const32 [0])
(Rsh32Ux8 (Const32 [0]) _) -> (Const32 [0])
(Lsh16x64 (Const16 [0]) _) -> (Const16 [0])
(Lsh16x32 (Const16 [0]) _) -> (Const16 [0])
(Lsh16x16 (Const16 [0]) _) -> (Const16 [0])
(Lsh16x8 (Const16 [0]) _) -> (Const16 [0])
(Rsh16x64 (Const16 [0]) _) -> (Const16 [0])
(Rsh16x32 (Const16 [0]) _) -> (Const16 [0])
(Rsh16x16 (Const16 [0]) _) -> (Const16 [0])
(Rsh16x8 (Const16 [0]) _) -> (Const16 [0])
(Rsh16Ux64 (Const16 [0]) _) -> (Const16 [0])
(Rsh16Ux32 (Const16 [0]) _) -> (Const16 [0])
(Rsh16Ux16 (Const16 [0]) _) -> (Const16 [0])
(Rsh16Ux8 (Const16 [0]) _) -> (Const16 [0])
(Lsh8x64 (Const8 [0]) _) -> (Const8 [0])
(Lsh8x32 (Const8 [0]) _) -> (Const8 [0])
(Lsh8x16 (Const8 [0]) _) -> (Const8 [0])
(Lsh8x8 (Const8 [0]) _) -> (Const8 [0])
(Rsh8x64 (Const8 [0]) _) -> (Const8 [0])
(Rsh8x32 (Const8 [0]) _) -> (Const8 [0])
(Rsh8x16 (Const8 [0]) _) -> (Const8 [0])
(Rsh8x8 (Const8 [0]) _) -> (Const8 [0])
(Rsh8Ux64 (Const8 [0]) _) -> (Const8 [0])
(Rsh8Ux32 (Const8 [0]) _) -> (Const8 [0])
(Rsh8Ux16 (Const8 [0]) _) -> (Const8 [0])
(Rsh8Ux8 (Const8 [0]) _) -> (Const8 [0])
// large left shifts of all values, and right shifts of unsigned values
(Lsh64x64 _ (Const64 [c])) && uint64(c) >= 64 -> (Const64 [0])
......@@ -286,31 +322,31 @@
// ((x >> c1) << c2) >> c3
(Rsh64Ux64 (Lsh64x64 (Rsh64Ux64 x (Const64 [c1])) (Const64 [c2])) (Const64 [c3]))
&& uint64(c1) >= uint64(c2) && uint64(c3) >= uint64(c2)
&& uint64(c1) >= uint64(c2) && uint64(c3) >= uint64(c2) && !uaddOvf(c1-c2, c3)
-> (Rsh64Ux64 x (Const64 <config.fe.TypeUInt64()> [c1-c2+c3]))
(Rsh32Ux64 (Lsh32x64 (Rsh32Ux64 x (Const32 [c1])) (Const32 [c2])) (Const32 [c3]))
&& uint32(c1) >= uint32(c2) && uint32(c3) >= uint32(c2)
-> (Rsh32Ux64 x (Const32 <config.fe.TypeUInt32()> [int64(int32(c1-c2+c3))]))
(Rsh16Ux64 (Lsh16x64 (Rsh16Ux64 x (Const16 [c1])) (Const16 [c2])) (Const16 [c3]))
&& uint16(c1) >= uint16(c2) && uint16(c3) >= uint16(c2)
-> (Rsh16Ux64 x (Const16 <config.fe.TypeUInt16()> [int64(int16(c1-c2+c3))]))
(Rsh8Ux64 (Lsh8x64 (Rsh8Ux64 x (Const8 [c1])) (Const8 [c2])) (Const8 [c3]))
&& uint8(c1) >= uint8(c2) && uint8(c3) >= uint8(c2)
-> (Rsh8Ux64 x (Const8 <config.fe.TypeUInt8()> [int64(int8(c1-c2+c3))]))
(Rsh32Ux64 (Lsh32x64 (Rsh32Ux64 x (Const64 [c1])) (Const64 [c2])) (Const64 [c3]))
&& uint64(c1) >= uint64(c2) && uint64(c3) >= uint64(c2) && !uaddOvf(c1-c2, c3)
-> (Rsh32Ux64 x (Const64 <config.fe.TypeUInt64()> [c1-c2+c3]))
(Rsh16Ux64 (Lsh16x64 (Rsh16Ux64 x (Const64 [c1])) (Const64 [c2])) (Const64 [c3]))
&& uint64(c1) >= uint64(c2) && uint64(c3) >= uint64(c2) && !uaddOvf(c1-c2, c3)
-> (Rsh16Ux64 x (Const64 <config.fe.TypeUInt64()> [c1-c2+c3]))
(Rsh8Ux64 (Lsh8x64 (Rsh8Ux64 x (Const64 [c1])) (Const64 [c2])) (Const64 [c3]))
&& uint64(c1) >= uint64(c2) && uint64(c3) >= uint64(c2) && !uaddOvf(c1-c2, c3)
-> (Rsh8Ux64 x (Const64 <config.fe.TypeUInt64()> [c1-c2+c3]))
// ((x << c1) >> c2) << c3
(Lsh64x64 (Rsh64Ux64 (Lsh64x64 x (Const64 [c1])) (Const64 [c2])) (Const64 [c3]))
&& uint64(c1) >= uint64(c2) && uint64(c3) >= uint64(c2)
&& uint64(c1) >= uint64(c2) && uint64(c3) >= uint64(c2) && !uaddOvf(c1-c2, c3)
-> (Lsh64x64 x (Const64 <config.fe.TypeUInt64()> [c1-c2+c3]))
(Lsh32x64 (Rsh32Ux64 (Lsh32x64 x (Const32 [c1])) (Const32 [c2])) (Const32 [c3]))
&& uint32(c1) >= uint32(c2) && uint32(c3) >= uint32(c2)
-> (Lsh32x64 x (Const32 <config.fe.TypeUInt32()> [int64(int32(c1-c2+c3))]))
(Lsh16x64 (Rsh16Ux64 (Lsh16x64 x (Const16 [c1])) (Const16 [c2])) (Const16 [c3]))
&& uint16(c1) >= uint16(c2) && uint16(c3) >= uint16(c2)
-> (Lsh16x64 x (Const16 <config.fe.TypeUInt16()> [int64(int16(c1-c2+c3))]))
(Lsh8x64 (Rsh8Ux64 (Lsh8x64 x (Const8 [c1])) (Const8 [c2])) (Const8 [c3]))
&& uint8(c1) >= uint8(c2) && uint8(c3) >= uint8(c2)
-> (Lsh8x64 x (Const8 <config.fe.TypeUInt8()> [int64(int8(c1-c2+c3))]))
(Lsh32x64 (Rsh32Ux64 (Lsh32x64 x (Const64 [c1])) (Const64 [c2])) (Const64 [c3]))
&& uint64(c1) >= uint64(c2) && uint64(c3) >= uint64(c2) && !uaddOvf(c1-c2, c3)
-> (Lsh32x64 x (Const64 <config.fe.TypeUInt64()> [c1-c2+c3]))
(Lsh16x64 (Rsh16Ux64 (Lsh16x64 x (Const64 [c1])) (Const64 [c2])) (Const64 [c3]))
&& uint64(c1) >= uint64(c2) && uint64(c3) >= uint64(c2) && !uaddOvf(c1-c2, c3)
-> (Lsh16x64 x (Const64 <config.fe.TypeUInt64()> [c1-c2+c3]))
(Lsh8x64 (Rsh8Ux64 (Lsh8x64 x (Const64 [c1])) (Const64 [c2])) (Const64 [c3]))
&& uint64(c1) >= uint64(c2) && uint64(c3) >= uint64(c2) && !uaddOvf(c1-c2, c3)
-> (Lsh8x64 x (Const64 <config.fe.TypeUInt64()> [c1-c2+c3]))
// constant comparisons
(Eq64 (Const64 [c]) (Const64 [d])) -> (ConstBool [b2i(c == d)])
......
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