On Fri, May 15, 2026 at 10:40 AM Uros Bizjak <[email protected]> wrote: > > On Fri, May 15, 2026 at 3:46 AM Liu, Hongtao <[email protected]> wrote: > > > > > > > > > -----Original Message----- > > > From: Roger Sayle <[email protected]> > > > Sent: Friday, May 15, 2026 5:23 AM > > > To: 'GCC Patches' <[email protected]> > > > Cc: 'Hongtao Liu' <[email protected]>; Liu, Hongtao > > > <[email protected]>; 'Uros Bizjak' <[email protected]> > > > Subject: [PATCH] Improve vector increment/decrement on x86. > > > > > > > > > This patch improves the code generated by the i386 backend for > > > incrementing > > > (adding one to) and decrementing (subtracting one from) a vector. With > > > SSE > > > materializing the vector -1 is more efficient than materializing the > > > vector +1, > > > hence x + 1 (increment) is better expressed as x - (-1), and x - 1 > > > (decrement) is > > > better expressed as x + (-1). Conveniently the relevant additions and > > > subtractions are specified as a single pattern, using a plusminus > > > iterator, in the > > > machine description. > > > > Can we add pre_reload define_insn_and_split for them, > > > > (set (reg:V16QI 100 [ _2 ]) > > (minus:V16QI (reg:V16QI 107 [ x ]) > > (const_vector:V16QI [ > > (const_int 1 [0x1]) repeated x16 > > ]))) > > > > Theoretically, it should be able to capture more optimization opportunities > > (if vector +/-1 is only exposed through RTL optimization)
Another issue is with insn canonicalization [1], where (minus x (const_int n)) is converted to (plus x (const_int -n)). According to the above, x - (-1) is not a canonical form and optimizers will convert it to the canonical form anyway. [1] https://gcc.gnu.org/onlinedocs/gccint/Insn-Canonicalizations.html Uros.
