sampsyo / bril

an educational compiler intermediate representation
https://capra.cs.cornell.edu/bril/
MIT License
569 stars 237 forks source link

LVN missed opportunity for eq? #99

Open Xazax-hun opened 3 years ago

Xazax-hun commented 3 years ago

As far as I understand, if two values have the same value number, they are guaranteed to be the same at runtime. As a result, for operator eq, if both operands have the same value number (even if they are not constants) we could fold the operator to a constant true.

Xazax-hun commented 3 years ago

Also for comparison operators, we might be able to fold when only one argument is constant. E.g. false && var.

sampsyo commented 3 years ago

Yeah, that seems quite plausible! I'd be happy to merge those identities in the example LVN implementation if they're not too tricky to implement.

cgyurgyik commented 3 years ago

Since bril doesn't support logical operators (please correct me if I'm wrong), this should be OK to close?

sampsyo commented 3 years ago

We do have and, or, and not: https://capra.cs.cornell.edu/bril/lang/core.html#logic

cgyurgyik commented 3 years ago

https://capra.cs.cornell.edu/bril/lang/core.html#logic

Well that's embarrassing. I'll get a patch in for this.