<html><body><div><div class="" style="font-family: SFNSText, 'Helvetica Neue', Helvetica, sans-serif;" data-mce-style="font-family: SFNSText, 'Helvetica Neue', Helvetica, sans-serif;">Hi all,</div><div class="" style="font-family: SFNSText, 'Helvetica Neue', Helvetica, sans-serif;" data-mce-style="font-family: SFNSText, 'Helvetica Neue', Helvetica, sans-serif;"><br class=""></div><span style="font-family: SFNSText, 'Helvetica Neue', Helvetica, sans-serif;" data-mce-style="font-family: SFNSText, 'Helvetica Neue', Helvetica, sans-serif;">Another improvement in integer division sw expansion and a bug fix.</span><div class="" style="font-family: SFNSText, 'Helvetica Neue', Helvetica, sans-serif;" data-mce-style="font-family: SFNSText, 'Helvetica Neue', Helvetica, sans-serif;"><br class=""></div><div class="" style="font-family: SFNSText, 'Helvetica Neue', Helvetica, sans-serif;" data-mce-style="font-family: SFNSText, 'Helvetica Neue', Helvetica, sans-serif;"><p class="" style="margin: 0px 0px 12px; padding: 0px; border: 0px; font-variant-ligatures: normal; orphans: 2; widows: 2;" data-mce-style="margin: 0px 0px 12px; padding: 0px; border: 0px; font-variant-ligatures: normal; orphans: 2; widows: 2;">The special case code in udiv expansion is currently broken, namely the check for divisor==1 :</p><div class="remarkup-code-block repository-crossreference crossreference-cursor" style="margin: 12px 0px; padding: 0px; border: 0px; cursor: help; white-space: pre; font-variant-ligatures: normal; orphans: 2; widows: 2;" data-mce-style="margin: 12px 0px; padding: 0px; border: 0px; cursor: help; white-space: pre; font-variant-ligatures: normal; orphans: 2; widows: 2;"><pre class="remarkup-code" style="margin-top: 0px; margin-bottom: 0px; padding: 12px; border: 0px; background-color: rgba(71, 87, 120, 0.0784314); overflow: auto; border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; font-variant-ligatures: normal; font-variant-position: normal; font-variant-numeric: normal; font-variant-alternates: normal; font-variant-east-asian: normal; line-height: 15px; white-space: pre-wrap !important; word-wrap: normal !important;" data-mce-style="margin-top: 0px; margin-bottom: 0px; padding: 12px; border: 0px; background-color: rgba(71, 87, 120, 0.0784314); overflow: auto; border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; font-variant-ligatures: normal; font-variant-position: normal; font-variant-numeric: normal; font-variant-alternates: normal; font-variant-east-asian: normal; line-height: 15px; white-space: pre-wrap !important; word-wrap: normal !important;"><span class="" style="white-space: normal; background-color: rgb(255, 255, 255); font-size: 12px;" data-mce-style="white-space: normal; background-color: #ffffff; font-size: 12px;"><span face="Menlo" data-mce-style="font-family: Menlo;" style="font-family: Menlo;">// ; special-cases:</span></span></pre><pre class="remarkup-code" style="font-family: Menlo, Consolas, Monaco, monospace; margin-top: 0px; margin-bottom: 0px; padding: 12px; border: 0px; background-color: rgba(71, 87, 120, 0.0784314); overflow: auto; border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; font-variant-ligatures: normal; font-variant-position: normal; font-variant-numeric: normal; font-variant-alternates: normal; font-variant-east-asian: normal; line-height: 15px; white-space: pre-wrap !important; word-wrap: normal !important;" data-mce-style="font-family: Menlo, Consolas, Monaco, monospace; margin-top: 0px; margin-bottom: 0px; padding: 12px; border: 0px; background-color: rgba(71, 87, 120, 0.0784314); overflow: auto; border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; font-variant-ligatures: normal; font-variant-position: normal; font-variant-numeric: normal; font-variant-alternates: normal; font-variant-east-asian: normal; line-height: 15px; white-space: pre-wrap !important; word-wrap: normal !important;"><span class="" style="font-size: 11px;" data-mce-style="font-size: 11px;">// ;   %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 </span><b class="">%sr</b><span class="" style="font-size: 11px;" data-mce-style="font-size: 11px;">, 31
// ;   %retVal      = select i1 %ret0, i32 0, i32 %dividend
// ;   %earlyRet    = or i1 %ret0, %retDividend
// ;   br i1 %earlyRet, label %end, label %bb1</span></pre></div><p class="" style="margin: 0px 0px 12px; padding: 0px; border: 0px; font-variant-ligatures: normal; orphans: 2; widows: 2;" data-mce-style="margin: 0px 0px 12px; padding: 0px; border: 0px; font-variant-ligatures: normal; orphans: 2; widows: 2;"><br class="" style="margin-top: 0px;" data-mce-style="margin-top: 0px;">The intention must have been to use<span face="Segoe UI, Segoe UI Web Regular, Segoe UI Symbol, Lato, Helvetica Neue, Helvetica, Arial, sans-serif" data-mce-style="font-size: 13px; font-family: 'Segoe UI', 'Segoe UI Web Regular', 'Segoe UI Symbol', Lato, 'Helvetica Neue', Helvetica, Arial, sans-serif;" style="font-size: 13px; font-family: 'Segoe UI', 'Segoe UI Web Regular', 'Segoe UI Symbol', Lato, 'Helvetica Neue', Helvetica, Arial, sans-serif;"> </span><tt class="remarkup-monospaced" style="font-size: 13px; font-family: 'Segoe UI', 'Segoe UI Web Regular', 'Segoe UI Symbol', Lato, 'Helvetica Neue', Helvetica, Arial, sans-serif; background-color: rgba(71, 87, 120, 0.0980392); padding: 1px 4px; border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; white-space: pre-wrap;" data-mce-style="font-size: 13px; font-family: 'Segoe UI', 'Segoe UI Web Regular', 'Segoe UI Symbol', Lato, 'Helvetica Neue', Helvetica, Arial, sans-serif; background-color: rgba(71, 87, 120, 0.0980392); padding: 1px 4px; border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; white-space: pre-wrap;"><b class="">%tmp0</b></tt><span>, not </span><tt class="remarkup-monospaced" style="font-size: 13px; font-family: 'Segoe UI', 'Segoe UI Web Regular', 'Segoe UI Symbol', Lato, 'Helvetica Neue', Helvetica, Arial, sans-serif; background-color: rgba(71, 87, 120, 0.0980392); padding: 1px 4px; border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; white-space: pre-wrap;" data-mce-style="font-size: 13px; font-family: 'Segoe UI', 'Segoe UI Web Regular', 'Segoe UI Symbol', Lato, 'Helvetica Neue', Helvetica, Arial, sans-serif; background-color: rgba(71, 87, 120, 0.0980392); padding: 1px 4px; border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; white-space: pre-wrap;"><b class="">%sr</b></tt><span>:</span></p><div class="" style="margin: 0px; padding: 0px; border: 0px; font-variant-ligatures: normal; orphans: 2; widows: 2;" data-mce-style="margin: 0px; padding: 0px; border: 0px; font-variant-ligatures: normal; orphans: 2; widows: 2;"><pre class="remarkup-code" style="font-family: Menlo, Consolas, Monaco, monospace; margin-top: 0px; margin-bottom: 0px; padding: 12px; border: 0px; background-color: rgba(71, 87, 120, 0.0784314); overflow: auto; border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; font-variant-ligatures: normal; font-variant-position: normal; font-variant-numeric: normal; font-variant-alternates: normal; font-variant-east-asian: normal; line-height: 15px; white-space: pre-wrap !important; word-wrap: normal !important;" data-mce-style="font-family: Menlo, Consolas, Monaco, monospace; margin-top: 0px; margin-bottom: 0px; padding: 12px; border: 0px; background-color: rgba(71, 87, 120, 0.0784314); overflow: auto; border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; font-variant-ligatures: normal; font-variant-position: normal; font-variant-numeric: normal; font-variant-alternates: normal; font-variant-east-asian: normal; line-height: 15px; white-space: pre-wrap !important; word-wrap: normal !important;"><span class="" style="font-size: 11px;" data-mce-style="font-size: 11px;">// ;   %retDividend = icmp eq i32 </span><span style="font-size: 13px;" data-mce-style="font-size: 13px;"><b class="">%tmp0</b></span><span class="" style="font-size: 11px;" data-mce-style="font-size: 11px;">, 31</span></pre><div class=""><br class=""></div></div><div class="" style="margin: 0px; padding: 0px; border: 0px; font-variant-ligatures: normal; orphans: 2; widows: 2;" data-mce-style="margin: 0px; padding: 0px; border: 0px; font-variant-ligatures: normal; orphans: 2; widows: 2;">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.</div></div><div class="" style="font-family: SFNSText, 'Helvetica Neue', Helvetica, sans-serif; margin: 0px; padding: 0px; border: 0px; font-variant-ligatures: normal; orphans: 2; widows: 2;" data-mce-style="font-family: SFNSText, 'Helvetica Neue', Helvetica, sans-serif; margin: 0px; padding: 0px; border: 0px; font-variant-ligatures: normal; orphans: 2; widows: 2;"><br class=""></div><div class="" style="font-family: SFNSText, 'Helvetica Neue', Helvetica, sans-serif; margin: 0px; padding: 0px; border: 0px; font-variant-ligatures: normal; orphans: 2; widows: 2;" data-mce-style="font-family: SFNSText, 'Helvetica Neue', Helvetica, sans-serif; margin: 0px; padding: 0px; border: 0px; font-variant-ligatures: normal; orphans: 2; widows: 2;">Please review.</div><div class="" style="font-family: SFNSText, 'Helvetica Neue', Helvetica, sans-serif; margin: 0px; padding: 0px; border: 0px; font-variant-ligatures: normal; orphans: 2; widows: 2;" data-mce-style="font-family: SFNSText, 'Helvetica Neue', Helvetica, sans-serif; margin: 0px; padding: 0px; border: 0px; font-variant-ligatures: normal; orphans: 2; widows: 2;">Dmitri</div><div class="" style="font-family: SFNSText, 'Helvetica Neue', Helvetica, sans-serif; margin: 0px; padding: 0px; border: 0px; font-variant-ligatures: normal; orphans: 2; widows: 2;" data-mce-style="font-family: SFNSText, 'Helvetica Neue', Helvetica, sans-serif; margin: 0px; padding: 0px; border: 0px; font-variant-ligatures: normal; orphans: 2; widows: 2;"><br class=""></div><div class="" style="font-family: SFNSText, 'Helvetica Neue', Helvetica, sans-serif; margin: 0px; padding: 0px; border: 0px; font-variant-ligatures: normal; orphans: 2; widows: 2;" data-mce-style="font-family: SFNSText, 'Helvetica Neue', Helvetica, sans-serif; margin: 0px; padding: 0px; border: 0px; font-variant-ligatures: normal; orphans: 2; widows: 2;"><a href="https://reviews.llvm.org/D26818" class="" rel="noreferrer" data-mce-href="https://reviews.llvm.org/D26818">https://reviews.llvm.org/D26818</a></div></div></body></html>