[llvm-dev] Proposal: virtual constant propagation

Peter Collingbourne via llvm-dev llvm-dev at lists.llvm.org
Thu Jan 28 10:41:54 PST 2016


On Thu, Jan 28, 2016 at 09:48:05AM -0800, Xinliang David Li wrote:
> Peter,
> 
> Interesting idea. One small extension that can be done is to allow the
> optimization to work on a value range. For instance, if the argument type
> is has know limited range (enum for instance), you can still optimize it
> when the argument is not a constant via proper bit mapping/shifting. In
> your example, the following is also devirtualizable.
> 
> bool g(Base *b, Type t) {
>   return b->isOfType(t);
> }

Yes, but we'd need to be careful about this, as the C++ standard rules for
enum ranges are rather complicated. See:

http://stackoverflow.com/questions/18195312/what-happens-if-you-static-cast-invalid-value-to-enum-class

Thanks,
-- 
Peter


More information about the llvm-dev mailing list