Arthur Eubanks 61d4b342d1 [test][NewPM] Make dead-uses.ll work under NPM
This one is weird...

globals-aa needs to be already computed at licm, or else a function pass
can't run a module analysis and won't have access to globals-aa.
But the globals-aa result is impacted by instcombine in a way that
affects what the test is expecting. If globals-aa is computed before
instcombine, it is cached and globals-aa used in licm won't contain the
necessary info provided by instcombine.
Another catch is that if we don't invalidate AAManager, it will use the
cached AAManager that instcombine requested, which may not contain
globals-aa. So we have to invalidate<aa> so that licm can recompute
an AAManager with the globals-aa created by the require<globals-aa>.

This is essentially the problem described in https://reviews.llvm.org/D84259.

Reviewed By: asbirlea

Differential Revision: https://reviews.llvm.org/D88118
2020-10-06 07:33:02 -07:00

56 lines
1.7 KiB
LLVM

; RUN: opt < %s -instcombine -globals-aa -licm -enable-new-pm=0 -S | FileCheck %s
; RUN: opt < %s -aa-pipeline=basic-aa,globals-aa -passes='function(instcombine),require<globals-aa>,function(invalidate<aa>,loop(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
}