https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106677
--- Comment #9 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to Andrew Pinski from comment #8)
> One thing I Noticed:
> _43 = foo_6(D) + 24;
> ...
> _41 = _54 + 24;
> if (_41 != _43)
>
>
> There is a pattern if the lhs of pointer_plus is the same but not if the rhs
> is the same.
> the patterns (:2789):
> ```
> /* And similar for pointers. */
> (for op (eq ne)
> (simplify
> (op (pointer_plus @0 @1) (pointer_plus @0 @2))
> (op @1 @2)))
> (simplify
> (pointer_diff (pointer_plus @0 @1) (pointer_plus @0 @2))
> (if (TYPE_OVERFLOW_WRAPS (TREE_TYPE (@1)))
> (convert (minus @1 @2))))
> ```
> I don't know if that will help here though.
>
> Note there is the pointer_diff pattern for this further down:
> ```
> (simplify
> (pointer_diff (pointer_plus @0 @2) (pointer_plus @1 @2))
> (pointer_diff @0 @1))
> (simplify
> (pointer_diff (pointer_plus @@0 @1) (pointer_plus @0 @2))
> /* The second argument of pointer_plus must be interpreted as signed, and
> thus sign-extended if necessary. */
> (with { tree stype = signed_type_for (TREE_TYPE (@1)); }
> /* Use view_convert instead of convert here, as POINTER_PLUS_EXPR
> second arg is unsigned even when we need to consider it as signed,
> we don't want to diagnose overflow here. */
> (minus (convert (view_convert:stype @1))
> ```
>
> So adding one for ne/eq should be ok too. Let me see if it helps this case.
Just FYI, fold_comparison does this too. Just in this case forwprop because of
single use does not do the combine when calling fold_comparison. So this
pattern is needed if we are going to remove
combine_cond_expr_cond/forward_propagate_into_comparison_1 anyways.