llvm-project/llvm/test/Verifier/writable-attr.ll
Nikita Popov 6b8ed78719 [IR] Add writable attribute
This adds a writable attribute, which in conjunction with
dereferenceable(N) states that a spurious store of N bytes is
introduced on function entry. This implies that this many bytes
are writable without trapping or introducing data races. See
https://llvm.org/docs/Atomics.html#optimization-outside-atomic for
why the second point is important.

This attribute can be added to sret arguments. I believe Rust will
also be able to use it for by-value (moved) arguments. Rust likely
won't be able to use it for &mut arguments (tree borrows does not
appear to allow spurious stores).

In this patch the new attribute is only used by LICM scalar promotion.
However, the actual motivation for this is to fix a correctness issue
in call slot optimization, which needs this attribute to avoid
optimization regressions.

Followup to the discussion on D157499.

Differential Revision: https://reviews.llvm.org/D158081
2023-11-01 10:46:31 +01:00

31 lines
923 B
LLVM

; RUN: not llvm-as -disable-output %s 2>&1 | FileCheck %s
; CHECK: Attribute 'writable' applied to incompatible type!
; CHECK-NEXT: ptr @not_pointer
define void @not_pointer_writable(i32 writable %arg) {
ret void
}
; CHECK: Attributes writable and readnone are incompatible!
; CHECK-NEXT: ptr @writable_readnone
define void @writable_readnone(ptr writable readnone %arg) {
ret void
}
; CHECK: Attributes writable and readonly are incompatible!
; CHECK-NEXT: ptr @writable_readonly
define void @writable_readonly(ptr writable readonly %arg) {
ret void
}
; CHECK: Attribute writable and memory without argmem: write are incompatible!
; CHECK-NEXT: ptr @writable_memory_argmem_read
define void @writable_memory_argmem_read(ptr writable %arg) memory(write, argmem: read) {
ret void
}
; CHECK-NOT: incompatible
define void @writable_memory_argmem_write(ptr writable %arg) memory(read, argmem: write) {
ret void
}