public inbox for gcc-cvs@sourceware.org help / color / mirror / Atom feed
From: Richard Biener <rguenth@gcc.gnu.org> To: gcc-cvs@gcc.gnu.org Subject: [gcc r12-8974] tree-optimization/107647 - avoid FMA from SLP with -ffp-contract=off Date: Mon, 12 Dec 2022 11:20:42 +0000 (GMT) [thread overview] Message-ID: <20221212112042.2DDEC3AA8430@sourceware.org> (raw) https://gcc.gnu.org/g:a9fafa2f533e25c57528c0294e19a154197848dd commit r12-8974-ga9fafa2f533e25c57528c0294e19a154197848dd Author: Richard Biener <rguenther@suse.de> Date: Thu Nov 17 09:43:31 2022 +0100 tree-optimization/107647 - avoid FMA from SLP with -ffp-contract=off Only with -ffp-contract=fast we can synthesize FMA operations like vfmaddsub231ps, so properly guard the transform in SLP pattern detection. PR tree-optimization/107647 * tree-vect-slp-patterns.cc (addsub_pattern::recognize): Only allow FMA generation with -ffp-contract=fast for FP types. (complex_mul_pattern::matches): Likewise. * gcc.target/i386/pr107647.c: New testcase. (cherry picked from commit c5df8392c5848c0462558f41cdf6eab31db301cf) Diff: --- gcc/testsuite/gcc.target/i386/pr107647.c | 17 +++++++++++++++++ gcc/tree-vect-slp-patterns.cc | 15 +++++++++++---- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/gcc/testsuite/gcc.target/i386/pr107647.c b/gcc/testsuite/gcc.target/i386/pr107647.c new file mode 100644 index 00000000000..45fcb55d698 --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/pr107647.c @@ -0,0 +1,17 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -ffp-contract=off -mavx2 -mfma" } */ + +void cscal(int n, float da_r, float *x) +{ + for (int i = 0; i < n; i += 4) + { + float temp0 = da_r * x[i] - x[i+1]; + float temp1 = da_r * x[i+2] - x[i+3]; + x[i+1] = da_r * x[i+1] + x[i]; + x[i+3] = da_r * x[i+3] + x[i+2]; + x[i] = temp0; + x[i+2] = temp1; + } +} + +/* { dg-final { scan-assembler-not "fma" } } */ diff --git a/gcc/tree-vect-slp-patterns.cc b/gcc/tree-vect-slp-patterns.cc index 4b6384d7e25..5c6ce8729bd 100644 --- a/gcc/tree-vect-slp-patterns.cc +++ b/gcc/tree-vect-slp-patterns.cc @@ -1035,8 +1035,11 @@ complex_mul_pattern::matches (complex_operation_t op, auto_vec<slp_tree> left_op, right_op; slp_tree add0 = NULL; - /* Check if we may be a multiply add. */ + /* Check if we may be a multiply add. It's only valid to form FMAs + with -ffp-contract=fast. */ if (!mul0 + && (flag_fp_contract_mode == FP_CONTRACT_FAST + || !FLOAT_TYPE_P (SLP_TREE_VECTYPE (l0node[0]))) && vect_match_expression_p (l0node[0], PLUS_EXPR)) { auto vals = SLP_TREE_CHILDREN (l0node[0]); @@ -1501,9 +1504,13 @@ addsub_pattern::recognize (slp_tree_to_load_perm_map_t *, } /* Now we have either { -, +, -, + ... } (!l0add_p) or { +, -, +, - ... } - (l0add_p), see whether we have FMA variants. */ - if (!l0add_p - && vect_match_expression_p (SLP_TREE_CHILDREN (l0node)[0], MULT_EXPR)) + (l0add_p), see whether we have FMA variants. We can only form FMAs + if allowed via -ffp-contract=fast. */ + if (flag_fp_contract_mode != FP_CONTRACT_FAST + && FLOAT_TYPE_P (SLP_TREE_VECTYPE (l0node))) + ; + else if (!l0add_p + && vect_match_expression_p (SLP_TREE_CHILDREN (l0node)[0], MULT_EXPR)) { /* (c * d) -+ a */ if (vect_pattern_validate_optab (IFN_VEC_FMADDSUB, node))
reply other threads:[~2022-12-12 11:20 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20221212112042.2DDEC3AA8430@sourceware.org \ --to=rguenth@gcc.gnu.org \ --cc=gcc-cvs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).