[prev in list] [next in list] [prev in thread] [next in thread]
List: openjdk-hotspot-compiler-dev
Subject: Re: Suboptimal code generation in C2?
From: Vitaly Davidovich <vitalyd () gmail ! com>
Date: 2015-09-24 1:31:34
Message-ID: CAHjP37Gv_=1GM7+2bJNtB0M9cW4_09eh8x0g+-g+m1v8OyyANw () mail ! gmail ! com
[Download RAW message or body]
Great, thank you guys.
sent from my phone
On Sep 23, 2015 9:09 PM, "Vladimir Kozlov" <vladimir.kozlov@oracle.com>
wrote:
> Could be loop predicates or C2 splits loop (pre-main-post) before we
> collapsed it. But I agree that we could do better.
>
> Aleksey, thank you for filing RFE.
>
> Thanks,
> Vladimir
>
> On 9/24/15 3:04 AM, Vitaly Davidovich wrote:
>
>> Thanks Aleksey.
>>
>> The cmov is probably a non-issue here since both dependencies are in
>> registers. The arithmetic dance, jumps, and register allocation seems
>> off though. For instance, esi is cleared with xor then it jumps to code
>> that adds edx to esi, then it moves esi into eax - this could be
>> replaced with moving edx into eax.
>>
>> sent from my phone
>>
>> Hi,
>>
>> On 09/23/2015 08:49 PM, Vitaly Davidovich wrote:
>> > Consider this simple method:
>> >
>> > private static int test(final int ops, int start) {
>> > for (int i = 0; i < ops; ++i) {
>> > start++;
>> > }
>> > return start;
>> > }
>>
>> > test(int, int):
>> > leal(%rsi,%rdi), %edx
>> > movl%esi, %eax
>> > testl%edi, %edi
>> > cmovg%edx, %eax
>> > ret
>> >
>> > Any ideas on why C2 doesn't generate roughly the same thing? Clang 3.7
>> > and ICC 13.0.1 are almost the same as the GCC output above.
>>
>> Yup, could be better:
>> https://bugs.openjdk.java.net/browse/JDK-8137049
>> <https://bugs.openjdk.java.net/browse/JDK-8137049>
>>
>> I am not entirely sure conditional move is better than a branch in this
>> particular case, since $ops is probably always non-negative in practice.
>> HotSpot generates a branch there, which is good. The arithmetic dance is
>> indeed not very clean -- I'd speculate that's a leftover from loop
>> peeling.
>>
>> Thanks,
>> -Aleksey
>>
>>
>> sent from my phone
>>
>>
[Attachment #3 (text/html)]
<p dir="ltr">Great, thank you guys. </p>
<p dir="ltr">sent from my phone</p>
<div class="gmail_quote">On Sep 23, 2015 9:09 PM, "Vladimir Kozlov" <<a \
href="mailto:vladimir.kozlov@oracle.com">vladimir.kozlov@oracle.com</a>> wrote:<br \
type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 \
.8ex;border-left:1px #ccc solid;padding-left:1ex">Could be loop predicates or C2 \
splits loop (pre-main-post) before we collapsed it. But I agree that we could do \
better.<br> <br>
Aleksey, thank you for filing RFE.<br>
<br>
Thanks,<br>
Vladimir<br>
<br>
On 9/24/15 3:04 AM, Vitaly Davidovich wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc \
solid;padding-left:1ex"> Thanks Aleksey.<br>
<br>
The cmov is probably a non-issue here since both dependencies are in<br>
registers. The arithmetic dance, jumps, and register allocation seems<br>
off though. For instance, esi is cleared with xor then it jumps to code<br>
that adds edx to esi, then it moves esi into eax - this could be<br>
replaced with moving edx into eax.<br>
<br>
sent from my phone<br>
<br>
Hi,<br>
<br>
On 09/23/2015 08:49 PM, Vitaly Davidovich wrote:<br>
> Consider this simple method:<br>
><br>
> private static int test(final int ops, int start) {<br>
> for (int i = 0; i < ops; ++i) {<br>
> start++;<br>
> }<br>
> return start;<br>
> }<br>
<br>
> test(int, int):<br>
> leal(%rsi,%rdi), %edx<br>
> movl%esi, %eax<br>
> testl%edi, %edi<br>
> cmovg%edx, %eax<br>
> ret<br>
><br>
> Any ideas on why C2 doesn't generate roughly the same thing? Clang 3.7<br>
> and ICC 13.0.1 are almost the same as the GCC output above.<br>
<br>
Yup, could be better:<br>
<a href="https://bugs.openjdk.java.net/browse/JDK-8137049" rel="noreferrer" \
target="_blank">https://bugs.openjdk.java.net/browse/JDK-8137049</a><br> <<a \
href="https://bugs.openjdk.java.net/browse/JDK-8137049" rel="noreferrer" \
target="_blank">https://bugs.openjdk.java.net/browse/JDK-8137049</a>><br> <br>
I am not entirely sure conditional move is better than a branch in this<br>
particular case, since $ops is probably always non-negative in practice.<br>
HotSpot generates a branch there, which is good. The arithmetic dance is<br>
indeed not very clean -- I'd speculate that's a leftover from loop \
peeling.<br> <br>
Thanks,<br>
-Aleksey<br>
<br>
<br>
sent from my phone<br>
<br>
</blockquote>
</blockquote></div>
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic