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;