I am working on a domain specific language where the basic data types
included unstructured bit patterns. For example, it is possible to
extract individual bits, bit ranges, etc from these unstructured bit
patterns. It turns out to be pretty convenient for the types of things
that I am doing.

I am compiling to Java source code. Obviously the bit patterns, which
currently are all smaller than 64 bits, must be represented in the
primitive type system of Java, which includes byte, short, int, long,
char, and boolean (I do not support floating point yet).

Is there any work, or any languages, for optimizing the conversion of
bit patterns. For example, signed / unsigned extension, truncation,
shifting, etc.

My goal is to write everything in bit patterns and have the compiler
do the job of scheduling the necessary conversions to / from various
primitive types as well as masking, shifting, etc.