[llvm-dev] tracking known operand bits across passes

Steve King via llvm-dev llvm-dev at lists.llvm.org
Wed Oct 28 11:58:58 PDT 2015

Hello LLVM,

tl;dr:  Is there a reasonable way to track known operand bits all the
way to a pre-emit pass?

Long version:

For code size optimization, targets like x86 could use operand
known-zero and known-one bits.  For example, a 16-bit 'andw' can be
promoted to a cheaper 32-bit 'andl' so long as an operand has amenable
zero bits.

So far, experiments making this work in my own target have failed.

During lowering, DAG.computeKnownBits() tells me what I need to know.
I can promote the operation here and add a leading zero-extend and
trailing truncate.  Subsequent DAG processing just strips ext/trunc
back off, leaving me with the original node again and in an endless
lowering loop.

Since the promotion is really an encoding trick, not a logical change
to the program, perhaps the best place to promote an andw to andl is
in a late pre-emit pass.  Is that reasonable and can anyone outline
the right approach?


More information about the llvm-dev mailing list