-
Notifications
You must be signed in to change notification settings - Fork 104
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
139 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
; RUN: opt < %s %loadEnzyme -enzyme -enzyme_preopt=false -inline -mem2reg -instsimplify -adce -loop-deletion -correlated-propagation -simplifycfg -licm -early-cse -simplifycfg -instsimplify -S | FileCheck %s | ||
|
||
; Function Attrs: noinline norecurse nounwind uwtable | ||
define dso_local double @get(double* nocapture %x, i64 %i, i64 %j) local_unnamed_addr #0 { | ||
entry: | ||
%arrayidx = getelementptr inbounds double, double* %x, i64 %i | ||
%0 = load double, double* %arrayidx, align 8 | ||
store double 0.000000e+00, double* %arrayidx, align 8 | ||
ret double %0 | ||
} | ||
|
||
; Function Attrs: noinline norecurse nounwind uwtable | ||
define dso_local double @f(double* nocapture %x, i64 %n) #0 { | ||
entry: | ||
br label %for.cond3.preheader | ||
|
||
for.cond3.preheader: ; preds = %entry, %for.cond.cleanup6 | ||
%i = phi i64 [ %i_inc, %for.cond.cleanup6 ], [ 0, %entry ] | ||
%outersum = phi double [ %sum.1.lcssa, %for.cond.cleanup6 ], [ 0.000000e+00, %entry ] | ||
%i_inc = add nuw i64 %i, 1 | ||
; note this is now technically not exactly triangular | ||
; %cmp423 = icmp eq i64 %i, 0 | ||
; br i1 %cmp423, label %for.cond.cleanup6, label %for.body7 | ||
br label %for.body7 | ||
|
||
for.body7: ; preds = %for.cond3.preheader, %for.body7 | ||
%j = phi i64 [ %j_inc, %for.body7 ], [ 0, %for.cond3.preheader ] | ||
%innersum = phi double [ %add, %for.body7 ], [ %outersum, %for.cond3.preheader ] | ||
%call = tail call fast double @get(double* %x, i64 undef, i64 %j) | ||
%mul = fmul fast double %call, %call | ||
%add = fadd fast double %mul, %innersum | ||
%j_inc = add nuw i64 %j, 1 | ||
%exitcond = icmp eq i64 %j, %i | ||
br i1 %exitcond, label %for.cond.cleanup6, label %for.body7 | ||
|
||
for.cond.cleanup6: ; preds = %for.body7 | ||
%sum.1.lcssa = phi double [ %add, %for.body7 ] | ||
%cmp1 = icmp eq i64 %i, %n | ||
br i1 %cmp1, label %return, label %for.cond3.preheader | ||
|
||
return: ; preds = %for.cond.cleanup6 | ||
%retval.0 = phi double [ %sum.1.lcssa, %for.cond.cleanup6 ] | ||
ret double %retval.0 | ||
} | ||
|
||
; Function Attrs: noinline nounwind uwtable | ||
define dso_local double @dsumsquare(double* %x, double* %xp, i64 %n) local_unnamed_addr #1 { | ||
entry: | ||
%call = tail call fast double @__enzyme_autodiff(i8* bitcast (double (double*, i64)* @f to i8*), double* %x, double* %xp, i64 %n) | ||
ret double %call | ||
} | ||
|
||
declare dso_local double @__enzyme_autodiff(i8*, double*, double*, i64) local_unnamed_addr | ||
|
||
attributes #0 = { noinline norecurse nounwind uwtable } | ||
attributes #1 = { noinline nounwind uwtable } | ||
|
||
; CHECK: define internal {} @diffef(double* nocapture %x, double* %"x'", i64 %n, double %differeturn) #0 { | ||
; CHECK-NEXT: entry: | ||
; CHECK-NEXT: %0 = add nuw i64 %n, 1 | ||
; CHECK-NEXT: %mallocsize = mul i64 %0, 8 | ||
; CHECK-NEXT: %malloccall = tail call noalias nonnull i8* @malloc(i64 %mallocsize) | ||
; CHECK-NEXT: %call_malloccache = bitcast i8* %malloccall to double** | ||
; CHECK-NEXT: br label %for.cond3.preheader | ||
|
||
; CHECK: for.cond3.preheader: ; preds = %for.cond.cleanup6, %entry | ||
; CHECK-NEXT: %iv = phi i64 [ %iv.next, %for.cond.cleanup6 ], [ 0, %entry ] | ||
; CHECK-NEXT: %iv.next = add nuw i64 %iv, 1 | ||
; CHECK-NEXT: %[[mallocgep1:.+]] = getelementptr double*, double** %call_malloccache, i64 %iv | ||
; CHECK-NEXT: %mallocsize3 = mul i64 %iv.next, 8 | ||
; CHECK-NEXT: %malloccall4 = tail call noalias nonnull i8* @malloc(i64 %mallocsize3) | ||
; CHECK-NEXT: %call_malloccache5 = bitcast i8* %malloccall4 to double* | ||
; CHECK-NEXT: store double* %call_malloccache5, double** %[[mallocgep1]] | ||
; CHECK-NEXT: br label %for.body7 | ||
|
||
; CHECK: for.body7: ; preds = %for.body7, %for.cond3.preheader | ||
; CHECK-NEXT: %iv1 = phi i64 [ %iv.next2, %for.body7 ], [ 0, %for.cond3.preheader ] | ||
; CHECK-NEXT: %iv.next2 = add nuw i64 %iv1, 1 | ||
; CHECK-NEXT: %[[augmented:.+]] = call { {}, double } @augmented_get(double* %x, double* %"x'", i64 undef, i64 %iv1) | ||
; CHECK-NEXT: %[[retval:.+]] = extractvalue { {}, double } %[[augmented]], 1 | ||
; CHECK-NEXT: %[[mallocgep2:.+]] = getelementptr double, double* %call_malloccache5, i64 %iv1 | ||
; CHECK-NEXT: store double %[[retval]], double* %[[mallocgep2]] | ||
; CHECK-NEXT: %exitcond = icmp eq i64 %iv1, %iv | ||
; CHECK-NEXT: br i1 %exitcond, label %for.cond.cleanup6, label %for.body7 | ||
|
||
; CHECK: for.cond.cleanup6: ; preds = %for.body7 | ||
; CHECK-NEXT: %cmp1 = icmp eq i64 %iv, %n | ||
; CHECK-NEXT: br i1 %cmp1, label %invertfor.cond.cleanup6, label %for.cond3.preheader | ||
|
||
; CHECK: invertentry: ; preds = %invertfor.cond3.preheader | ||
; CHECK-NEXT: tail call void @free(i8* nonnull %malloccall) | ||
; CHECK-NEXT: ret {} undef | ||
|
||
; CHECK: invertfor.cond3.preheader: ; preds = %invertfor.body7 | ||
; CHECK-NEXT: %[[innerdatai8:.+]] = bitcast double* %[[innerdata:.+]] to i8* | ||
; CHECK-NEXT: tail call void @free(i8* nonnull %[[innerdatai8]]) | ||
; CHECK-NEXT: %[[done1:.+]] = icmp eq i64 %"iv'phi", 0 | ||
; CHECK-NEXT: br i1 %[[done1]], label %invertentry, label %invertfor.cond.cleanup6 | ||
|
||
; CHECK: invertfor.body7: ; preds = %invertfor.cond.cleanup6, %invertfor.body7 | ||
; CHECK-NEXT: %"iv1'phi" = phi i64 [ %"iv'phi", %invertfor.cond.cleanup6 ], [ %[[subinner:.+]], %invertfor.body7 ] | ||
; CHECK-NEXT: %[[subinner]] = sub i64 %"iv1'phi", 1 | ||
; CHECK-NEXT: %[[invertedgep2:.+]] = getelementptr double, double* %[[innerdata]], i64 %"iv1'phi" | ||
; CHECK-NEXT: %[[cached:.+]] = load double, double* %[[invertedgep2]], !invariant.load !0 | ||
; CHECK-NEXT: %m0diffecall = fmul fast double %differeturn, %[[cached]] | ||
; CHECK-NEXT: %[[innerdiffe:.+]] = fadd fast double %m0diffecall, %m0diffecall | ||
; CHECK-NEXT: %[[dcall:.+]] = call {} @diffeget(double* %x, double* %"x'", i64 undef, i64 %"iv1'phi", double %[[innerdiffe]], {} undef) | ||
; CHECK-NEXT: %[[done2:.+]] = icmp eq i64 %"iv1'phi", 0 | ||
; CHECK-NEXT: br i1 %[[done2]], label %invertfor.cond3.preheader, label %invertfor.body7 | ||
|
||
; CHECK: invertfor.cond.cleanup6: ; preds = %for.cond.cleanup6, %invertfor.cond3.preheader | ||
; CHECK-NEXT: %"iv'phi" = phi i64 [ %[[subouter:.+]], %invertfor.cond3.preheader ], [ %n, %for.cond.cleanup6 ] | ||
; CHECK-NEXT: %[[subouter]] = sub i64 %"iv'phi", 1 | ||
; CHECK-NEXT: %[[invertedgep1:.+]] = getelementptr double*, double** %call_malloccache, i64 %"iv'phi" | ||
; CHECK-NEXT: %[[innerdata]] = load double*, double** %[[invertedgep1]] | ||
; CHECK-NEXT: br label %invertfor.body7 | ||
; CHECK-NEXT: } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters