Skip to content

Commit 5d263f8

Browse files
authored
Improve activity analysis with not for analysis uses (#2643)
* Improve activity analysis with not for analysis uses * fix
1 parent 460c4e0 commit 5d263f8

File tree

2 files changed

+70
-2
lines changed

2 files changed

+70
-2
lines changed

enzyme/Enzyme/ActivityAnalysis.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3350,13 +3350,14 @@ bool ActivityAnalyzer::isValueInactiveFromUsers(TypeResults const &TR,
33503350
UseActivity NU = UA;
33513351
if (UA == UseActivity::OnlyLoads || UA == UseActivity::OnlyStores ||
33523352
UA == UseActivity::OnlyNonPointerStores) {
3353-
if (!isPointerArithmeticInst(I))
3353+
if (!isPointerArithmeticInst(I) &&
3354+
!(UA == UseActivity::OnlyNonPointerStores && isa<LoadInst>(I)))
33543355
NU = UseActivity::None;
33553356
}
33563357

33573358
if (EnzymePrintActivity) {
33583359
llvm::errs() << "Adding users of value " << *I << " now with sub UA "
3359-
<< to_string(UA) << "\n";
3360+
<< to_string(NU) << "\n";
33603361
}
33613362
for (auto u : I->users()) {
33623363
todo.push_back(std::make_tuple(u, (Value *)I, NU));
@@ -3435,6 +3436,11 @@ bool ActivityAnalyzer::isValueActivelyStoredOrReturned(TypeResults const &TR,
34353436
continue;
34363437
}
34373438

3439+
if (auto I = dyn_cast<Instruction>(a))
3440+
if (notForAnalysis.count(I->getParent())) {
3441+
continue;
3442+
}
3443+
34383444
if (isa<ReturnInst>(a)) {
34393445
if (ActiveReturns == DIFFE_TYPE::CONSTANT)
34403446
continue;
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
; RUN: %opt < %s %newLoadEnzyme -passes="print-activity-analysis" -activity-analysis-func=_Z8simulatef -S | FileCheck %s
2+
3+
declare {} addrspace(10)* @ijl_alloc_array_1d({} addrspace(10)*, i64)
4+
5+
declare void @ijl_bounds_error_ints({} addrspace(12)*, i64*, i64)
6+
7+
define double @_Z8simulatef(i1 %cmp, i64 %val) {
8+
entry:
9+
br i1 %cmp, label %b1, label %b2
10+
11+
b1:
12+
%alloc1 = call noalias nonnull {} addrspace(10)* @ijl_alloc_array_1d({} addrspace(10)* noundef addrspacecast ({}* inttoptr (i64 123962498842016 to {}*) to {} addrspace(10)*), i64 2)
13+
br label %end
14+
15+
b2:
16+
%alloc2 = call noalias nonnull {} addrspace(10)* @ijl_alloc_array_1d({} addrspace(10)* noundef addrspacecast ({}* inttoptr (i64 123962498842016 to {}*) to {} addrspace(10)*), i64 2)
17+
br label %end
18+
19+
end:
20+
%phi = phi {} addrspace(10)* [ %alloc1, %b1 ], [ %alloc2, %b2 ]
21+
%ac = addrspacecast {} addrspace(10)* %phi to double addrspace(13)* addrspace(11)*
22+
%arrayptr189517 = load double addrspace(13)*, double addrspace(13)* addrspace(11)* %ac, align 8
23+
%gep = getelementptr inbounds double, double addrspace(13)* %arrayptr189517, i64 0
24+
%si = sitofp i64 %val to double
25+
store double %si, double addrspace(13)* %gep, align 8
26+
br i1 %cmp, label %oob, label %exit
27+
28+
oob:
29+
%errorbox186 = alloca i64
30+
%ei = addrspacecast {} addrspace(10)* %phi to {} addrspace(12)*
31+
call void @ijl_bounds_error_ints({} addrspace(12)* %ei, i64* noundef nonnull align 8 %errorbox186, i64 noundef 1)
32+
unreachable
33+
34+
exit:
35+
%res = load double, double addrspace(13)* %gep
36+
ret double %res
37+
}
38+
39+
; CHECK: entry
40+
; CHECK-NEXT: br i1 %cmp, label %b1, label %b2: icv:1 ici:1
41+
; CHECK-NEXT: b1
42+
; CHECK-NEXT: %alloc1 = call noalias nonnull {} addrspace(10)* @ijl_alloc_array_1d({} addrspace(10)* noundef addrspacecast ({}* inttoptr (i64 123962498842016 to {}*) to {} addrspace(10)*), i64 2): icv:1 ici:1
43+
; CHECK-NEXT: br label %end: icv:1 ici:1
44+
; CHECK-NEXT: b2
45+
; CHECK-NEXT: %alloc2 = call noalias nonnull {} addrspace(10)* @ijl_alloc_array_1d({} addrspace(10)* noundef addrspacecast ({}* inttoptr (i64 123962498842016 to {}*) to {} addrspace(10)*), i64 2): icv:1 ici:1
46+
; CHECK-NEXT: br label %end: icv:1 ici:1
47+
; CHECK-NEXT: end
48+
; CHECK-NEXT: %phi = phi {} addrspace(10)* [ %alloc1, %b1 ], [ %alloc2, %b2 ]: icv:1 ici:1
49+
; CHECK-NEXT: %ac = addrspacecast {} addrspace(10)* %phi to double addrspace(13)* addrspace(11)*: icv:1 ici:1
50+
; CHECK-NEXT: %arrayptr189517 = load double addrspace(13)*, double addrspace(13)* addrspace(11)* %ac, align 8: icv:1 ici:1
51+
; CHECK-NEXT: %gep = getelementptr inbounds double, double addrspace(13)* %arrayptr189517, i64 0: icv:1 ici:1
52+
; CHECK-NEXT: %si = sitofp i64 %val to double: icv:1 ici:1
53+
; CHECK-NEXT: store double %si, double addrspace(13)* %gep, align 8: icv:1 ici:1
54+
; CHECK-NEXT: br i1 %cmp, label %oob, label %exit: icv:1 ici:1
55+
; CHECK-NEXT: oob
56+
; CHECK-NEXT: %errorbox186 = alloca i64, align 8: icv:1 ici:1
57+
; CHECK-NEXT: %ei = addrspacecast {} addrspace(10)* %phi to {} addrspace(12)*: icv:1 ici:1
58+
; CHECK-NEXT: call void @ijl_bounds_error_ints({} addrspace(12)* %ei, i64* noundef nonnull align 8 %errorbox186, i64 noundef 1): icv:1 ici:1
59+
; CHECK-NEXT: unreachable: icv:1 ici:1
60+
; CHECK-NEXT: exit
61+
; CHECK-NEXT: %res = load double, double addrspace(13)* %gep, align 8: icv:1 ici:1
62+
; CHECK-NEXT: ret double %res: icv:1 ici:1

0 commit comments

Comments
 (0)