[nvptx PATCH] Implement rtx_costs target hook for nvptx backend.
Roger Sayle
roger@nextmovesoftware.com
Thu Jul 11 16:54:00 GMT 2024
This patch adds support for TARGET_RTX_COSTS to the nvptx backend.
Currently, nvptx uses GCC's default instruction timing estimates,
but this patch provides (slightly) more accurate timings. The
most significant difference is that integer division is much slower
(relatively) than other instructions, so the compiler should be
making more use of the middle-end's expand_divmod.
For an example of the benefit consider:
int foo(unsigned int x)
{
return x/10;
}
currently with -O2 we generate:
.visible .func (.param.u32 %value_out) foo (.param.u32 %in_ar0)
{
.reg.u32 %value;
.reg.u32 %ar0;
ld.param.u32 %ar0, [%in_ar0];
.reg.u32 %r24;
mov.u32 %r24, %ar0;
div.u32 %value, %r24, 10;
st.param.u32 [%value_out], %value;
ret;
}
but with this patch, we now generate:
.visible .func (.param.u32 %value_out) foo (.param.u32 %in_ar0)
{
.reg.u32 %value;
.reg.u32 %ar0;
ld.param.u32 %ar0, [%in_ar0];
.reg.u32 %r24;
.reg.u32 %r26;
mov.u32 %r24, %ar0;
mul.hi.u32 %r26, %r24, -858993459;
shr.u32 %value, %r26, 3;
st.param.u32 [%value_out], %value;
ret;
}
The performance benefits can be seen/measured by the attached
microbenchmark, bench.c, when run with nvptx-none-run-single.
Before:
result = 266546680000
19004366269 ticks
15.203493 seconds
After:
result = 266546680000
5153988012 ticks
4.123190 seconds
So about a 3.7x performance improvement.
This patch has been tested with make and make -k check for nvptx-none
hosted on x86_64-pc-linux-gnu with no new failures. Ok for mainline?
2024-07-11 Roger Sayle <roger@nextmovesoftware.com>
gcc/ChangeLog
* config/nvptx/nvptx.cc (nvptx_rtx_size_costs): New function to
estimate the size of an RTX expression (in ptxas instructions).
(nvptx_rtx_costs): Implementation of rtx_costs target hook.
(TARGET_RTX_COSTS): Define to nvptx_rtx_costs.
gcc/testsuite/ChangeLog
* gcc.target/nvptx/div10.c: New test case.
Thanks in advance,
Roger
--
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: patchc6.txt
URL: <https://gcc.gnu.org/pipermail/gcc-patches/attachments/20240711/584b5092/attachment.txt>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: bench.c
URL: <https://gcc.gnu.org/pipermail/gcc-patches/attachments/20240711/584b5092/attachment.c>
More information about the Gcc-patches
mailing list