From 91a2e921dd0bdb4d6437091f82b4b22527cafa94 Mon Sep 17 00:00:00 2001 From: erifan01 Date: Tue, 7 Mar 2023 08:44:08 +0800 Subject: cmd/compile: fix incorrect truncating when converting CMP to TST on arm64 CL 420434 optimized CMP into TST in some situations, but it has a bug, these four rules are not correct: (LessThan (CMPWconst [0] x:(ANDconst [c] y))) && x.Uses == 1 => (LessThan (TSTconst [c] y)) (LessEqual (CMPWconst [0] x:(ANDconst [c] y))) && x.Uses == 1 => (LessEqual (TSTconst [c] y)) (GreaterThan (CMPWconst [0] x:(ANDconst [c] y))) && x.Uses == 1 => (GreaterThan (TSTconst [c] y)) (GreaterEqual (CMPWconst [0] x:(ANDconst [c] y))) && x.Uses == 1 => (GreaterEqual (TSTconst [c] y)) But due to the existence of this rule (LessThan (CMPWconst [0] x:(ANDconst [c] y))) && x.Uses == 1 => (LessThan (TSTWconst [int32(c)] y)), the above rules have never been fired. This CL corrects them as: (LessThan (CMPconst [0] x:(ANDconst [c] y))) && x.Uses == 1 => (LessThan (TSTconst [c] y)) (LessEqual (CMPconst [0] x:(ANDconst [c] y))) && x.Uses == 1 => (LessEqual (TSTconst [c] y)) (GreaterThan (CMPconst [0] x:(ANDconst [c] y))) && x.Uses == 1 => (GreaterThan (TSTconst [c] y)) (GreaterEqual (CMPconst [0] x:(ANDconst [c] y))) && x.Uses == 1 => (GreaterEqual (TSTconst [c] y)) Change-Id: I7d60bcc9a266ee58388baeaab9f493b57cf1ad55 Reviewed-on: https://go-review.googlesource.com/c/go/+/473617 TryBot-Result: Gopher Robot Reviewed-by: Cherry Mui Reviewed-by: Dmitri Shuralyov Run-TryBot: Eric Fang --- test/codegen/comparisons.go | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'test/codegen') diff --git a/test/codegen/comparisons.go b/test/codegen/comparisons.go index c613e13ced..ee732e06d9 100644 --- a/test/codegen/comparisons.go +++ b/test/codegen/comparisons.go @@ -234,6 +234,8 @@ func CmpToZero(a, b, d int32, e, f int64, deOptC0, deOptC1 bool) int32 { c7 := e&(f<<3) < 0 // arm64:`CMN\sR[0-9]+<<3,\sR[0-9]+` c8 := e+(f<<3) < 0 + // arm64:`TST\sR[0-9],\sR[0-9]+` + c9 := e&17 < 0 if c0 { return 1 } else if c1 { @@ -252,6 +254,8 @@ func CmpToZero(a, b, d int32, e, f int64, deOptC0, deOptC1 bool) int32 { return 9 } else if c8 { return 10 + } else if c9 { + return 11 } else if deOptC0 { return b + d } else if deOptC1 { -- cgit v1.3-5-g9baa