[AArch64] Extra unconditional branch instruction being generated
Following up the discussion on the AArch64 Sync call (2024-01-09):
While debugging OpenMP (ompt/synchronization/master.c), I noticed this:
cec: 97ffff19 bl 950 <__kmpc_end_master@plt>
cf0: 14000001 b cf4 <main.omp_outlined+0xd4>
cf4: d503201f nop
cf8: 14000001 b cfc <main.omp_outlined+0xdc>
cfc: d0000088 adrp x8, 12000 <__gmon_start__@Base>
d00: f9404d08 ldr x8, [x8, #152]
I'd expect the nop to be followed by the adrp. Instead, there is an unconditional branch to the adrp.
I've seen this pattern in other parts of the code as well, but this is the example I had at hand. I can try to create a smaller reproducer, if necessary.
Thanks for the reproducer. I've not looked in great detail, but it may be something to do with the inline assembly blocks in the code. I was compiling the master.c file manually - I had to cobble it together to make it work and so might have got it wrong, but didn't see the same branches. Do you know which compiler options it uses?
@llvm/issue-subscribers-backend-aarch64
Author: Carlos Eduardo Seo (ceseo)
While debugging OpenMP (ompt/synchronization/master.c), I noticed this:
cec: 97ffff19 bl 950 <__kmpc_end_master@<!-- -->plt>
cf0: 14000001 b cf4 <main.omp_outlined+0xd4>
cf4: d503201f nop
cf8: 14000001 b cfc <main.omp_outlined+0xdc>
cfc: d0000088 adrp x8, 12000 <__gmon_start__@<!-- -->Base>
d00: f9404d08 ldr x8, [x8, #<!-- -->152]
I'd expect the nop to be followed by the adrp. Instead, there is an unconditional branch to the adrp.
I've seen this pattern in other parts of the code as well, but this is the example I had at hand. I can try to create a smaller reproducer, if necessary.
Thanks for the reproducer. I've not looked in great detail, but it may be something to do with the inline assembly blocks in the code. I was compiling the master.c file manually - I had to cobble it together to make it work and so might have got it wrong, but didn't see the same branches. Do you know which compiler options it uses?
Nothing out of the ordinary. The only extra flag I can see is -fopenmp.
Is it -O0 by any chance? If so it would not be a surprise to see unoptimized code.
Is it -O0 by any chance? If so it would not be a surprise to see unoptimized code.
No. It's just getting flags passed to cmake (in this case, -g and -O2).
@davemgreen I stand corrected. I rechecked this and it's -O0. Sorry about that... it's very convoluted to get the correct compiler options for these tests.
as Dave mentions unoptimized code at O0 is pretty typical, redundant branches used to be optimized away at O0 to help code size but that was changed to help debugging (https://github.com/llvm/llvm-project/commit/c5d84d2eb35c1f0d3b08e1d1e95c1a22a28904d1)