match-sat-alu.pd: Recognize more unsigned saturating subtraction forms

Equivalent unsigned saturating subtraction forms can reverse the comparison
operands or the conditional arms:

  B < A ? A - B : 0
  A < B ? 0 : A - B

The middle end can keep either comparison operand order.  Control flow with
two returns can also reverse the conditional arms.

Recognize both forms and reversed comparisons in the multiply-by-predicate
form.

AArch64 -O2:

before:

	sub	w2, w0, w1
	cmp	w1, w0
	csel	w0, w2, wzr, cc

after:

	subs	w0, w0, w1
	csel	w0, w0, wzr, cs

The vector form replaces a comparison, a subtraction, and an AND with one
UQSUB.

Bootstrapped and tested on aarch64-none-linux-gnu.

gcc/ChangeLog:

	* match-sat-alu.pd (unsigned_integer_sat_sub): Accept commuted
	comparison operand orders and the arm order from a two-return source.

gcc/testsuite/ChangeLog:

	* gcc.target/aarch64/sat_u_sub_swapped-1.c: New test.

Signed-off-by: Kyrylo Tkachov <ktkachov@nvidia.com>
2 files changed