Skip to content

Commit b136f0c

Browse files
committed
cmd/compile: fix buggy AMD64 rewrite from CL 213058
CL 213058's "bonus optimization I noticed while working on this" turns out to be buggy. It would be correct for CMP, but not TEST. Fix it to use TEST semantics instead. This was breaking compilation with the upcoming Spectre mode. Change-Id: If2d4c3798ed182f35f0244febe74e68c61e4c61b Reviewed-on: https://go-review.googlesource.com/c/go/+/222853 Reviewed-by: Keith Randall <[email protected]>
1 parent 96dc044 commit b136f0c

2 files changed

Lines changed: 52 additions & 3 deletions

File tree

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1254,7 +1254,10 @@
12541254
(CMPWconst (ANDLconst _ [m]) [n]) && 0 <= int16(m) && int16(m) < int16(n) -> (FlagLT_ULT)
12551255
(CMPBconst (ANDLconst _ [m]) [n]) && 0 <= int8(m) && int8(m) < int8(n) -> (FlagLT_ULT)
12561256

1257-
(TEST(Q|L)const [c] (MOV(Q|L)const [c])) -> (FlagEQ)
1257+
// TESTQ c c sets flags like CMPQ c 0.
1258+
(TEST(Q|L)const [c] (MOV(Q|L)const [c])) && c == 0 -> (FlagEQ)
1259+
(TEST(Q|L)const [c] (MOV(Q|L)const [c])) && c < 0 -> (FlagLT_UGT)
1260+
(TEST(Q|L)const [c] (MOV(Q|L)const [c])) && c > 0 -> (FlagGT_UGT)
12581261

12591262
// TODO: DIVxU also.
12601263

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

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

0 commit comments

Comments
 (0)