OSDN Git Service

[GlobalsAA] Don't let dbg intrinsics affect analysis result
authorMikael Holmen <mikael.holmen@ericsson.com>
Mon, 15 Jan 2018 07:05:51 +0000 (07:05 +0000)
committerMikael Holmen <mikael.holmen@ericsson.com>
Mon, 15 Jan 2018 07:05:51 +0000 (07:05 +0000)
Summary:
This fixes PR35899.

Debug info intrinsics shouldn't affect code generation so ignore them
in GlobalsAA.

Reviewers: hfinkel, aprantl

Reviewed By: aprantl

Subscribers: aprantl, llvm-commits

Differential Revision: https://reviews.llvm.org/D41984

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@322470 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Analysis/GlobalsModRef.cpp
test/Analysis/GlobalsModRef/pr35899-dbg-value.ll [new file with mode: 0644]

index daee932..9f33b94 100644 (file)
@@ -582,6 +582,10 @@ void GlobalsAAResult::AnalyzeCallGraph(CallGraph &CG, Module &M) {
           } else if (Function *Callee = CS.getCalledFunction()) {
             // The callgraph doesn't include intrinsic calls.
             if (Callee->isIntrinsic()) {
+              if (isa<DbgInfoIntrinsic>(I))
+                // Don't let dbg intrinsics affect alias info.
+                continue;
+
               FunctionModRefBehavior Behaviour =
                   AAResultBase::getModRefBehavior(Callee);
               FI.addModRefInfo(createModRefInfo(Behaviour));
diff --git a/test/Analysis/GlobalsModRef/pr35899-dbg-value.ll b/test/Analysis/GlobalsModRef/pr35899-dbg-value.ll
new file mode 100644 (file)
index 0000000..c0600d3
--- /dev/null
@@ -0,0 +1,57 @@
+; RUN: opt -S -strip-debug -globals-aa -instcombine < %s | FileCheck %s
+; RUN: opt -S -globals-aa -instcombine < %s | FileCheck %s
+
+; Having debug info around shouldn't affect what globals-aa and instcombine do.
+
+@g = global i8 0
+
+define void @bar(i8 %p) {
+   call void @llvm.dbg.value(metadata i64 0, metadata !14, metadata !DIExpression()), !dbg !15
+  ret void
+}
+
+declare void @gaz(i8 %p)
+
+define void @foo() {
+  store i8 42, i8* @g, align 1
+  call void @bar(i8 1)
+  %_tmp = load i8, i8* @g, align 1
+  call void @gaz(i8 %_tmp)
+  ret void
+}
+
+; Function Attrs: nounwind readnone speculatable
+declare void @llvm.dbg.value(metadata, metadata, metadata) #0
+
+attributes #0 = { nounwind readnone speculatable }
+
+!llvm.dbg.cu = !{!5}
+!llvm.module.flags = !{!8, !9}
+!llvm.ident = !{!10}
+
+!0 = !DIFile(filename: "foo.c", directory: "/tmp")
+!1 = !DIDerivedType(tag: DW_TAG_typedef, name: "uint64_t", file: !2, line: 77, baseType: !3)
+!2 = !DIFile(filename: "foo.h", directory: "/tmp")
+!3 = !DIDerivedType(tag: DW_TAG_typedef, name: "__u64_t", file: !0, baseType: !4)
+!4 = !DIBasicType(name: "unsigned long long", size: 64, encoding: DW_ATE_unsigned)
+!5 = distinct !DICompileUnit(language: DW_LANG_C, file: !0, producer: "My Compiler", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !6, retainedTypes: !6, globals: !7)
+!6 = !{}
+!7 = !{}
+!8 = !{i32 2, !"Dwarf Version", i32 4}
+!9 = !{i32 2, !"Debug Info Version", i32 3}
+!10 = !{!"My Compiler"}
+!11 = distinct !DISubprogram(name: "func_5", scope: !0, file: !0, line: 117, type: !12, isLocal: true, isDefinition: true, scopeLine: 118, isOptimized: false, unit: !5, variables: !6)
+!12 = !DISubroutineType(types: !13)
+!13 = !{}
+!14 = !DILocalVariable(name: "p_6", arg: 1, scope: !11, line: 117, type: !1)
+!15 = !DILocation(line: 117, column: 34, scope: !11)
+
+; instcombine should realize that the load will read 42 from g and pass 42 to
+; gaz regardless of the dbg.value in bar.
+
+; CHECK: define void @foo() {
+; CHECK-NEXT:  store i8 42, i8* @g, align 1
+; CHECK-NEXT:  call void @bar(i8 1)
+; CHECK-NEXT:  call void @gaz(i8 42)
+; CHECK-NEXT:  ret void
+