diff options
author | Jakub Jelinek <jakub@redhat.com> | 2023-07-02 17:36:33 +0200 |
---|---|---|
committer | Jakub Jelinek <jakub@redhat.com> | 2023-07-02 17:36:33 +0200 |
commit | 83733be3f7583f75f626c57e49679cfb9d877c5f (patch) | |
tree | f5fa16196ff2f8f3a0f5930ada2837b476ba21f1 /gcc | |
parent | 2f615b33dd61590a74e7758e19016250ade2b828 (diff) | |
download | gcc-83733be3f7583f75f626c57e49679cfb9d877c5f.zip gcc-83733be3f7583f75f626c57e49679cfb9d877c5f.tar.gz gcc-83733be3f7583f75f626c57e49679cfb9d877c5f.tar.bz2 |
tree-ssa-math-opts: Fix up ICE in match_uaddc_usubc [PR110508]
The match_uaddc_usubc matching doesn't require that the second
.{ADD,SUB}_OVERFLOW has REALPART_EXPR of its lhs used, only that there is
at most one. So, in the weird case where the REALPART_EXPR of it isn't
present, we shouldn't ICE trying to replace that REALPART_EXPR with
REALPART_EXPR of .U{ADD,SUB}C result.
2023-07-02 Jakub Jelinek <jakub@redhat.com>
PR tree-optimization/110508
* tree-ssa-math-opts.cc (match_uaddc_usubc): Only replace re2 with
REALPART_EXPR opf nlhs if re2 is non-NULL.
* gcc.dg/pr110508.c: New test.
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/testsuite/gcc.dg/pr110508.c | 9 | ||||
-rw-r--r-- | gcc/tree-ssa-math-opts.cc | 13 |
2 files changed, 17 insertions, 5 deletions
diff --git a/gcc/testsuite/gcc.dg/pr110508.c b/gcc/testsuite/gcc.dg/pr110508.c new file mode 100644 index 0000000..a1f8f55 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr110508.c @@ -0,0 +1,9 @@ +/* PR tree-optimization/110508 */ +/* { dg-do compile } */ +/* { dg-options "-O2" } */ + +void +foo (unsigned a, unsigned b, unsigned *c, _Bool d) +{ + __builtin_addc (a, b, d, c); +} diff --git a/gcc/tree-ssa-math-opts.cc b/gcc/tree-ssa-math-opts.cc index 701fce2..68fc518 100644 --- a/gcc/tree-ssa-math-opts.cc +++ b/gcc/tree-ssa-math-opts.cc @@ -4861,11 +4861,14 @@ match_uaddc_usubc (gimple_stmt_iterator *gsi, gimple *stmt, tree_code code) gsi_remove (&gsi2, true); /* Replace the re2 statement with __real__ of the newly added .UADDC/.USUBC call. */ - gsi2 = gsi_for_stmt (re2); - tree rlhs = gimple_assign_lhs (re2); - g = gimple_build_assign (rlhs, REALPART_EXPR, - build1 (REALPART_EXPR, TREE_TYPE (rlhs), nlhs)); - gsi_replace (&gsi2, g, true); + if (re2) + { + gsi2 = gsi_for_stmt (re2); + tree rlhs = gimple_assign_lhs (re2); + g = gimple_build_assign (rlhs, REALPART_EXPR, + build1 (REALPART_EXPR, TREE_TYPE (rlhs), nlhs)); + gsi_replace (&gsi2, g, true); + } if (rhs[2]) { /* If this is the arg1 + arg2 + (ovf1 + ovf2) or |