]> git.ipfire.org Git - thirdparty/gcc.git/commit
math-opts: Only build FMA when use is in addends. [PR123940]
authorRobin Dapp <rdapp@oss.qualcomm.com>
Tue, 3 Feb 2026 20:24:33 +0000 (21:24 +0100)
committerRobin Dapp <rdapp@oss.qualcomm.com>
Fri, 6 Feb 2026 08:18:37 +0000 (09:18 +0100)
commitbd67b5a8c90194f7499981bbbc247fd45f8de6b9
tree18c3c6f83a836bb45a68b84f41e4dca783527870
parentbcb3b1eef1eca3ea62391fb3c0e6af549b4d9d02
math-opts: Only build FMA when use is in addends. [PR123940]

When looking for an FMA opportunity we can find a multiplication use in an
else operand:

  vect_pretmp_50.23_121 = MEM <vector(2) charD.2> [(charD.2 *)&dD.2916 + 14B];
  vect__28.25_123 = vect_pretmp_50.23_121 * { 2, 2 };
  vect_patt_99.26_124 = .COND_ADD ({ -1, -1 }, vect_pretmp_50.23_121, { 14, 15 }, vect__28.25_123);

and build it:
  vect_pretmp_50.23_121 = MEM <vector(2) charD.2> [(charD.2 *)&dD.2916 + 14B];
  vect_patt_99.26_124 = .FMA (vect_pretmp_50.23_121, { 2, 2 }, vect_pretmp_50.23_121);

This patch checks if the use is in one of the addends.

PR tree-optimization/123940

gcc/ChangeLog:

* tree-ssa-math-opts.cc (convert_mult_to_fma): Check
multiplication result is an addend.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/rvv/autovec/pr123940.c: New test.

Signed-off-by: Robin Dapp <rdapp@oss.qualcomm.com>
gcc/testsuite/gcc.target/riscv/rvv/autovec/pr123940.c [new file with mode: 0644]
gcc/tree-ssa-math-opts.cc