RFC: Value range propagation for if-else
Don via Digitalmars-d
digitalmars-d at puremagic.com
Fri Jun 20 00:53:16 PDT 2014
On Wednesday, 18 June 2014 at 06:40:21 UTC, Lionello Lunesu wrote:
> Hi,
> https://github.com/lionello/dmd/compare/if-else-range
>
> There, I've also added a __traits(intrange, <expression>) which
> returns a tuple with the min and max for the given expression.
> Destroy?
The compiler uses value range propagation in this {min, max}
form, but I think that's an implementation detail. It's well
suited for arithmetic operations, but less suitable for logical
operations. For example, this code can't overflow, but {min, max}
range propagation thinks it can.
ubyte foo ( uint a) {
return (a & 0x8081) & 0x0FFF;
}
For these types of expressions, {known_one_bits, known_zero_bits}
works better.
Now, you can track both types of range propagation
simultaneously, and I think we probably should improve our
implementation in that way. It would improve the accuracy in many
cases.
Question: If we had implemented that already, would you still
want the interface you're proposing here?
More information about the Digitalmars-d
mailing list