llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

[OpenMP][AArch64] ompt/synchronization/[masked.c | master.c] fail due to possibly wrong codegen

Open ceseo opened this issue 3 years ago • 6 comments

On AArch64, ompt/synchronization/master.c and ompt/synchronization/masked.c both fail in similar ways in current main:

# | /GitHub/llvm/llvm-project/openmp/runtime/test/ompt/synchronization/masked.c:38:11: error: CHECK: expected string not found in input
# | // CHECK: {{^}}[[MASTER_ID]]: current_address={{.*}}[[RETURN_ADDRESS_END]]
# |           ^
# | <stdin>:8:120: note: scanning from here
# | 281474976710658: ompt_event_masked_end: parallel_id=281474976710661, task_id=281474976710662, codeptr_ra=0xaaaaaf8260d0
# |                                                                                                                        ^
# | <stdin>:8:120: note: with "MASTER_ID" equal to "281474976710658"
# | 281474976710658: ompt_event_masked_end: parallel_id=281474976710661, task_id=281474976710662, codeptr_ra=0xaaaaaf8260d0
# |                                                                                                                        ^
# | <stdin>:8:120: note: with "RETURN_ADDRESS_END" equal to "0xaaaaaf8260d0"
# | 281474976710658: ompt_event_masked_end: parallel_id=281474976710661, task_id=281474976710662, codeptr_ra=0xaaaaaf8260d0
# |                                                                                                                        ^
# | <stdin>:9:13: note: possible intended match here
# | 281474976710658: current_address=0xaaaaaf8260d8 or 0xaaaaaf8260d4

When looking at the disassembly, there is a spurious branch instruction that isn't supposed to be there:

 ce8:   91364000        add     x0, x0, #0xd90
 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 code to fallthrough from the nop (label) to the adrp. Instead, there's a branch to the adrp instruction.

ceseo avatar Oct 19 '23 18:10 ceseo

@llvm/issue-subscribers-openmp

Author: Carlos Eduardo Seo (ceseo)

On AArch64, `ompt/synchronization/master.c` and `ompt/synchronization/masked.c` both fail in similar ways in current `main`:
# | /GitHub/llvm/llvm-project/openmp/runtime/test/ompt/synchronization/masked.c:38:11: error: CHECK: expected string not found in input
# | // CHECK: {{^}}[[MASTER_ID]]: current_address={{.*}}[[RETURN_ADDRESS_END]]
# |           ^
# | &lt;stdin&gt;:8:120: note: scanning from here
# | 281474976710658: ompt_event_masked_end: parallel_id=281474976710661, task_id=281474976710662, codeptr_ra=0xaaaaaf8260d0
# |                                                                                                                        ^
# | &lt;stdin&gt;:8:120: note: with "MASTER_ID" equal to "281474976710658"
# | 281474976710658: ompt_event_masked_end: parallel_id=281474976710661, task_id=281474976710662, codeptr_ra=0xaaaaaf8260d0
# |                                                                                                                        ^
# | &lt;stdin&gt;:8:120: note: with "RETURN_ADDRESS_END" equal to "0xaaaaaf8260d0"
# | 281474976710658: ompt_event_masked_end: parallel_id=281474976710661, task_id=281474976710662, codeptr_ra=0xaaaaaf8260d0
# |                                                                                                                        ^
# | &lt;stdin&gt;:9:13: note: possible intended match here
# | 281474976710658: current_address=0xaaaaaf8260d8 or 0xaaaaaf8260d4

When looking at the disassembly, there is a spurious branch instruction that isn't supposed to be there:

 ce8:   91364000        add     x0, x0, #<!-- -->0xd90
 cec:   97ffff19        bl      950 &lt;__kmpc_end_master@<!-- -->plt&gt;
 cf0:   14000001        b       cf4 &lt;main.omp_outlined+0xd4&gt;
 cf4:   d503201f        nop
 cf8:   14000001        b       cfc &lt;main.omp_outlined+0xdc&gt;
 cfc:   d0000088        adrp    x8, 12000 &lt;__gmon_start__@<!-- -->Base&gt;
 d00:   f9404d08        ldr     x8, [x8, #<!-- -->152]

I'd expect the code to fallthrough from the nop (label) to the adrp. Instead, there's a branch to the adrp instruction.

llvmbot avatar Oct 19 '23 18:10 llvmbot

@llvm/issue-subscribers-backend-aarch64

Author: Carlos Eduardo Seo (ceseo)

On AArch64, `ompt/synchronization/master.c` and `ompt/synchronization/masked.c` both fail in similar ways in current `main`:
# | /GitHub/llvm/llvm-project/openmp/runtime/test/ompt/synchronization/masked.c:38:11: error: CHECK: expected string not found in input
# | // CHECK: {{^}}[[MASTER_ID]]: current_address={{.*}}[[RETURN_ADDRESS_END]]
# |           ^
# | &lt;stdin&gt;:8:120: note: scanning from here
# | 281474976710658: ompt_event_masked_end: parallel_id=281474976710661, task_id=281474976710662, codeptr_ra=0xaaaaaf8260d0
# |                                                                                                                        ^
# | &lt;stdin&gt;:8:120: note: with "MASTER_ID" equal to "281474976710658"
# | 281474976710658: ompt_event_masked_end: parallel_id=281474976710661, task_id=281474976710662, codeptr_ra=0xaaaaaf8260d0
# |                                                                                                                        ^
# | &lt;stdin&gt;:8:120: note: with "RETURN_ADDRESS_END" equal to "0xaaaaaf8260d0"
# | 281474976710658: ompt_event_masked_end: parallel_id=281474976710661, task_id=281474976710662, codeptr_ra=0xaaaaaf8260d0
# |                                                                                                                        ^
# | &lt;stdin&gt;:9:13: note: possible intended match here
# | 281474976710658: current_address=0xaaaaaf8260d8 or 0xaaaaaf8260d4

When looking at the disassembly, there is a spurious branch instruction that isn't supposed to be there:

 ce8:   91364000        add     x0, x0, #<!-- -->0xd90
 cec:   97ffff19        bl      950 &lt;__kmpc_end_master@<!-- -->plt&gt;
 cf0:   14000001        b       cf4 &lt;main.omp_outlined+0xd4&gt;
 cf4:   d503201f        nop
 cf8:   14000001        b       cfc &lt;main.omp_outlined+0xdc&gt;
 cfc:   d0000088        adrp    x8, 12000 &lt;__gmon_start__@<!-- -->Base&gt;
 d00:   f9404d08        ldr     x8, [x8, #<!-- -->152]

I'd expect the code to fallthrough from the nop (label) to the adrp. Instead, there's a branch to the adrp instruction.

llvmbot avatar Oct 19 '23 18:10 llvmbot

Add our OMPT expert @jprotze here

shiltian avatar Oct 27 '23 17:10 shiltian

Is this fixed with a3c0f70, or did you see the issue on non-darwin platform?

jprotze avatar Nov 24 '23 22:11 jprotze

Is this fixed with a3c0f70, or did you see the issue on non-darwin platform?

It's Linux. If I apply the same rationale from Darwin, the tests pass. But looking at the disassembly above, I think there still is a codegen problem specific to AArch64 (one unnecessary branch instruction being generated).

What we could do for now is to apply the same fix for Linux here and add a FIXME comment pointing to this issue so whoever is working on AArch64 backend can take a look and see if it is a real bug. Does that sound reasonable?

ceseo avatar Dec 12 '23 13:12 ceseo

Since the testcase workaround fixed the problem, I'll close this. When I have a better understanding about the weird codegen observed here, I'll open a new issue against the AArch64 backend.

ceseo avatar Jan 04 '24 18:01 ceseo