Skip to content

Commit

Permalink
[tests] Add coverage of writeonly attribute and operand bundle inters…
Browse files Browse the repository at this point in the history
…ection
  • Loading branch information
preames committed Jan 18, 2022
1 parent bf366bd commit 7ac65f6
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 5 deletions.
25 changes: 20 additions & 5 deletions llvm/test/Feature/OperandBundles/function-attrs.ll
Expand Up @@ -2,11 +2,12 @@

declare void @f_readonly() readonly
declare void @f_readnone() readnone
declare void @f_writeonly() writeonly

define void @test_0(i32* %x) {
; FunctionAttrs must not infer readonly / readnone for %x

; CHECK-LABEL: define void @test_0(i32* %x) #2 {
; CHECK-LABEL: define void @test_0(i32* %x) #3 {
entry:
; CHECK: call void @f_readonly() [ "foo"(i32* %x) ]
call void @f_readonly() [ "foo"(i32* %x) ]
Expand All @@ -16,21 +17,35 @@ define void @test_0(i32* %x) {
define void @test_1(i32* %x) {
; FunctionAttrs must not infer readonly / readnone for %x

; CHECK-LABEL: define void @test_1(i32* %x) #3 {
; CHECK-LABEL: define void @test_1(i32* %x) #4 {
entry:
; CHECK: call void @f_readnone() [ "foo"(i32* %x) ]
call void @f_readnone() [ "foo"(i32* %x) ]
ret void
}

; FIXME: We are incorectly inferring writeonly on the function
define void @test_2(i32* %x) {
; FunctionAttrs must not infer writeonly

; CHECK-LABEL: define void @test_2(i32* %x) #2 {
entry:
; CHECK: call void @f_writeonly() [ "foo"(i32* %x) ]
call void @f_writeonly() [ "foo"(i32* %x) ]
ret void
}

define void @test_3(i32* %x) {
; The "deopt" operand bundle does not capture or write to %x.

; CHECK-LABEL: define void @test_2(i32* nocapture readonly %x)
; CHECK-LABEL: define void @test_3(i32* nocapture readonly %x)
entry:
call void @f_readonly() [ "deopt"(i32* %x) ]
ret void
}

; CHECK: attributes #2 = { nofree }
; CHECK: attributes #3 = { nofree nosync }
; CHECK: attributes #0 = { nofree readonly }
; CHECK: attributes #1 = { nofree nosync readnone }
; CHECK: attributes #2 = { writeonly }
; CHECK: attributes #3 = { nofree }
; CHECK: attributes #4 = { nofree nosync }
14 changes: 14 additions & 0 deletions llvm/test/Transforms/DeadStoreElimination/trivial-dse-calls.ll
Expand Up @@ -193,6 +193,20 @@ define i32 @test_neg_captured_before() {
ret i32 %res
}

; Callee might be dead, but op bundle has unknown semantics and thus isn't.
define void @test_new_op_bundle() {
; CHECK-LABEL: @test_new_op_bundle(
; CHECK-NEXT: [[A:%.*]] = alloca i32, align 4
; CHECK-NEXT: [[BITCAST:%.*]] = bitcast i32* [[A]] to i8*
; CHECK-NEXT: call void @f(i8* nocapture writeonly [[BITCAST]]) #[[ATTR1]] [ "unknown"(i8* [[BITCAST]]) ]
; CHECK-NEXT: ret void
;
%a = alloca i32, align 4
%bitcast = bitcast i32* %a to i8*
call void @f(i8* writeonly nocapture %bitcast) argmemonly nounwind willreturn ["unknown" (i8* %bitcast)]
ret void
}

; Show that reading from unrelated memory is okay
define void @test_unreleated_read() {
; CHECK-LABEL: @test_unreleated_read(
Expand Down
6 changes: 6 additions & 0 deletions llvm/test/Transforms/FunctionAttrs/writeonly.ll
Expand Up @@ -100,6 +100,12 @@ define void @direct3(i8* %p) {
ret void
}

; CHECK: define void @direct3b(i8* %p)
define void @direct3b(i8* %p) {
call void @direct3_callee(i8* %p) ["may-read-and-capture"(i8* %p)]
ret void
}

; CHECK: define void @fptr_test1(i8* %p, void (i8*)* nocapture readonly %f)
define void @fptr_test1(i8* %p, void (i8*)* %f) {
call void %f(i8* %p)
Expand Down

0 comments on commit 7ac65f6

Please sign in to comment.