profiling of branches - odd code generation? (original) (raw)
Vitaly Davidovich vitalyd at gmail.com
Thu Jun 4 23:20:47 UTC 2015
- Previous message: RSA intrinsics [Was: RFR(L): 8069539: RSA acceleration]
- Next message: profiling of branches - odd code generation?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Hi,
Suppose you have a method like this:
private static int f(final int x) { if (x == 0) return 1; else if (x == 1) return 2; else if (x == 2) return 3; return 4;
}
If I then call it with x=2 always, the generated asm is not what I expect (8u40 with C2 compiler)
parm0: rsi = int
[sp+0x30] (sp of caller)
0x00007fcc5970c520: mov %eax,-0x14000(%rsp) 0x00007fcc5970c527: push %rbp 0x00007fcc5970c528: sub $0x20,%rsp ;*synchronization entry
0x00007fcc5970c52c: test %esi,%esi 0x00007fcc5970c52e: je 0x00007fcc5970c55d ;*ifne
0x00007fcc5970c530: cmp $0x1,%esi 0x00007fcc5970c533: je 0x00007fcc5970c571 ;*if_icmpne
0x00007fcc5970c535: cmp $0x2,%esi 0x00007fcc5970c538: jne 0x00007fcc5970c54b ;*if_icmpne
0x00007fcc5970c53a: mov $0x3,%eax 0x00007fcc5970c53f: add $0x20,%rsp 0x00007fcc5970c543: pop %rbp 0x00007fcc5970c544: test %eax,0x5e0dab6(%rip)300000 # 0x00007fcc5f51a000 ; {poll_return} 0x00007fcc5970c54a: retq
It's checking the if conditions in order, and then jumps to some runtime calls (I'm assuming that's for deopt to restore pruned branches? Cause I don't see anything that returns 1 or 2 otherwise). Why is this code not favoring x=2? I'd have thought this code would be something like (after epilogue):
cmp $0x2, %esi jne mov $0x3, %eax retq
Thanks -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.openjdk.java.net/pipermail/hotspot-compiler-dev/attachments/20150604/6ec3e503/attachment.html>
- Previous message: RSA intrinsics [Was: RFR(L): 8069539: RSA acceleration]
- Next message: profiling of branches - odd code generation?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the hotspot-compiler-dev mailing list