[llvm] r322470 - [GlobalsAA] Don't let dbg intrinsics affect analysis result

Mikael Holmen via llvm-commits llvm-commits at lists.llvm.org
Sun Jan 14 23:05:51 PST 2018


Author: uabelho
Date: Sun Jan 14 23:05:51 2018
New Revision: 322470

URL: http://llvm.org/viewvc/llvm-project?rev=322470&view=rev
Log:
[GlobalsAA] Don't let dbg intrinsics affect analysis result

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

Added:
    llvm/trunk/test/Analysis/GlobalsModRef/pr35899-dbg-value.ll
Modified:
    llvm/trunk/lib/Analysis/GlobalsModRef.cpp

Modified: llvm/trunk/lib/Analysis/GlobalsModRef.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/GlobalsModRef.cpp?rev=322470&r1=322469&r2=322470&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/GlobalsModRef.cpp (original)
+++ llvm/trunk/lib/Analysis/GlobalsModRef.cpp Sun Jan 14 23:05:51 2018
@@ -582,6 +582,10 @@ void GlobalsAAResult::AnalyzeCallGraph(C
           } 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));

Added: llvm/trunk/test/Analysis/GlobalsModRef/pr35899-dbg-value.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Analysis/GlobalsModRef/pr35899-dbg-value.ll?rev=322470&view=auto
==============================================================================
--- llvm/trunk/test/Analysis/GlobalsModRef/pr35899-dbg-value.ll (added)
+++ llvm/trunk/test/Analysis/GlobalsModRef/pr35899-dbg-value.ll Sun Jan 14 23:05:51 2018
@@ -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.
+
+ at 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
+




More information about the llvm-commits mailing list