On 8/8/24 11:10 AM, Raphael Moreira Zinsly wrote:
Improve handling of constants where the high half can be constructed
by shifting the low half.
gcc/ChangeLog:
* config/riscv/riscv.cc (riscv_build_integer): Detect constants
were the higher half is a shift of the lower half.
gcc/testsuite/ChangeLog:
* gcc.target/riscv/synthesis-12.c: New test.
Oh, nevermind. The test is a bit later than I expected to find it.
I'd move the test for equality after shifting to a point before you call
riscv_build_integer_1. That routine is more expensive than I'd like
with all the recursive calls and such, so let's do the relatively cheap
test first and only call riscv_build_integer_1 when there's a reasonable
chance we can optimize.
This code should also test ALLOW_NEW_PSEUDOS since we need cost
stability before/after reload.
Repost after those changes.
With this framework I think you could also handle the case where the
upper/lower vary by just one bit fairly trivially.
ie, when popcount (upper ^ lower) == 1 use binv to flip the bit high
word. Obviously this only applies when ZBS is enabled. If you want to
do this, I'd structure it largely like the shifted case.
And if high is +-2k from low, then there may be a synthesis for that
case as well.
And if the high word is 3x 5x or 9x the low word, then shadd applies.
Those three additional cases aren't required for this patch to move
forward. Just additional enhancements if you want to tackle them.
Jeff