<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">Hi All<div class=""><br class=""></div><div class="">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</div><div class=""><br class=""></div><div class="">I think we want to check if the clz(divisor) == (Num_word_bits - 1) rather than checking</div><div class="">(clz(divisor) - clz(dividend)) == (Num_word_bits - 1)</div><div class=""><br class=""></div><div class="">I also think compiler-rt should be updated - </div><div class=""><a href="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=" class="">http://llvm.org/svn/llvm-project/compiler-rt/trunk/lib/builtins/udivsi3.c</a></div><div class=""><br class=""></div><div class=""><pre style="word-wrap: break-word; white-space: pre-wrap;" class="">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;</pre><div class="">The last line should be replaced with </div></div><div class=""><span class="Apple-tab-span" style="white-space:pre">     </span></div><div class=""><span class="Apple-tab-span" style="white-space:pre">  </span>if ( __buildin_clz(d) == n_uword_bits - 1)</div><div class=""><span class="Apple-tab-span" style="white-space:pre">                </span>return n;</div><div class=""><br class=""></div><div class="">I have attached the LLVM patch here for the same.</div><div class=""></div></body></html>