diff options
| author | Eli Friedman <efriedma@codeaurora.org> | 2016-10-04 00:03:55 +0000 | 
|---|---|---|
| committer | Eli Friedman <efriedma@codeaurora.org> | 2016-10-04 00:03:55 +0000 | 
| commit | 74bed9d7575973202a38743722def09fee51413b (patch) | |
| tree | 4ecfe64dc908a1dd3e9c7498b85b27656acae6b5 /llvm | |
| parent | 396bfdd7076325be148e1e95c433b78849c1083d (diff) | |
| download | bcm5719-llvm-74bed9d7575973202a38743722def09fee51413b.tar.gz bcm5719-llvm-74bed9d7575973202a38743722def09fee51413b.zip  | |
Make GlobalsAA ignore dead constant expressions.
Slightly improves the precision of GlobalsAA in certain situations, and
makes the behavior of optimization passes more predictable.
Differential Revision: https://reviews.llvm.org/D24104
llvm-svn: 283165
Diffstat (limited to 'llvm')
| -rw-r--r-- | llvm/lib/Analysis/GlobalsModRef.cpp | 2 | ||||
| -rw-r--r-- | llvm/test/Analysis/GlobalsModRef/dead-uses.ll | 54 | 
2 files changed, 56 insertions, 0 deletions
diff --git a/llvm/lib/Analysis/GlobalsModRef.cpp b/llvm/lib/Analysis/GlobalsModRef.cpp index 0da888d47d1..d29b9703e9c 100644 --- a/llvm/lib/Analysis/GlobalsModRef.cpp +++ b/llvm/lib/Analysis/GlobalsModRef.cpp @@ -366,6 +366,8 @@ bool GlobalsAAResult::AnalyzeUsesOfPointer(Value *V,      } else if (ICmpInst *ICI = dyn_cast<ICmpInst>(I)) {        if (!isa<ConstantPointerNull>(ICI->getOperand(1)))          return true; // Allow comparison against null. +    } else if (Constant *C = dyn_cast<Constant>(I)) { +      return C->isConstantUsed();      } else {        return true;      } diff --git a/llvm/test/Analysis/GlobalsModRef/dead-uses.ll b/llvm/test/Analysis/GlobalsModRef/dead-uses.ll new file mode 100644 index 00000000000..a96655d48bf --- /dev/null +++ b/llvm/test/Analysis/GlobalsModRef/dead-uses.ll @@ -0,0 +1,54 @@ +; RUN: opt < %s -instcombine -globals-aa -licm -S | FileCheck %s + +; Make sure -globals-aa ignores dead uses of globals. + +@a = internal global i32 0, align 4 +@c = common global i32 0, align 4 + +; Function Attrs: nounwind +define i32 @g() { +; Make sure the load of @a is hoisted. +; CHECK-LABEL: define i32 @g() +; CHECK: entry: +; CHECK-NEXT: load i32, i32* @a, align 4 +; CHECK-NEXT: br label %for.cond +entry: +  br label %for.cond + +for.cond:                                         ; preds = %for.inc, %entry +  %i.0 = phi i32 [ 0, %entry ], [ %inc, %for.inc ] +  %sum.0 = phi i32 [ 0, %entry ], [ %add, %for.inc ] +  %cmp = icmp slt i32 %i.0, 1000 +  br i1 %cmp, label %for.body, label %for.end + +for.body:                                         ; preds = %for.cond +  %0 = load i32, i32* @a, align 4 +  %add = add nsw i32 %sum.0, %0 +  call void @f() +  br label %for.inc + +for.inc:                                          ; preds = %for.body +  %inc = add nsw i32 %i.0, 1 +  br label %for.cond + +for.end:                                          ; preds = %for.cond +  ret i32 %sum.0 +} + +; Function Attrs: nounwind +define internal void @f() { +entry: +  %tobool = icmp ne i32 0, 0 +  br i1 %tobool, label %if.then, label %if.end + +if.then:                                          ; preds = %entry +  store i32 ptrtoint (i32* @a to i32), i32* @c, align 4 +  br label %if.end + +if.end:                                           ; preds = %if.then, %entry +  %0 = load i32, i32* @c, align 4 +  %inc = add nsw i32 %0, 1 +  store i32 %inc, i32* @c, align 4 +  ret void +} +  | 

