From ac0ab1842de0e4522248ff9805c5c4e3267c8ae7 Mon Sep 17 00:00:00 2001 From: "H.J. Lu" Date: Thu, 12 Dec 2019 12:25:48 -0800 Subject: [PATCH] i386: Also check R12-R15 registers when optimizing testq to testb Similar to SP, BP, SI and DI registers, R12-R15 registers must use REX prefix for the low byte register when optimizing test $imm7, %r64/%r32/%r16 -> test $imm7, %r8 PR gas/25274 * config/tc-i386.c (optimize_encoding): Also check R12-R15 registers for "test $imm7, %r64/%r32/%r16 -> test $imm7, %r8" optimization. * testsuite/gas/i386/x86-64-optimize-3.s: Add tests for test with r12. * testsuite/gas/i386/x86-64-optimize-3.d: Updated. * testsuite/gas/i386/x86-64-optimize-3b.d: Likewise. --- gas/ChangeLog | 11 +++++++++++ gas/config/tc-i386.c | 5 ++--- gas/testsuite/gas/i386/x86-64-optimize-3.d | 4 ++++ gas/testsuite/gas/i386/x86-64-optimize-3.s | 4 ++++ gas/testsuite/gas/i386/x86-64-optimize-3b.d | 4 ++++ 5 files changed, 25 insertions(+), 3 deletions(-) diff --git a/gas/ChangeLog b/gas/ChangeLog index 4675ec81769..48c5430855c 100644 --- a/gas/ChangeLog +++ b/gas/ChangeLog @@ -1,3 +1,14 @@ +2019-12-12 H.J. Lu + + PR gas/25274 + * config/tc-i386.c (optimize_encoding): Also check R12-R15 + registers for "test $imm7, %r64/%r32/%r16 -> test $imm7, %r8" + optimization. + * testsuite/gas/i386/x86-64-optimize-3.s: Add tests for test + with r12. + * testsuite/gas/i386/x86-64-optimize-3.d: Updated. + * testsuite/gas/i386/x86-64-optimize-3b.d: Likewise. + 2019-12-12 H.J. Lu * testsuite/gas/i386/align-branch-1.s: New file. diff --git a/gas/config/tc-i386.c b/gas/config/tc-i386.c index 6c71fc4d223..0dc44a89a2e 100644 --- a/gas/config/tc-i386.c +++ b/gas/config/tc-i386.c @@ -4008,10 +4008,9 @@ optimize_encoding (void) i.types[1].bitfield.byte = 1; /* Ignore the suffix. */ i.suffix = 0; - if (base_regnum >= 4 - && !(i.op[1].regs->reg_flags & RegRex)) + if (base_regnum >= 4) { - /* Handle SP, BP, SI and DI registers. */ + /* Handle SP, BP, SI, DI and R12-R15 registers. */ if (i.types[1].bitfield.word) j = 16; else if (i.types[1].bitfield.dword) diff --git a/gas/testsuite/gas/i386/x86-64-optimize-3.d b/gas/testsuite/gas/i386/x86-64-optimize-3.d index 66ed213b58a..26122dd4e1e 100644 --- a/gas/testsuite/gas/i386/x86-64-optimize-3.d +++ b/gas/testsuite/gas/i386/x86-64-optimize-3.d @@ -24,6 +24,10 @@ Disassembly of section .text: +[a-f0-9]+: 41 f6 c1 7f test \$0x7f,%r9b +[a-f0-9]+: 41 f6 c1 7f test \$0x7f,%r9b +[a-f0-9]+: 41 f6 c1 7f test \$0x7f,%r9b + +[a-f0-9]+: 41 f6 c4 7f test \$0x7f,%r12b + +[a-f0-9]+: 41 f6 c4 7f test \$0x7f,%r12b + +[a-f0-9]+: 41 f6 c4 7f test \$0x7f,%r12b + +[a-f0-9]+: 41 f6 c4 7f test \$0x7f,%r12b +[a-f0-9]+: 20 c9 and %cl,%cl +[a-f0-9]+: 66 21 d2 and %dx,%dx +[a-f0-9]+: 21 db and %ebx,%ebx diff --git a/gas/testsuite/gas/i386/x86-64-optimize-3.s b/gas/testsuite/gas/i386/x86-64-optimize-3.s index 45b418a6fd1..cbfed3bdf47 100644 --- a/gas/testsuite/gas/i386/x86-64-optimize-3.s +++ b/gas/testsuite/gas/i386/x86-64-optimize-3.s @@ -19,6 +19,10 @@ _start: test $0x7f, %r9d test $0x7f, %r9w test $0x7f, %r9b + test $0x7f, %r12 + test $0x7f, %r12d + test $0x7f, %r12w + test $0x7f, %r12b and %cl, %cl and %dx, %dx diff --git a/gas/testsuite/gas/i386/x86-64-optimize-3b.d b/gas/testsuite/gas/i386/x86-64-optimize-3b.d index 19ea29ac066..00b65f3d8b2 100644 --- a/gas/testsuite/gas/i386/x86-64-optimize-3b.d +++ b/gas/testsuite/gas/i386/x86-64-optimize-3b.d @@ -25,6 +25,10 @@ Disassembly of section .text: +[a-f0-9]+: 41 f7 c1 7f 00 00 00 test \$0x7f,%r9d +[a-f0-9]+: 66 41 f7 c1 7f 00 test \$0x7f,%r9w +[a-f0-9]+: 41 f6 c1 7f test \$0x7f,%r9b + +[a-f0-9]+: 41 f7 c4 7f 00 00 00 test \$0x7f,%r12d + +[a-f0-9]+: 41 f7 c4 7f 00 00 00 test \$0x7f,%r12d + +[a-f0-9]+: 66 41 f7 c4 7f 00 test \$0x7f,%r12w + +[a-f0-9]+: 41 f6 c4 7f test \$0x7f,%r12b +[a-f0-9]+: 84 c9 test %cl,%cl +[a-f0-9]+: 66 85 d2 test %dx,%dx +[a-f0-9]+: 21 db and %ebx,%ebx -- 2.30.2