[llvm-commits] [llvm] r53271 - in /llvm/trunk: lib/Transforms/Scalar/InstructionCombining.cpp test/Transforms/InstCombine/2008-07-08-SubAnd.ll

Duncan Sands baldrick at free.fr
Thu Jul 10 00:12:31 PDT 2008


Hi,

> > However, since this seems to be a combination of two simplifications, namely
> > modulo arithmetic and the transform (& Mask & AndRHS -> & AndRHS), mightn't
> > it be better to teach instcombine about each simplification individually?
> > In fact I'm kind of surprised it doesn't do these already.
> 
> I don't quite follow. How else, besides the presence of an 'and' 
> instruction, would it know that's operating in a modulo space smaller 
> than the one defined by the bitwidth of the integer type?

Excellent question!  I hadn't though it through.

> Were you suggesting that we look for 'urem' instructions where the right 
> hand side isn't a power of 2? That wouldn't work correctly if the 
> subtraction were to wrap around.

Cases when urem would work are already transformed into 'and' I suppose?

Also, more generally you can transform
  (X binop Y) & Mask -> (X & Mask) binop (Y & Mask)
if binop = addition, subtraction or multiplication
and Mask = 2^X-1, because then &Mask is the same as
reducing modulo 2^X.

For example, in your (A - N) & AndMask example, if N&Mask = 0
then you can reduce this to A & AndMask.

Ciao,

Duncan.



More information about the llvm-commits mailing list