brintos

brintos / llvm-project-archived public Read only

0
0
Text · 5.0 KiB · 02bf290 Raw
140 lines · plain
1; RUN: opt -S -passes=rewrite-statepoints-for-gc < %s | FileCheck %s2 3; This test checks that metadata that's invalid after RS4GC is dropped.4; We can miscompile if optimizations scheduled after RS4GC uses the5; metadata that's infact invalid.6 7declare void @bar()8 9declare void @baz(i32)10; Confirm that loadedval instruction does not contain invariant.load metadata.11; but contains the range metadata.12; Since loadedval is not marked invariant, it will prevent incorrectly sinking13; %loadedval in LICM and avoid creation of an unrelocated use of %baseaddr.14define void @test_invariant_load(i1 %c) gc "statepoint-example" {15; CHECK-LABEL: @test_invariant_load16; CHECK: %loadedval = load i32, ptr addrspace(1) %baseaddr, align 8, !range !017bb:18  br label %outerloopHdr19 20outerloopHdr:                                              ; preds = %bb6, %bb21  %baseaddr = phi ptr addrspace(1) [ undef, %bb ], [ %tmp4, %bb6 ]22; LICM may sink this load to exit block after RS4GC because it's tagged invariant.23  %loadedval = load i32, ptr addrspace(1) %baseaddr, align 8, !range !0, !invariant.load !124  br label %innerloopHdr25 26innerloopHdr:                                              ; preds = %innerlooplatch, %outerloopHdr27  %tmp4 = phi ptr addrspace(1) [ %baseaddr, %outerloopHdr ], [ %gep, %innerlooplatch ]28  br label %innermostloophdr29 30innermostloophdr:                                              ; preds = %bb6, %innerloopHdr31  br i1 %c, label %exitblock, label %bb632 33bb6:                                              ; preds = %innermostloophdr34  switch i32 undef, label %innermostloophdr [35    i32 0, label %outerloopHdr36    i32 1, label %innerlooplatch37  ]38 39innerlooplatch:                                              ; preds = %bb640  call void @bar()41  %gep = getelementptr inbounds i32, ptr addrspace(1) %tmp4, i64 842  br label %innerloopHdr43 44exitblock:                                             ; preds = %innermostloophdr45  %tmp13 = add i32 42, %loadedval46  call void @baz(i32 %tmp13)47  unreachable48}49 50; drop the noalias metadata.51define void @test_noalias(i32 %x, ptr addrspace(1) %p, ptr addrspace(1) %q) gc "statepoint-example" {52; CHECK-LABEL: test_noalias53; CHECK: %y = load i32, ptr addrspace(1) %q, align 1654; CHECK: gc.statepoint55; CHECK: %p.relocated56; CHECK-NEXT: store i32 %x, ptr addrspace(1) %p.relocated, align 1657entry:58  %y = load i32, ptr addrspace(1) %q, align 16, !noalias !559  call void @baz(i32 %x)60  store i32 %x, ptr addrspace(1) %p, align 16, !noalias !561  ret void62}63 64; drop the dereferenceable metadata65define void @test_dereferenceable(ptr addrspace(1) %p, i32 %x, ptr addrspace(1) %q) gc "statepoint-example" {66; CHECK-LABEL: test_dereferenceable67; CHECK: %v1 = load ptr addrspace(1), ptr addrspace(1) %p68; CHECK-NEXT: %v2 = load i32, ptr addrspace(1) %v169; CHECK: gc.statepoint70  %v1 = load ptr addrspace(1), ptr addrspace(1) %p, !dereferenceable !671  %v2 = load i32, ptr addrspace(1) %v172  call void @baz(i32 %x)73  store i32 %v2, ptr addrspace(1) %q, align 1674  ret void75}76 77; invariant.start allows us to sink the load past the baz statepoint call into taken block, which is78; incorrect. remove the invariant.start and RAUW undef.79define void @test_inv_start(i1 %cond, ptr addrspace(1) %p, i32 %x, ptr addrspace(1) %q) gc "statepoint-example" {80; CHECK-LABEL: test_inv_start81; CHECK-NOT: invariant.start82; CHECK: gc.statepoint83  %v1 = load ptr addrspace(1), ptr addrspace(1) %p84  %invst = call ptr @llvm.invariant.start.p1(i64 1, ptr addrspace(1) %v1)85  %v2 = load i32, ptr addrspace(1) %v186  call void @baz(i32 %x)87  br i1 %cond, label %taken, label %untaken88 89taken:90  store i32 %v2, ptr addrspace(1) %q, align 1691  call void @llvm.invariant.end.p1(ptr %invst, i64 4, ptr addrspace(1) %v1)92  ret void93 94; CHECK-LABEL: untaken:95; CHECK: gc.statepoint96untaken:97  %foo = call i32 @escaping.invariant.start(ptr %invst)98  call void @dummy(i32 %foo)99  ret void100}101 102; invariant.start is removed and the uses are undef'ed.103define void @test_inv_start2(i1 %cond, ptr addrspace(1) %p, i32 %x, ptr addrspace(1) %q) gc "statepoint-example" {104; CHECK-LABEL: test_inv_start2105; CHECK-NOT: invariant.start106; CHECK: gc.statepoint107  %v1 = load ptr addrspace(1), ptr addrspace(1) %p108  %invst = call ptr @llvm.invariant.start.p1(i64 1, ptr addrspace(1) %v1)109  %v2 = load i32, ptr addrspace(1) %v1110  call void @baz(i32 %x)111  br i1 %cond, label %taken, label %untaken112 113taken:114  store i32 %v2, ptr addrspace(1) %q, align 16115  call void @llvm.invariant.end.p1(ptr %invst, i64 4, ptr addrspace(1) %v1)116  ret void117 118untaken:119  ret void120}121declare ptr @llvm.invariant.start.p1(i64, ptr addrspace(1)  nocapture) nounwind readonly122declare void @llvm.invariant.end.p1(ptr, i64, ptr addrspace(1) nocapture) nounwind123declare i32 @escaping.invariant.start(ptr) nounwind124declare void @dummy(i32)125declare token @llvm.experimental.gc.statepoint.p0(i64, i32, ptr, i32, i32, ...)126 127; Function Attrs: nounwind readonly128declare ptr addrspace(1) @llvm.experimental.gc.relocate.p1(token, i32, i32) #0129 130 131attributes #0 = { nounwind readonly }132 133!0 = !{i32 0, i32 2147483647}134!1 = !{}135!2 = !{i32 10, i32 1}136!3 = !{!3}137!4 = !{!4, !3}138!5 = !{!4}139!6 = !{i64 8}140