https://gcc.gnu.org/g:2fa2088a13bbfb37b900a623507bf2b4c15c1f1b
commit r17-968-g2fa2088a13bbfb37b900a623507bf2b4c15c1f1b Author: LIU Hao <[email protected]> Date: Fri May 29 12:17:53 2026 +0200 i386: Rewrite index*1+disp into base+disp Sometimes, GCC may synthesize an address like [index * 1 + displacement]. This commit rewrites that into [base + displacement], to eliminate the requirement of an SIB byte (which is always the case, as RSP isn't a valid index), and to allow a small displacement to be encoded in one byte. gcc/ChangeLog: * config/i386/i386.cc (ix86_decompose_address): Add a special case where there's no base, there's an index, and the scale is 1. gcc/testsuite/ChangeLog: * gcc.target/i386/rewrite-sib-without-base.c: New test. Signed-off-by: LIU Hao <[email protected]> Diff: --- gcc/config/i386/i386.cc | 4 ++++ gcc/testsuite/gcc.target/i386/rewrite-sib-without-base.c | 7 +++++++ 2 files changed, 11 insertions(+) diff --git a/gcc/config/i386/i386.cc b/gcc/config/i386/i386.cc index dd1f715b460b..ac8982964161 100644 --- a/gcc/config/i386/i386.cc +++ b/gcc/config/i386/i386.cc @@ -11504,6 +11504,10 @@ ix86_decompose_address (rtx addr, struct ix86_address *out) std::swap (base_reg, index_reg); } + /* Special case: rewrite index*1+disp into base+disp. */ + if (!base && index && scale == 1) + base = index, base_reg = index_reg, index = index_reg = NULL_RTX; + /* Special case: %ebp cannot be encoded as a base without a displacement. Similarly %r13. */ if (!disp && base_reg diff --git a/gcc/testsuite/gcc.target/i386/rewrite-sib-without-base.c b/gcc/testsuite/gcc.target/i386/rewrite-sib-without-base.c new file mode 100644 index 000000000000..6eaa384cce09 --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/rewrite-sib-without-base.c @@ -0,0 +1,7 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -masm=att" } */ +/* { dg-final { scan-assembler-not "\\(,%" } } */ + +_Complex a; +_Complex int b; +void c(void) { a = *(_Complex char *)__builtin_memset(&a, 1, 2) / b; }
