From: Josh Bleecher Snyder Date: Thu, 23 Apr 2020 07:21:59 +0000 (-0700) Subject: cmd/compile: optimize x & 1 != 0 to x & 1 on amd64 X-Git-Tag: go1.15beta1~424 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=e7c187369149741f96c445c153be4fc6475bc365;p=gostls13.git cmd/compile: optimize x & 1 != 0 to x & 1 on amd64 Triggers a handful of times in std+cmd. Change-Id: I9bb8ce9a5f8bae2547cb61157cd8f256e1b63e76 Reviewed-on: https://go-review.googlesource.com/c/go/+/229602 Run-TryBot: Josh Bleecher Snyder TryBot-Result: Gobot Gobot Reviewed-by: Keith Randall --- diff --git a/src/cmd/compile/internal/ssa/gen/AMD64.rules b/src/cmd/compile/internal/ssa/gen/AMD64.rules index bda8429c5f..0b02301c7d 100644 --- a/src/cmd/compile/internal/ssa/gen/AMD64.rules +++ b/src/cmd/compile/internal/ssa/gen/AMD64.rules @@ -571,6 +571,10 @@ (SETB (TEST(Q|L|W|B) x x)) -> (ConstBool [0]) (SETAE (TEST(Q|L|W|B) x x)) -> (ConstBool [1]) +// x & 1 != 0 -> x & 1 +(SETNE (TEST(B|W)const [1] x)) => (AND(L|L)const [1] x) +(SETB (BT(L|Q)const [0] x)) => (AND(L|Q)const [1] x) + // Recognize bit tests: a&(1<