Hi! On Tue, Sep 23, 2025 at 07:29:35PM +0530, Kishan Parmar wrote: > When expanding logical operations with constant operands, GCC currently > splits >= 16-bit constants into 16-bit pieces during expand, every time > the constant appears. This results in repeated immediate synthesis and > later passes not being able to see that the same constant was used > multiple times. > > This patch adjusts the costing so that if the constant is wider than > 16-bits, operations such as IOR, XOR, PLUS, and MINUS treat the > constant operand as COSTS_N_INSNS (2) instead of (1). As a result, > the constants >= 16-bits will materialized every time into a reg. > > By forcing larger constants into registers, later RTL optimizations can > see the common value and generate shorter sequences. The final reload > pass handles splitting the constant into lis/ori as needed, but only > once, rather than repeatedly during expansion.
Why would that be better? The current scheme allows us to handle things better if you have both 0x12345678 and 0x12349999 constants in one routine. Such things happen a lot, and even more if the two things are addresses (pointers to different fields of the same struct, say). Did you run any benchmarks with it? Did you investigate generated code and see that your new scheme gets better results? We need some of that! It also needs testing with more than just ELFv2 LE. Segher
