This is an archive of the discontinued LLVM Phabricator instance.

[RISCV] Handle "o" inline asm memory constraint
ClosedPublic

Authored by pcwang-thead on Jun 2 2023, 1:05 AM.

Details

Summary

This is the same as D100412.

We just found the same crash when we tried to compile some packages
like mariadb, php, etc.

For constraint "o", it means "A memory operand is allowed, but
only if the address is offsettable". So I think it can be handled
just like constraint "m" for RISCV target.

And we print verbose information when unsupported constraints occur.

Diff Detail

Event Timeline

Herald added a project: Restricted Project. · View Herald TranscriptJun 2 2023, 1:05 AM
pcwang-thead requested review of this revision.Jun 2 2023, 1:05 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 2 2023, 1:05 AM
jrtc27 added inline comments.Jun 2 2023, 1:17 AM
llvm/lib/Target/RISCV/RISCVISelDAGToDAG.cpp
2147–2148

report_fatal_error? llvm_unreachable doesn't always print its message, doesn't always print at all, and doesn't always even abort; in the worst case it ends up being a __builtin_unreachable() that tells the compiler to assume the case can't happen.

llvm/test/CodeGen/RISCV/inline-asm.ll
116

The implementation could be completely broken and this would be none the wiser. You need to test the implementation actually lowers it to something sensible, not that it doesn't crash.

  • Use report_fatal_error.
  • Add more tests.
pcwang-thead marked an inline comment as done.Jun 2 2023, 1:36 AM
pcwang-thead added inline comments.
llvm/test/CodeGen/RISCV/inline-asm.ll
116

These tests are the same as constraint "m" now.

pcwang-thead edited the summary of this revision. (Show Details)Jun 2 2023, 1:38 AM
pcwang-thead edited the summary of this revision. (Show Details)

I just dug into the crash.
The key point here is that these packages are using DTrace(_SDT_ASM_BODY) and some inline assemblies like below will be generated:

define ptr @simple_key_cache_read(ptr %0) {
  call void asm sideeffect "990: nop\0A.pushsection .note.stapsdt,\22?\22,\22note\22\0A.balign 4\0A.4byte 992f-991f,994f-993f,3\0A991: .asciz \22stapsdt\22\0A992: .balign 4\0A993: .8byte 990b\0A.8byte _.stapsdt.base\0A.8byte mysql_keycache__read__start_semaphore\0A.asciz \22mysql\22\0A.asciz \22keycache__read__start\22\0A.asciz \22${0:n}@$1 ${2:n}@$3 ${4:n}@$5 ${6:n}@$7\22\0A994: .balign 4\0A.popsection\0A", "n,nor,n,nor,n,nor,n,nor"(i32 0, ptr %0, i32 0, i32 0, i32 0, i64 0, i32 0, i64 0)
  ret ptr null
}

There are several usages of constraint "o".

asb accepted this revision.Jun 6 2023, 1:02 AM

LGTM, thanks for this fix.

This revision is now accepted and ready to land.Jun 6 2023, 1:02 AM
This revision was landed with ongoing or failed builds.Jun 6 2023, 2:51 AM
This revision was automatically updated to reflect the committed changes.
MaskRay added inline comments.Jun 6 2023, 4:01 PM
llvm/test/CodeGen/RISCV/inline-asm.ll
116

Thanks for the update. The previous case is what I call

https://maskray.me/blog/2021-08-08-toolchain-testing#the-test-checks-at-the-wrong-layer#the-test-checks-too-little "A regression test which simply runs the compiler and expects it not to crash has low utilization. It is often better to additionally test some properties of the produced object file."