[PATCH] D26818: Bug fix and a proposed improvement in integer division expansion

Vedant Kumar via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 29 16:53:09 PST 2016


Hi Dmitri,

Some people may have missed this review because llvm-commits wasn't initially
CC'd. I recommend abandoning the current review, and re-uploading the patch
with llvm-commits CC'd. It would also be good to specify at least one reviewer
and add tests to unittests/Transforms/Utils/IntegerDivision.cpp.

best,
vedant

> On Nov 29, 2016, at 4:22 PM, Dmitri Shtilman via llvm-commits <llvm-commits at lists.llvm.org> wrote:
> 
> Hi all,
> 
> Another improvement in integer division sw expansion and a bug fix.
> 
> The special case code in udiv expansion is currently broken, namely the check for divisor==1 :
> 
> // ; special-cases:
> // ;   %ret0_1      = icmp eq i32 %divisor, 0
> // ;   %ret0_2      = icmp eq i32 %dividend, 0
> // ;   %ret0_3      = or i1 %ret0_1, %ret0_2
> // ;   %tmp0        = tail call i32 @llvm.ctlz.i32(i32 %divisor, i1 true)
> // ;   %tmp1        = tail call i32 @llvm.ctlz.i32(i32 %dividend, i1 true)
> // ;   %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
> // ;   %retVal      = select i1 %ret0, i32 0, i32 %dividend
> // ;   %earlyRet    = or i1 %ret0, %retDividend
> // ;   br i1 %earlyRet, label %end, label %bb1
> 
> 
> The intention must have been to use %tmp0, not %sr:
> 
> // ;   %retDividend = icmp eq i32 %tmp0, 31
> 
> The following patch fixes this special case and also extends it to cover divisions by a power-of-2 which will be routed through a simple shift-right instead of going through the full division loop. Division by 1 will also go through the shift-right, yielding the dividend [shifted by 0]. Power-of-2 divisors are identified through adding trailing zeroes to the already calculated leading zeroes to verify that only one bit is set.
> 
> Please review.
> Dmitri
> 
> https://reviews.llvm.org/D26818
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits



More information about the llvm-commits mailing list