]> git.feebdaed.xyz Git - 0xmirror/gcc.git/commit
x86: improve lea peepholes
authorAlexandre Oliva <oliva@adacore.com>
Wed, 10 Dec 2025 23:56:17 +0000 (20:56 -0300)
committerAlexandre Oliva <oliva@gnu.org>
Wed, 10 Dec 2025 23:58:02 +0000 (20:58 -0300)
commit0ff1ea6a6a2ec7dc57c962920e790d94cd286f39
tree89417c4cd98b7a561d12780b4a1da0127dab6a1d
parent7a54d49061ef6a6720a4955f07d0ec2c1d7d4560
x86: improve lea peepholes

gcc.target/i386/lea-3.c fails on ia32 with PIE enabled by default.
There are two reasons for that:

- setting up the PIC register requires one addl instruction, and the
  testcase wants none

- the expected lea-combining peephole doesn't get applied for two
  reasons:

-- the second insn of the pair that could be turned into a single lea
   doesn't clobber CC, but the existing peephole2 requires an add with
   such a clobber

-- the first and second insns set different regs, and the existing
   peephole2 requires them to be the same

Add extra peephole2s for when the second insn doesn't clobber CC, and
for when the first set reg is different, but it dies at the second
insn.

Adjust lea-3.c to run with -fno-PIE, and add lea-4.c with -fPIE.

The last of the newly-added peephole2s, that enables lea-4.c to pass,
also hits during an i686-linux-gnu bootstrap (without PIE enabled),
while building shared libraries for the target.  I haven't been able
to exercise the other 2, but I haven't tried very hard, and I see no
why they couldn't possibly hit, so I left them in.

for  gcc/ChangeLog

* config/i386/i386.md (lea peephole2): Add 3 new variants.

for  gcc/testsuite/ChangeLog

* gcc.target/i386/lea-3.c: Add -fno-PIE.
* gcc.target/i386/lea-4.c: New, with -fPIE.
gcc/config/i386/i386.md
gcc/testsuite/gcc.target/i386/lea-3.c
gcc/testsuite/gcc.target/i386/lea-4.c [new file with mode: 0644]