match.pd: Extend pointer alignment folds

We have long had the fold:

/* Pattern match
     tem = (sizetype) ptr;
     tem = tem & algn;
     tem = -tem;
     ... = ptr p+ tem;
   and produce the simpler and easier to analyze with respect to alignment
     ... = ptr & ~algn;  */

But the gimple in gcc.target/aarch64/sve/pr98119.c has a variant in
which a constant is added before the conversion, giving:

     tem = (sizetype) (ptr p+ CST);
     tem = tem & algn;
     tem = -tem;
     ... = ptr p+ tem;

This case is also valid if algn fits within the trailing zero bits
of CST.  Adding CST then has no effect.

Similarly the testcase has:

     tem = (sizetype) (ptr p+ CST1);
     tem = tem & algn;
     tem = CST2 - tem;
     ... = ptr p+ tem;

This folds to:

     ... = (ptr & ~algn) p+ CST2;

if algn fits within the trailing zero bits of both CST1 and CST2.

An alternative would be:

     ... = (ptr p+ CST2) & ~algn;

but I would expect the alignment to be more easily shareable than
the CST2 addition, given that the CST2 addition wasn't being applied
by a POINTER_PLUS_EXPR.

gcc/
	* match.pd: Extend pointer alignment folds so that they handle
	the case where a constant is added before or after the alignment.

gcc/testsuite/
	* gcc.dg/pointer-arith-11.c: New test.
	* gcc.dg/pointer-arith-12.c: Likewise.
3 files changed