[PATCH] D24104: Make GlobalsAA ignore dead constant expressions.
Eli Friedman via llvm-commits
llvm-commits at lists.llvm.org
Wed Aug 31 15:20:27 PDT 2016
efriedma created this revision.
efriedma added reviewers: jmolloy, sanjoy, mkuper.
efriedma added a subscriber: llvm-commits.
efriedma set the repository for this revision to rL LLVM.
Slightly improves the precision of GlobalsAA in certain situations, and makes the behavior of optimization passes more predictable.
Repository:
rL LLVM
https://reviews.llvm.org/D24104
Files:
lib/Analysis/GlobalsModRef.cpp
test/Analysis/GlobalsModRef/dead-uses.ll
Index: test/Analysis/GlobalsModRef/dead-uses.ll
===================================================================
--- /dev/null
+++ test/Analysis/GlobalsModRef/dead-uses.ll
@@ -0,0 +1,52 @@
+; RUN: opt < %s -instcombine -globals-aa -licm -S | FileCheck %s
+
+; Make sure -globals-aa ignores dead uses of globals.
+
+ at a = internal global i32 0, align 4
+ at c = common global i32 0, align 4
+
+; Function Attrs: nounwind
+define i32 @g() #0 {
+; CHECK-LABEL: define i32 @g()
+; CHECK: 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() #0 {
+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
+}
+
Index: lib/Analysis/GlobalsModRef.cpp
===================================================================
--- lib/Analysis/GlobalsModRef.cpp
+++ lib/Analysis/GlobalsModRef.cpp
@@ -272,19 +272,24 @@
void GlobalsAAResult::AnalyzeGlobals(Module &M) {
SmallPtrSet<Function *, 32> TrackedFunctions;
for (Function &F : M)
- if (F.hasLocalLinkage())
+ if (F.hasLocalLinkage()) {
+ // AnalyzeUsesOfPointer assumes all uses of the value are live.
+ F.removeDeadConstantUsers();
if (!AnalyzeUsesOfPointer(&F)) {
// Remember that we are tracking this global.
NonAddressTakenGlobals.insert(&F);
TrackedFunctions.insert(&F);
Handles.emplace_front(*this, &F);
Handles.front().I = Handles.begin();
++NumNonAddrTakenFunctions;
}
+ }
SmallPtrSet<Function *, 16> Readers, Writers;
for (GlobalVariable &GV : M.globals())
if (GV.hasLocalLinkage()) {
+ // AnalyzeUsesOfPointer assumes all uses of the value are live.
+ GV.removeDeadConstantUsers();
if (!AnalyzeUsesOfPointer(&GV, &Readers,
GV.isConstant() ? nullptr : &Writers)) {
// Remember that we are tracking this global, and the mod/ref fns
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D24104.69912.patch
Type: text/x-patch
Size: 2973 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160831/f37b5524/attachment.bin>
More information about the llvm-commits
mailing list