For e.g.
const char a[] = "test"; int i; char f(unsigned char u) { const char *p = a + u; i++; return(*p); }
SDCC knows that a is in code space. But that information is not propagated to p, so the *p is an inefficient (for mcs51 and pdk15) read from a generic pointer instead of a read from a cpointer.
Philipp
Feature request 160 https://sourceforge.net/p/sdcc/feature-requests/160/#af0e is probably related. It's about idata though.
(To compile the dated example "idata" needs to be prepended with dual underscore.)
I've observed that pointer type propagation does work sometimes.
Yes. There is some basic such functionality in SDCC now. But this is so important for generating efficient code for mcs51, SDCC needs to get better at it.
Maybe we could use some of the generalized constant propagation infrastructure for this (currently in the genconstprop branch, already very useful for integers).
Here is a simple code sample, that I want to use as test code for the improvements:
Currently, we call __gptrget four times, both for mcs51 and pdk. Let's see if we can do better for 4.4.0.
Last edit: Philipp Klaus Krause 2023-07-02
As of [r14202], the optimization works in the genconstprop branch. So far writes via pointers are not covered yet, but the more important case of reads is.
Related
Commit: [r14202]