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

Nuno Lopes nunoplopes at sapo.pt
Mon Sep 15 04:50:31 PDT 2014


This patch is incorrect:

$ ./alive.py < a.opt
----------------------------------------
Optimization: 1
Precondition: true
%1 = srem %x, %z
%2 = srem %y, %z
%3 = add %1, %2
%r = srem %3, %z
   =>
%6 = add %x, %y
%r = srem %6, %z

Done: 1
ERROR: Domain of definedness of Target is smaller than Source's for i2 %r

Example:
%x i2 = 1 (0x1)
%z i2 = 3 (0x3)
%1 i2 = 0 (0x0)
%y i2 = 1 (0x1)
%2 i2 = 0 (0x0)
%3 i2 = 0 (0x0)
%6 i2 = 2 (0x2)
Source value: 0 (0x0)
Target value: undef


Meaning that the optimized code is introducing undefined behaviour  
where the original code didn't have.

Nuno



Citando Ankur Garg <ankur29.garg at samsung.com>:

> Hi majnemer, suyog, dexonsmith,
>
> Hi Eveyone,
>
> This patch implements the following transformation
>
>  " ((X % Z) + (Y % Z)) % Z -> (X + Y) % Z "
>
> Please help in reviewing it.
>
> Regards,
> Ankur.
>
> http://reviews.llvm.org/D5351
>
> Files:
>   lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
>   test/Transforms/InstCombine/rem.ll

http://reviews.llvm.org/D5351






More information about the llvm-commits mailing list