On 9/9/26 3:41 AM, Jakub Jelinek wrote:
On Thu, Aug 06, 2026 at 05:31:50PM +0200, Jakub Jelinek wrote:
Turns out it doesn't prevent that, because match.pd has also
/* Associate (p +p off1) +p off2 as (p +p (off1 + off2)). */
(simplify
(pointer_plus (pointer_plus:s @0 @1) @3)
(pointer_plus @0 (plus @1 @3)))
#if GENERIC
(simplify
(pointer_plus (convert:s (pointer_plus:s @0 @1)) @3)
(pointer_plus (convert:type @0) (plus @1 @3)))
#endif
Guess I'll try the cxx_fold_pointer_plus_expression change you're proposing.
Actually cxx_fold_pointer_plus_expression can't help that much, the main
optimization is folding of (convert (pointer_plus @0 @1)) into
(pointer_plus (convert @0) @1) and similar optimizations, so upon
fold_convert, which isn't called just from cp_fold_convert, but many other
spots.
Yes? I was thinking that when cxx_fold_pointer_plus_expression sees
(pointer_plus (convert @0) @1) it can evaluate (pointer_plus @0 @1)
instead and then convert the result.
cxx_fold_pointer_plus_expression could help only with the above
mentioned (pointer_plus (convert:s (pointer_plus:s @0 @1)) @3)
simplification, but even that not reliably, it can trigger also on
(convert (pointer_plus (convert:s (pointer_plus:s @0 @1)) @3)) and again
hit during cp_fold.
I don't follow, why is that a problem?
Jason