From baa33d8380e5a74a8709ed5790856c8d07739cc3 Mon Sep 17 00:00:00 2001 From: Eric Botcazou Date: Sat, 15 Oct 2016 18:46:02 +0000 Subject: [PATCH] optabs.c (expand_parity): Fix mode mismatch, add final conversion and keep looping on failure. * optabs.c (expand_parity): Fix mode mismatch, add final conversion and keep looping on failure. From-SVN: r241202 --- gcc/ChangeLog | 5 +++++ gcc/optabs.c | 18 +++++++++++++----- gcc/testsuite/ChangeLog | 6 ++++++ .../gcc.target/sparc/{popc.c => popc-1.c} | 0 gcc/testsuite/gcc.target/sparc/popc-2.c | 7 +++++++ 5 files changed, 31 insertions(+), 5 deletions(-) rename gcc/testsuite/gcc.target/sparc/{popc.c => popc-1.c} (100%) create mode 100644 gcc/testsuite/gcc.target/sparc/popc-2.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 2cf3f940d88..a5744845f15 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,8 @@ +2016-10-15 Eric Botcazou + + * optabs.c (expand_parity): Fix mode mismatch, add final conversion + and keep looping on failure. + 2016-10-14 David Malcolm * print-rtl-function.c (print_edge): Omit "(flags)" when none are diff --git a/gcc/optabs.c b/gcc/optabs.c index c5e9b4f8e13..f78d9989f05 100644 --- a/gcc/optabs.c +++ b/gcc/optabs.c @@ -2382,18 +2382,26 @@ expand_parity (machine_mode mode, rtx op0, rtx target) last = get_last_insn (); - if (target == 0) - target = gen_reg_rtx (mode); + if (target == 0 || GET_MODE (target) != wider_mode) + target = gen_reg_rtx (wider_mode); + xop0 = widen_operand (op0, wider_mode, mode, true, false); temp = expand_unop (wider_mode, popcount_optab, xop0, NULL_RTX, true); if (temp != 0) temp = expand_binop (wider_mode, and_optab, temp, const1_rtx, target, true, OPTAB_DIRECT); - if (temp == 0) - delete_insns_since (last); - return temp; + if (temp) + { + if (mclass != MODE_INT + || !TRULY_NOOP_TRUNCATION_MODES_P (mode, wider_mode)) + return convert_to_mode (mode, temp, 0); + else + return gen_lowpart (mode, temp); + } + else + delete_insns_since (last); } } } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 63eafa620dc..d3183332a4b 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2016-10-15 Eric Botcazou + + * gcc.target/sparc/popc.c: Rename to... + * gcc.target/sparc/popc-1.c: ...this. + * gcc.target/sparc/popc-2.c: New test. + 2016-10-15 Jerry DeLisle PR fortran/77972 diff --git a/gcc/testsuite/gcc.target/sparc/popc.c b/gcc/testsuite/gcc.target/sparc/popc-1.c similarity index 100% rename from gcc/testsuite/gcc.target/sparc/popc.c rename to gcc/testsuite/gcc.target/sparc/popc-1.c diff --git a/gcc/testsuite/gcc.target/sparc/popc-2.c b/gcc/testsuite/gcc.target/sparc/popc-2.c new file mode 100644 index 00000000000..8809f187de4 --- /dev/null +++ b/gcc/testsuite/gcc.target/sparc/popc-2.c @@ -0,0 +1,7 @@ +/* { dg-do compile } */ +/* { dg-options "-mcpu=niagara2 -Os" } */ + +int foo (unsigned long long l) +{ + return __builtin_parityll (l); +} -- 2.30.2