Skip to content

Commit 8ab42a9

Browse files
committed
cmd/compile: merge ANDconst and UBFX into UBFX on arm64
Add a new rewrite rule to merge ANDconst and UBFX into UBFX. Add test cases. Change-Id: I24d6442d0c956d7ce092c3a3858d4a3a41771670 Reviewed-on: https://go-review.googlesource.com/c/go/+/377054 Trust: Fannie Zhang <Fannie.Zhang@arm.com> Reviewed-by: Cherry Mui <cherryyz@google.com> Run-TryBot: Cherry Mui <cherryyz@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
1 parent a10a209 commit 8ab42a9

File tree

3 files changed

+47
-1
lines changed

3 files changed

+47
-1
lines changed

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1918,7 +1918,11 @@
19181918
// (x & ac) >> sc
19191919
(SRLconst [sc] (ANDconst [ac] x)) && isARM64BFMask(sc, ac, sc)
19201920
=> (UBFX [armBFAuxInt(sc, arm64BFWidth(ac, sc))] x)
1921-
1921+
// merge ANDconst and ubfx into ubfx
1922+
(ANDconst [c] (UBFX [bfc] x)) && isARM64BFMask(0, c, 0) =>
1923+
(UBFX [armBFAuxInt(bfc.getARM64BFlsb(), min(bfc.getARM64BFwidth(), arm64BFWidth(c, 0)))] x)
1924+
(UBFX [bfc] (ANDconst [c] x)) && isARM64BFMask(0, c, 0) && bfc.getARM64BFlsb() + bfc.getARM64BFwidth() <= arm64BFWidth(c, 0) =>
1925+
(UBFX [bfc] x)
19221926
// merge ubfx and zerso-extension into ubfx
19231927
(MOVWUreg (UBFX [bfc] x)) && bfc.getARM64BFwidth() <= 32 => (UBFX [bfc] x)
19241928
(MOVHUreg (UBFX [bfc] x)) && bfc.getARM64BFwidth() <= 16 => (UBFX [bfc] x)

src/cmd/compile/internal/ssa/rewriteARM64.go

Lines changed: 36 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/codegen/bitfield.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,12 @@ func ubfx15(x uint64) bool {
321321
return false
322322
}
323323

324+
// merge ANDconst and ubfx into ubfx
325+
func ubfx16(x uint64) uint64 {
326+
// arm64:"UBFX\t[$]4, R[0-9]+, [$]6",-"AND\t[$]63"
327+
return ((x >> 3) & 0xfff) >> 1 & 0x3f
328+
}
329+
324330
// Check that we don't emit comparisons for constant shifts.
325331
//go:nosplit
326332
func shift_no_cmp(x int) int {

0 commit comments

Comments
 (0)