[Review]: Fix Integer Division Expansion special case of divide by 1
Aditya Nandakumar
aditya_nandakumar at apple.com
Thu Jul 2 12:26:52 PDT 2015
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 <http://llvm.org/svn/llvm-project/compiler-rt/trunk/lib/builtins/udivsi3.c>
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.
Thanks
Aditya
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150702/eceabd98/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: DiffIntUnsignedDivision.patch
Type: application/octet-stream
Size: 1268 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150702/eceabd98/attachment.obj>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150702/eceabd98/attachment-0001.html>
More information about the llvm-commits
mailing list