From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1386) id 8BA553896C0B; Fri, 21 Jun 2024 06:36:19 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8BA553896C0B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1718951779; bh=/KYVYEScqcxI4jHbh7WxM2YbQMnP+PM0z59sT2Td/yM=; h=From:To:Subject:Date:From; b=VUkKfXEBCQ5PrId1a796g1anUga3uPeC/tdQ+ycS6Aou0j7Ct+jwHj7D81LySmZ4Y chkhlGFmA2WVqaPaZuWtk/uDTBmrgBDfhnJsUrtFgZtdSmP2Qz46AeyY+sZHTeuluH Irp6ETnd93gOHyHYnffqj040jr5+KCV+nEZ06e2E= Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Jan Beulich To: binutils-cvs@sourceware.org Subject: [binutils-gdb] x86: don't suppress errors when optimizing X-Act-Checkin: binutils-gdb X-Git-Author: Jan Beulich X-Git-Refname: refs/heads/master X-Git-Oldrev: 4ad2348edbf43a3d1a694fd5375680cb55e6b1c1 X-Git-Newrev: c68a6e5cadf333ab3d55443d3aed156415660600 Message-Id: <20240621063619.8BA553896C0B@sourceware.org> Date: Fri, 21 Jun 2024 06:36:19 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3Dc68a6e5cadf3= 33ab3d55443d3aed156415660600 commit c68a6e5cadf333ab3d55443d3aed156415660600 Author: Jan Beulich Date: Fri Jun 21 08:33:57 2024 +0200 x86: don't suppress errors when optimizing =20 Blindly ignoring any mnemonic suffix can't be quite right: Bad suffix / operand combinations still want flagging. Simply avoid optimizing in such situations. Diff: --- gas/config/tc-i386.c | 17 ++++++++++++++++- gas/testsuite/gas/i386/i386.exp | 1 + gas/testsuite/gas/i386/optimize-8.l | 4 ++++ gas/testsuite/gas/i386/optimize-8.s | 6 ++++++ 4 files changed, 27 insertions(+), 1 deletion(-) diff --git a/gas/config/tc-i386.c b/gas/config/tc-i386.c index b8fc3c43819..b8911c04436 100644 --- a/gas/config/tc-i386.c +++ b/gas/config/tc-i386.c @@ -4573,6 +4573,20 @@ check_hle (void) } } =20 +/* Helper for optimization (running ahead of process_suffix()), to make su= re we + convert only well-formed insns. @OP is the sized operand to cross check + against (typically a register). Checking against a single operand typi= cally + suffices, as match_template() has already honored CheckOperandSize. */ + +static bool is_plausible_suffix (unsigned int op) +{ + return !i.suffix + || (i.suffix =3D=3D BYTE_MNEM_SUFFIX && i.types[op].bitfield.byte) + || (i.suffix =3D=3D WORD_MNEM_SUFFIX && i.types[op].bitfield.word) + || (i.suffix =3D=3D LONG_MNEM_SUFFIX && i.types[op].bitfield.dword) + || (i.suffix =3D=3D QWORD_MNEM_SUFFIX && i.types[op].bitfield.qword); +} + /* Encode aligned vector move as unaligned vector move. */ =20 static void @@ -4758,6 +4772,7 @@ optimize_encoding (void) && i.reg_operands =3D=3D 1 && i.imm_operands =3D=3D 1 && !i.types[1].bitfield.byte + && is_plausible_suffix (1) && i.op[0].imms->X_op =3D=3D O_constant && fits_in_imm7 (i.op[0].imms->X_add_number)) { @@ -4768,7 +4783,7 @@ optimize_encoding (void) if (flag_code =3D=3D CODE_64BIT || base_regnum < 4) { i.types[1].bitfield.byte =3D 1; - /* Ignore the suffix. */ + /* Squash the suffix. */ i.suffix =3D 0; /* Convert to byte registers. 8-bit registers are special, RegRex64 and non-RegRex64 each have 8 registers. */ diff --git a/gas/testsuite/gas/i386/i386.exp b/gas/testsuite/gas/i386/i386.= exp index 2584c69bddc..e40b45fe990 100644 --- a/gas/testsuite/gas/i386/i386.exp +++ b/gas/testsuite/gas/i386/i386.exp @@ -615,6 +615,7 @@ if [gas_32_check] then { run_list_test "optimize-6a" "-I${srcdir}/$subdir -march=3D+noavx -al" run_dump_test "optimize-6b" run_list_test "optimize-7" "-I${srcdir}/$subdir -march=3D+noavx2 -al" + run_list_test "optimize-8" "-Os" run_dump_test "noopt" run_dump_test "lea-optimize" run_dump_test "lea16-optimize" diff --git a/gas/testsuite/gas/i386/optimize-8.l b/gas/testsuite/gas/i386/o= ptimize-8.l new file mode 100644 index 00000000000..af97d73a086 --- /dev/null +++ b/gas/testsuite/gas/i386/optimize-8.l @@ -0,0 +1,4 @@ +.*: Assembler messages: +.*:5: Error: .* `%ecx' .* suffix +.*:6: Error: .* `%cx' .* suffix +#pass diff --git a/gas/testsuite/gas/i386/optimize-8.s b/gas/testsuite/gas/i386/o= ptimize-8.s new file mode 100644 index 00000000000..9b68189f91d --- /dev/null +++ b/gas/testsuite/gas/i386/optimize-8.s @@ -0,0 +1,6 @@ +# Check bogus instructions are still rejected when optimizing + + .text +_start: + testw $4, %ecx + testl $4, %cx