On 5/16/25 02:35, Richard Biener wrote:
On Thu, May 15, 2025 at 7:02 PM Andrew MacLeod <amacl...@redhat.com> wrote:
Recent changes to get_range_from_bitmask can sometimes turn a small
range into an undefined one if the bitmask indicates the bits make all
values impossible.
range_cast () was not expecting this and checks for UNDEFINED before
peforming the cast. It also needs to check for it after the cast now.
in this testcase, the pattern is
y = x * 4 <- we know y will have the bottom 2 bits cleared
z = Y + 7 <- we know z will have the bottom 2 bit set.
then a switch checks for z == 128 | z== 129 and performs a store into
*(int *)y
eventually the store is eliminated as unreachable, but range analysis
recognizes that the value is UNDEFINED when [121, 122] with the last 2
bits having to be 11 is calculated :-P
Do the default for casts, and if the result is UNDEFINED, turn it into
VARYING.
Bootstrapped on x86_64-pc-linux-gnu with no regressions. Pushed.
For unreachable code it probably does not matter much. but IMO dropping
from UNDEFINED to VARYING within the core ranger is pessimizing
and could end up papering over issues that would otherwise show up.
IMO such UNDEFINED -> VARYING should happen at the consumer
side or alternatively a uppermost API layer that's not used from within
ranger itself.
Richard.
Its been a while since I visited this, but for most of the fold
operations we turn UNDEFINED into VARYING because of the potential
double meaning of UNDEFINED. ISTR that an uninitialized local can also
show up as UNDEFINED, but we are not allowed to actually remove uses of
it, we have to treat it as VARYING or bad things happen. Its value
truly can be VARYING in that case because its a garbage value.
Most operations start with:
if (empty_range_varying (r, type, op1, op2))
return true;
which checks if either operand is UNDEFINED and sets the return result
to VARYING before going any further. In the case of the fold operation
in the patch, it did that, but then the value changed to UNDEFINED
during processing of the cast, so i needed to check again.
Anything that is truly UNDEFINED will have an edge leading to it that is
unexecutable and should be removed somewhere.
Andrew