[Review]: Fix Integer Division Expansion special case of divide by 1

Aditya Nandakumar aditya_nandakumar at apple.com
Thu Jul 2 18:05:14 PDT 2015


http://reviews.llvm.org/D10904 <http://reviews.llvm.org/D10904>

Added to phabricator.

Aditya
> On Jul 2, 2015, at 12:26 PM, Aditya Nandakumar <aditya_nandakumar at apple.com> wrote:
> 
> Hi All
> 
> I think the handling of special case of divide by 1 is incorrect in udivsi3.c (compiler-rt) and it’s equivalent in llvm/lib/Transforms/Utils/IntegerDivision.cpp
> 
> I think we want to check if the clz(divisor) == (Num_word_bits - 1) rather than checking
> (clz(divisor) - clz(dividend)) == (Num_word_bits - 1)
> 
> I also think compiler-rt should be updated - 
> http://llvm.org/svn/llvm-project/compiler-rt/trunk/lib/builtins/udivsi3.c <https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_svn_llvm-2Dproject_compiler-2Drt_trunk_lib_builtins_udivsi3.c&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=mQ4LZ2PUj9hpadE3cDHZnIdEwhEBrbAstXeMaFoB9tg&m=pW4Q1JdZMBOl8hRJ5f7uP2klbSmXe6EUr3CajMv6lhQ&s=YhRty41MrEPazrXTJ1lTya7lpHm4bykiDBdAK8w2OtU&e=>
> 
> sr = __builtin_clz(d) - __builtin_clz(n);
>     /* 0 <= sr <= n_uword_bits - 1 or sr large */
>     if (sr > n_uword_bits - 1)  /* d > r */
>         return 0;
>     if (sr == n_uword_bits - 1)  /* d == 1 */
>         return n;
> The last line should be replaced with 
> 	
> 	if ( __buildin_clz(d) == n_uword_bits - 1)
> 		return n;
> 
> I have attached the LLVM patch here for the same.
> <DiffIntUnsignedDivision.patch>
> 
> Thanks
> Aditya
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150702/368fe975/attachment.html>


More information about the llvm-commits mailing list