Skip to content

Commit 05f1c8b

Browse files
authored
Make activity analysis more aggressive re gep (rust-lang#761)
1 parent 8836427 commit 05f1c8b

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

enzyme/Enzyme/ActivityAnalysis.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2483,6 +2483,13 @@ bool ActivityAnalyzer::isValueInactiveFromUsers(TypeResults const &TR,
24832483
}
24842484
}
24852485

2486+
// For an inbound gep, args which are not the pointer being offset
2487+
// are not used in an active way by definition.
2488+
if (auto gep = dyn_cast<GetElementPtrInst>(a)) {
2489+
if (gep->isInBounds() && gep->getPointerOperand() != parent)
2490+
continue;
2491+
}
2492+
24862493
// If this doesn't write to memory this can only be an active use
24872494
// if its return is used in an active way, therefore add this to
24882495
// the list of users to analyze
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
; RUN: %opt < %s %loadEnzyme -print-activity-analysis -activity-analysis-func=f -enzyme-strict-aliasing=0 -o /dev/null | FileCheck %s
2+
3+
declare i64 @getint(double* %x)
4+
5+
define void @f(double* %x) {
6+
entry:
7+
%a189 = call i64 @getint(double* %x)
8+
%a190 = ashr exact i64 %a189, 4
9+
br i1 true, label %r, label %e
10+
11+
r:
12+
%g = getelementptr inbounds double, double* %x, i64 %a190
13+
store double 1.000000e+00, double* %g, align 8
14+
br label %e
15+
16+
e:
17+
ret void
18+
}
19+
20+
; CHECK: double* %x: icv:0
21+
; CHECK-NEXT: entry
22+
; CHECK-NEXT: %a189 = call i64 @getint(double* %x): icv:0 ici:0
23+
; CHECK-NEXT: %a190 = ashr exact i64 %a189, 4: icv:0 ici:1
24+
; CHECK-NEXT: br i1 true, label %r, label %e: icv:1 ici:1
25+
; CHECK-NEXT: r
26+
; CHECK-NEXT: %g = getelementptr inbounds double, double* %x, i64 %a190: icv:0 ici:1
27+
; CHECK-NEXT: store double 1.000000e+00, double* %g, align 8: icv:1 ici:1
28+
; CHECK-NEXT: br label %e: icv:1 ici:1
29+
; CHECK-NEXT: e
30+
; CHECK-NEXT: ret void: icv:1 ici:1
31+

0 commit comments

Comments
 (0)