<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;"><div>If this is disruptive to other architectures/optimizations in the middle end, perhaps you can use a dagcombine to do this. You would check for movabsq, see if it is being piped into an add, and if that is true fix it up.</div><div><br></div><div>Just my 17179869180 cents.</div><div><br></div><div>Michael</div><br><div><div>On Jun 26, 2013, at 11:24 AM, Eli Friedman <<a href="mailto:eli.friedman@gmail.com">eli.friedman@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div style="letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><div dir="ltr">On Wed, Jun 26, 2013 at 6:56 AM, Tim Northover<span class="Apple-converted-space"> </span><span dir="ltr"><<a href="mailto:tnorthover@apple.com" target="_blank">tnorthover@apple.com</a>></span><span class="Apple-converted-space"> </span>wrote:<br><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex;">Hi,<br><br>The attached patch adds a heuristic to ShrinkDemandedConstant so that small negative constants are preferred over large ones even if as an unsigned value the transformation would be an improvement.<br><br>The motivating case is added as a test:<br>define i32 @foo(i64 %in) {<br> <span class="Apple-converted-space"> </span>%sub = sub i64 %in, 4<br> <span class="Apple-converted-space"> </span>%shift = lshr i64 %sub, 2<br> <span class="Apple-converted-space"> </span>%res = trunc i64 %shift to i32<br><br> <span class="Apple-converted-space"> </span>ret i32 %res<br>}<br><br>On x86-64 this currently generates:<br><br>_foo:<br>       <span class="Apple-converted-space"> </span>movabsq $17179869180, %rax      ## imm = 0x3FFFFFFFC<br>       <span class="Apple-converted-space"> </span>addq    %rdi, %rax<br>       <span class="Apple-converted-space"> </span>shrq    $2, %rax<br>       <span class="Apple-converted-space"> </span>ret<br><br>with an unnecessary and large movabsq. With this change the fact that we’re really subtracting 4 survives to CodeGen and we just emit<br><br>_foo:<br>       <span class="Apple-converted-space"> </span>leaq -4(%rdi), %rax<br>       <span class="Apple-converted-space"> </span>shrq $2, %rax<br>       <span class="Apple-converted-space"> </span>ret<br><br>Does anyone have any objections to this change? Is it likely to cause more damage than good for later passes?<br><br></blockquote><div><br></div><div>This seems like a big change that could affect all sorts of optimizations; I'd like to see performance numbers from the nightly test suite.</div><div><br></div><div>Also, I'm not sure this code is actually performing the check you want it to; it appears that, for example, it would prefer -3 over -4.</div><div><br></div><div>-Eli </div></div><br></div></div>_______________________________________________<br>llvm-commits mailing list<br><a href="mailto:llvm-commits@cs.uiuc.edu">llvm-commits@cs.uiuc.edu</a><br><a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br></div></blockquote></div><br></body></html>