<html><head><meta http-equiv="Content-Type" content="text/html charset=windows-1252"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><br><div><div>On Oct 30, 2013, at 11:21 PM, Renato Golin <<a href="mailto:renato.golin@linaro.org">renato.golin@linaro.org</a>> wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div dir="ltr">On 30 October 2013 18:40, Frank Winter <span dir="ltr"><<a href="mailto:fwinter@jlab.org" target="_blank">fwinter@jlab.org</a>></span> wrote:<br><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

  
    
  
  <div bgcolor="#FFFFFF" text="#000000">
    <div>      const std::uint64_t ir0 = (i+0)%4;  // not working<br></div></div></blockquote><div><br></div><div>I thought this would be the case when I saw the original expression. Maybe we need to teach module arithmetic to SCEV?</div></div></div></div></blockquote><div><div><br></div><div>I let this thread get stale, so here’s the background again:</div><div><br></div><div>source:</div><div><br></div><div>      const std::uint64_t ir0 = i%4 + 8*(i/4);</div><div>      c[ ir0 ]         = a[ ir0 ]         + b[ ir0 ];</div><div><br></div><div><div>before instcombine:</div><div><br></div><div>  %4 = urem i64 %i.0, 4</div><div>  %5 = udiv i64 %i.0, 4</div><div>  %6 = mul i64 8, %5</div><div>  %7 = add i64 %4, %6</div><div>  %8 = getelementptr inbounds float* %a, i64 %7</div></div><div><br></div><div>after instcombine:</div><div><br></div></div><div><div>  %2 = and i64 %i.04, 3</div><div>  %3 = lshr i64 %i.04, 2</div><div>  %4 = shl i64 %3, 3</div><div>  %5 = or i64 %4, %2</div><div>  %11 = getelementptr inbounds float* %c, i64 %5</div><div>  store float %10, float* %11, align 4, !tbaa !0</div><div><br></div><div>Honestly, I don't understand why InstCombine "anti-canonicalizes" add->or. I think that transformation should be deferred into we begin target-specific lower (e.g. InstOptimize pass).</div></div><div><br></div><div>Given, that we aren't going to change that any time soon, SCEV could probably be taught to recognize the specific pattern:</div><div><br></div><div>Instructions (or (and %a, C1), (shl %b, C2)) -> SCEV (add %a, %b)</div><div><br></div><div>-Andy</div></div></body></html>