[PATCH] Added InstCombine transform for pattern " ((X % Z) + (Y % Z)) % Z -> (X + Y) % Z ".

Nuno Lopes nunoplopes at sapo.pt
Sun Oct 19 02:52:28 PDT 2014


>>! In D5351#15, @ankur29.garg wrote:
> Hi nlopes,
> Thanks for reviewing the patch.
> 
> In the example you have stated,
> 
> %x i2 = 3
> 
> since we are talking about signed integers, that is equivalent to %x i2 = -1
> 
> Similarly, %y i2 = -1 and %z i2 = -1.
> 
> I am not sure how [%6 = add %x, %y] calculates to [%6 i2 = 2]. Shouldn't it be [%6 i2 = -2] ?
> 
> Please clarify.
> Thanks.

I think our output is now slightly better:
  Example:
  %x i4 = 0xC (12, -4)
  %z i4 = 0xF (15, -1)
  %y i4 = 0xC (12, -4)
  %1 i4 = 0x0 (0)
  %2 i4 = 0x0 (0)
  %3 i4 = 0x0 (0)
  %6 i4 = 0x8 (8, -8)
  Source value: 0x0 (0)
  Target value: undef

The idea is that %6 is INT_MIN and %z=-1. And so we get 'srem INT_MIN, -1', which is undefined behavior per the manual (http://llvm.org/docs/LangRef.html#srem-instruction).

http://reviews.llvm.org/D5351






More information about the llvm-commits mailing list