[LLVMdev] InstCombine adds bit masks, confuses self, others
Jakob Stoklund Olesen
stoklund at 2pi.dk
Tue Apr 17 10:57:27 PDT 2012
On Apr 17, 2012, at 6:35 AM, Rafael EspĂndola <rafael.espindola at gmail.com> wrote:
> I also agree that the pipeline should first make the IL canonical, and
> then decide what is the best way to compute the canonical form. The
> one thing I find unfortunate is that in LLVM the second step is almost
> all in DAG and MI levels. There is no point were we have IL passes
> that known more about the target.
Note that adding the bit masks does make sense as a canonical form, it is not just a premature optimization.
Expressions like x >> 2 << 3 >> 5 << 6 get canonicalized to a single shift + a mask that way.
I think it would make sense to leave the last shl alone, so the above expression gets canonicalized to:
((x >> 4) & mask) << 6
DAGCombine can reduce it completely if it wants.
This also matches the code generated for the bit field access in my small2.c example:
entry:
%and = lshr i64 %d, 2
%div = and i64 %and, 63
%add.ptr.sum = shl nuw nsw i64 %div, 1
/jakob
More information about the llvm-dev
mailing list