Skip to content

Commit 315dbd1

Browse files
committed
cmd/compile: fold double negate on arm64
Fixes #48467 Change-Id: I52305dbf561ee3eee6c1f053e555a3a6ec1ab892 Reviewed-on: https://go-review.googlesource.com/c/go/+/350910 Trust: Keith Randall <[email protected]> Trust: Josh Bleecher Snyder <[email protected]> Run-TryBot: Keith Randall <[email protected]> TryBot-Result: Go Bot <[email protected]> Reviewed-by: Josh Bleecher Snyder <[email protected]>
1 parent 83b36ff commit 315dbd1

File tree

3 files changed

+19
-0
lines changed

3 files changed

+19
-0
lines changed

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

+1
Original file line numberDiff line numberDiff line change
@@ -1363,6 +1363,7 @@
13631363
(XOR x (MVN y)) => (EON x y)
13641364
(OR x (MVN y)) => (ORN x y)
13651365
(MVN (XOR x y)) => (EON x y)
1366+
(NEG (NEG x)) => x
13661367

13671368
(CSEL [cc] (MOVDconst [-1]) (MOVDconst [0]) flag) => (CSETM [cc] flag)
13681369
(CSEL [cc] (MOVDconst [0]) (MOVDconst [-1]) flag) => (CSETM [arm64Negate(cc)] flag)

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

+10
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/codegen/bits.go

+8
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
package codegen
88

9+
import "math/bits"
10+
911
/************************************
1012
* 64-bit instructions
1113
************************************/
@@ -355,3 +357,9 @@ func issue44228b(a []int32, i int) bool {
355357
// amd64: "BTL", -"SHL"
356358
return a[i>>5]&(1<<(i&31)) != 0
357359
}
360+
361+
func issue48467(x, y uint64) uint64 {
362+
// arm64: -"NEG"
363+
d, borrow := bits.Sub64(x, y, 0)
364+
return x - d&(-borrow)
365+
}

0 commit comments

Comments
 (0)