[Bug middle-end/122871] [13/14/15/16/17 Regression] de-optimized synthesis of long long shift and add
cvs-commit at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Fri Jun 5 13:55:42 GMT 2026
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=122871
--- Comment #17 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Roger Sayle <sayle@gcc.gnu.org>:
https://gcc.gnu.org/g:373e2c30b1710e271664cf95fcfb66fea7dd15ed
commit r17-1373-g373e2c30b1710e271664cf95fcfb66fea7dd15ed
Author: Roger Sayle <roger@nextmovesoftware.com>
Date: Fri Jun 5 14:53:27 2026 +0100
PR target/56102: Improve rtx_costs from -mthumb on ARM.
This patch provides improved (more accurate) RTX costs for -mthumb on ARM.
My recent patch for double word multiplication, PR 122871, revealed that
the current costs for THUMB code on ARM are... let's say a little dubious.
To demonstrate the code generation improvements provided by better
thumb1_rtx_costs consider the function below (from PR middle-end/122871).
long long foo (long long a)
{
long long c = a << 33;
c += a;
return c;
}
With the ARM backend's current costs, this produces 11 instructions with
-O2 -mthumb.
Before: movs r3, r0
movs r2, #0
adds r2, r2, r0
adcs r3, r3, r1
adds r2, r2, r2
adcs r3, r3, r3
subs r2, r2, r0
sbcs r3, r3, r1
movs r0, r2
movs r1, r3
bx lr
With sane RTX costs, GCC now generate the much more reasonable 5 insns:
After: movs r2, #0
lsls r3, r0, #1
adds r0, r0, r2
adcs r1, r1, r3
bx lr
2026-06-05 Roger Sayle <roger@nextmovesoftware.com>
Richard Earnshaw <richard.earnshaw@arm.com>
gcc/ChangeLog
PR target/56102
PR middle-end/122871
* config/arm/arm.cc (thumb1_rtx_costs): Provide reasonable costs
for PLUS, MINUS, COMPARE, AND, XOR, IOR, NEG, NOT, ASHIFT,
ASHIFTRT and ROTATERT for SImode, DImode, HImode and QImode.
(thumb1_size_rtx_costs): Likewise.
(comp_not_to_clear_mask_str_un): Silence host compiler warning.
More information about the Gcc-bugs
mailing list