[LLVMdev] A pass to minimize instruction bitwidth?

Andrew Canis andrewcanis at gmail.com
Wed Aug 31 14:14:35 PDT 2011


Does llvm have a pass that minimizes the bitwidth of llvm instructions?
For instance:

  %8 = and i32 %7, 63

63 is 111111 in binary. So the 'and' instruction only requires 6 bits.

We could rewrite the above code as:
  %8 = trunc i32 %7 to i6
  %9 = and i6 %8, 63

Since we only need the lower 6 bits we could also propagate this
change backwards to reduce the bitwidth of prior instructions.
I'm synthesizing hardware from LLVM IR so these non-standard bitwidths
can actually save chip area.
I've started writing a pass to do this but I figured there might be an
existing pass for downcasting 64-bit operations to 32-bit operations
that I could borrow code from.

Thanks,
Andrew




More information about the llvm-dev mailing list