From: Eric Botcazou Date: Sat, 15 Oct 2016 18:46:02 +0000 (+0000) Subject: optabs.c (expand_parity): Fix mode mismatch, add final conversion and keep looping... X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=baa33d8380e5a74a8709ed5790856c8d07739cc3;p=gcc.git 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 --- 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-1.c b/gcc/testsuite/gcc.target/sparc/popc-1.c new file mode 100644 index 00000000000..5442a610fa2 --- /dev/null +++ b/gcc/testsuite/gcc.target/sparc/popc-1.c @@ -0,0 +1,18 @@ +/* { dg-do compile } */ +/* { dg-options "-mcpu=niagara2" } */ +int test_popcount(int a) +{ + return __builtin_popcount(a); +} + +long test_popcountl(long a) +{ + return __builtin_popcountl(a); +} + +long long test_popcountll(long long a) +{ + return __builtin_popcountll(a); +} + +/* { dg-final { scan-assembler-times "popc\t%" 3 } } */ 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); +} diff --git a/gcc/testsuite/gcc.target/sparc/popc.c b/gcc/testsuite/gcc.target/sparc/popc.c deleted file mode 100644 index 5442a610fa2..00000000000 --- a/gcc/testsuite/gcc.target/sparc/popc.c +++ /dev/null @@ -1,18 +0,0 @@ -/* { dg-do compile } */ -/* { dg-options "-mcpu=niagara2" } */ -int test_popcount(int a) -{ - return __builtin_popcount(a); -} - -long test_popcountl(long a) -{ - return __builtin_popcountl(a); -} - -long long test_popcountll(long long a) -{ - return __builtin_popcountll(a); -} - -/* { dg-final { scan-assembler-times "popc\t%" 3 } } */