pru: Fix CLZ expansion for QI and HI modes
authorDimitar Dimitrov <dimitar@dinux.eu>
Sat, 21 Jan 2023 16:10:59 +0000 (18:10 +0200)
committerDimitar Dimitrov <dimitar@dinux.eu>
Sun, 22 Jan 2023 19:11:34 +0000 (21:11 +0200)
commitc517295940a23db8ca165dfd5d0edea4457eda49
treeb6d5382d85b8ff98fa167d43ccecebafdd22b689
parent011c0c29a2452e588f255673238460da4167c4c0
pru: Fix CLZ expansion for QI and HI modes

The recent gcc.dg/tree-ssa/clz-char.c test case failed for PRU target,
exposing a wrong code generation bug in the PRU backend.  The "clz"
pattern did not produce correct output for QI and HI input operand
modes.  SI mode is ok.

The "clz" pattern is expanded to an LMBD instruction to get the
left-most bit position having value "1".  In turn, to get the correct
"clz" value, that bit position must be subtracted from the MSB bit
position of the input operand.  The old behaviour of hard-coding 31
for MSB bit position is wrong.

The LMBD instruction returns 32 if input operand is zero, irrespective
of its register mode.  This maps nicely for SI mode, where the "clz"
pattern outputs -1.  It also leads to peculiar (but valid!) output
values from the "clz" pattern for QI and HI zero-valued inputs.

gcc/ChangeLog:

* config/pru/pru.h (CLZ_DEFINED_VALUE_AT_ZERO): Fix value for QI
and HI input modes.
* config/pru/pru.md (clz): Fix generated code for QI and HI
input modes.

gcc/testsuite/ChangeLog:

* gcc.target/pru/clz-hi-2.c: New test.
* gcc.target/pru/clz-hi.c: New test.

Signed-off-by: Dimitar Dimitrov <dimitar@dinux.eu>
gcc/config/pru/pru.h
gcc/config/pru/pru.md
gcc/testsuite/gcc.target/pru/clz-hi-2.c [new file with mode: 0644]
gcc/testsuite/gcc.target/pru/clz-hi.c [new file with mode: 0644]