cmd/compile: omit unnecessary boolean zero extension on arm64

On arm64, all boolean-generating instructions (CSET, etc.) set the upper
63 bits of the destination register to zero, so there is no need
to zero-extend the lower 8 bits again.

Fixes #21445

Change-Id: I3b176baab706eb684105400bacbaa24175f721f3
Reviewed-on: https://go-review.googlesource.com/55671
Run-TryBot: Cherry Zhang <cherryyz@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
This commit is contained in:
philhofer 2017-08-14 21:50:43 -07:00 committed by Cherry Zhang
parent eccd3ef526
commit 07ec4385f1
2 changed files with 16 additions and 0 deletions

View File

@ -1033,6 +1033,10 @@
(GreaterEqual (InvertFlags x)) -> (LessEqual x)
(GreaterEqualU (InvertFlags x)) -> (LessEqualU x)
// Boolean-generating instructions always
// zero upper bit of the register; no need to zero-extend
(MOVBUreg x) && x.Type.IsBoolean() -> (MOVDreg x)
// absorb flag constants into conditional instructions
(CSELULT _ y (FlagEQ)) -> y
(CSELULT x _ (FlagLT_ULT)) -> x

View File

@ -3790,6 +3790,18 @@ func rewriteValueARM64_OpARM64MOVBUreg_0(v *Value) bool {
v.AuxInt = int64(uint8(c))
return true
}
// match: (MOVBUreg x)
// cond: x.Type.IsBoolean()
// result: (MOVDreg x)
for {
x := v.Args[0]
if !(x.Type.IsBoolean()) {
break
}
v.reset(OpARM64MOVDreg)
v.AddArg(x)
return true
}
return false
}
func rewriteValueARM64_OpARM64MOVBload_0(v *Value) bool {