xref: /llvm-project/llvm/test/Transforms/GlobalOpt/metadata.ll (revision 72776850ed81b0e38673b86614bdc7fbb9619d04)
1; RUN: opt -S -passes=globalopt < %s | FileCheck %s
2
3; PR6112 - When globalopt does RAUW(@G, %G), the metadata reference should drop
4; to null.  Function local metadata that references @G from a different function
5; to that containing %G should likewise drop to null.
6@G = internal global ptr null
7
8define i32 @main(i32 %argc, ptr %argv) norecurse {
9; CHECK-LABEL: @main(
10; CHECK: %G = alloca
11  store ptr %argv, ptr @G
12  ret i32 0
13}
14
15define void @foo(i32 %x) {
16; Note: these arguments look like MDNodes, but they're really syntactic sugar
17; for 'MetadataAsValue::get(ValueAsMetadata::get(Value*))'.  When @G drops to
18; null, the ValueAsMetadata instance gets replaced by metadata !{}, or
19; MDNode::get({}).
20  call void @llvm.foo(metadata ptr @G, metadata i32 %x)
21; CHECK: call void @llvm.foo(metadata ![[EMPTY:[0-9]+]], metadata i32 %x)
22  ret void
23}
24
25declare void @llvm.foo(metadata, metadata) nounwind readnone
26
27!named = !{!0}
28; CHECK: !named = !{![[NULL:[0-9]+]]}
29
30!0 = !{ptr @G}
31; CHECK-DAG: ![[NULL]] = distinct !{null}
32; CHECK-DAG: ![[EMPTY]] = !{}
33