[PATCH] D10904: Fix Integer Division Expansion special case of divide by 1
Aditya Nandakumar
aditya_nandakumar at apple.com
Thu Jul 2 13:13:40 PDT 2015
aditya_nandakumar created this revision.
aditya_nandakumar added a reviewer: llvm-commits-list.
aditya_nandakumar set the repository for this revision to rL LLVM.
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
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;
rL LLVM
http://reviews.llvm.org/D10904
Files:
lib/Transforms/Utils/IntegerDivision.cpp
Index: lib/Transforms/Utils/IntegerDivision.cpp
===================================================================
--- lib/Transforms/Utils/IntegerDivision.cpp
+++ lib/Transforms/Utils/IntegerDivision.cpp
@@ -244,7 +244,7 @@
// ; %sr = sub nsw i32 %tmp0, %tmp1
// ; %ret0_4 = icmp ugt i32 %sr, 31
// ; %ret0 = or i1 %ret0_3, %ret0_4
- // ; %retDividend = icmp eq i32 %sr, 31
+ // ; %retDividend = icmp eq i32 %tmp0, 31
// ; %retVal = select i1 %ret0, i32 0, i32 %dividend
// ; %earlyRet = or i1 %ret0, %retDividend
// ; br i1 %earlyRet, label %end, label %bb1
@@ -257,7 +257,7 @@
Value *SR = Builder.CreateSub(Tmp0, Tmp1);
Value *Ret0_4 = Builder.CreateICmpUGT(SR, MSB);
Value *Ret0 = Builder.CreateOr(Ret0_3, Ret0_4);
- Value *RetDividend = Builder.CreateICmpEQ(SR, MSB);
+ Value *RetDividend = Builder.CreateICmpEQ(Tmp0, MSB);
Value *RetVal = Builder.CreateSelect(Ret0, Zero, Dividend);
Value *EarlyRet = Builder.CreateOr(Ret0, RetDividend);
Builder.CreateCondBr(EarlyRet, End, BB1);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D10904.28970.patch
Type: text/x-patch
Size: 1101 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150702/cbacaff6/attachment.bin>
More information about the llvm-commits
mailing list