Skip to content

Commit ac74225

Browse files
committed
cmd/compile: remove redundant extension after shift
var x uint64 uint8(x >> 56) We don't need to generate any code for the uint8(). Update #15090 Change-Id: Ie1ca4e32022dccf7f7bc42d531a285521fb67872 Reviewed-on: https://go-review.googlesource.com/28191 Run-TryBot: Keith Randall <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: David Chase <[email protected]>
1 parent deb4177 commit ac74225

File tree

2 files changed

+398
-0
lines changed

2 files changed

+398
-0
lines changed

src/cmd/compile/internal/ssa/gen/generic.rules

+14
Original file line numberDiff line numberDiff line change
@@ -602,6 +602,20 @@
602602
(Trunc32to16 (And32 (Const32 [y]) x)) && y&0xFFFF == 0xFFFF -> (Trunc32to16 x)
603603
(Trunc16to8 (And16 (Const16 [y]) x)) && y&0xFF == 0xFF -> (Trunc16to8 x)
604604

605+
(ZeroExt8to64 (Trunc64to8 x:(Rsh64Ux64 _ (Const64 [s])))) && s >= 56 -> x
606+
(ZeroExt16to64 (Trunc64to16 x:(Rsh64Ux64 _ (Const64 [s])))) && s >= 48 -> x
607+
(ZeroExt32to64 (Trunc64to32 x:(Rsh64Ux64 _ (Const64 [s])))) && s >= 32 -> x
608+
(ZeroExt8to32 (Trunc32to8 x:(Rsh32Ux64 _ (Const64 [s])))) && s >= 24 -> x
609+
(ZeroExt16to32 (Trunc32to16 x:(Rsh32Ux64 _ (Const64 [s])))) && s >= 16 -> x
610+
(ZeroExt8to16 (Trunc16to8 x:(Rsh16Ux64 _ (Const64 [s])))) && s >= 8 -> x
611+
612+
(SignExt8to64 (Trunc64to8 x:(Rsh64x64 _ (Const64 [s])))) && s >= 56 -> x
613+
(SignExt16to64 (Trunc64to16 x:(Rsh64x64 _ (Const64 [s])))) && s >= 48 -> x
614+
(SignExt32to64 (Trunc64to32 x:(Rsh64x64 _ (Const64 [s])))) && s >= 32 -> x
615+
(SignExt8to32 (Trunc32to8 x:(Rsh32x64 _ (Const64 [s])))) && s >= 24 -> x
616+
(SignExt16to32 (Trunc32to16 x:(Rsh32x64 _ (Const64 [s])))) && s >= 16 -> x
617+
(SignExt8to16 (Trunc16to8 x:(Rsh16x64 _ (Const64 [s])))) && s >= 8 -> x
618+
605619
(Slicemask (Const32 [x])) && x > 0 -> (Const32 [-1])
606620
(Slicemask (Const32 [0])) -> (Const32 [0])
607621
(Slicemask (Const64 [x])) && x > 0 -> (Const64 [-1])

0 commit comments

Comments
 (0)