|
| 1 | +; RUN: %opt < %s %loadEnzyme -enzyme -enzyme-preopt=false -mem2reg -instsimplify -simplifycfg -S | FileCheck %s |
| 2 | + |
| 3 | +; Function Attrs: nounwind uwtable |
| 4 | +define dso_local void @compute(double* noalias nocapture %data, i64* noalias nocapture readnone %array, double* noalias nocapture %out) #0 { |
| 5 | +entry: |
| 6 | + br label %for.body5.preheader |
| 7 | + |
| 8 | +for.cond.cleanup: ; preds = %for.cond.cleanup4 |
| 9 | + store double 0.000000e+00, double* %data, align 8, !tbaa !2 |
| 10 | + ret void |
| 11 | + |
| 12 | +for.body5.preheader: ; preds = %entry, %for.cond.cleanup4 |
| 13 | + %indvars.iv = phi i64 [ 0, %entry ], [ %indvars.iv.next, %for.cond.cleanup4 ] |
| 14 | + %call = tail call i64 @getSize() #2 |
| 15 | + br label %for.body5 |
| 16 | + |
| 17 | +for.cond.cleanup4: ; preds = %for.body5 |
| 18 | + %arrayidx7 = getelementptr inbounds double, double* %out, i64 %indvars.iv |
| 19 | + store double %add, double* %arrayidx7, align 8, !tbaa !2 |
| 20 | + %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1 |
| 21 | + %exitcond29 = icmp eq i64 %indvars.iv.next, 10 |
| 22 | + br i1 %exitcond29, label %for.cond.cleanup, label %for.body5.preheader |
| 23 | + |
| 24 | +for.body5: ; preds = %for.body5, %for.body5.preheader |
| 25 | + %j.027 = phi i64 [ %inc, %for.body5 ], [ 0, %for.body5.preheader ] |
| 26 | + %res.026 = phi double [ %add, %for.body5 ], [ 0.000000e+00, %for.body5.preheader ] |
| 27 | + %arrayidx = getelementptr inbounds double, double* %data, i64 %j.027 |
| 28 | + %i0 = load double, double* %arrayidx, align 8, !tbaa !2 |
| 29 | + %mul = fmul double %i0, %i0 |
| 30 | + %add = fadd double %res.026, %mul |
| 31 | + %inc = add nuw i64 %j.027, 1 |
| 32 | + %exitcond = icmp eq i64 %inc, %call |
| 33 | + br i1 %exitcond, label %for.cond.cleanup4, label %for.body5 |
| 34 | +} |
| 35 | + |
| 36 | +declare dso_local i64 @getSize() local_unnamed_addr #1 |
| 37 | + |
| 38 | +; Function Attrs: nounwind |
| 39 | +declare void @llvm.assume(i1) #2 |
| 40 | + |
| 41 | +; Function Attrs: nounwind uwtable |
| 42 | +define dso_local void @call(double* %data, double* %d_data, i64* %array, double* %out, double* %d_out) local_unnamed_addr #0 { |
| 43 | +entry: |
| 44 | + tail call void (i8*, ...) @__enzyme_autodiff(i8* bitcast (void (double*, i64*, double*)* @compute to i8*), double* %data, double* %d_data, i64* %array, double* %out, double* %d_out) #2 |
| 45 | + ret void |
| 46 | +} |
| 47 | + |
| 48 | +declare dso_local void @__enzyme_autodiff(i8*, ...) local_unnamed_addr #1 |
| 49 | + |
| 50 | +attributes #0 = { nounwind uwtable "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+fxsr,+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" } |
| 51 | +attributes #1 = { "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+fxsr,+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" } |
| 52 | +attributes #2 = { nounwind } |
| 53 | + |
| 54 | +!llvm.module.flags = !{!0} |
| 55 | +!llvm.ident = !{!1} |
| 56 | + |
| 57 | +!0 = !{i32 1, !"wchar_size", i32 4} |
| 58 | +!1 = !{!"clang version 7.1.0 "} |
| 59 | +!2 = !{!3, !3, i64 0} |
| 60 | +!3 = !{!"double", !4, i64 0} |
| 61 | +!4 = !{!"omnipotent char", !5, i64 0} |
| 62 | +!5 = !{!"Simple C/C++ TBAA"} |
| 63 | + |
| 64 | +; CHECK: define internal void @diffecompute(double* noalias nocapture %data, double* nocapture %"data'", i64* noalias nocapture readnone %array, double* noalias nocapture %out, double* nocapture %"out'") |
| 65 | +; CHECK-NEXT: entry: |
| 66 | +; CHECK-NEXT: %malloccall = tail call noalias nonnull dereferenceable(80) dereferenceable_or_null(80) i8* @malloc(i64 80) |
| 67 | +; CHECK-NEXT: %_malloccache = bitcast i8* %malloccall to i64* |
| 68 | +; CHECK-NEXT: %malloccall3 = tail call noalias nonnull dereferenceable(80) dereferenceable_or_null(80) i8* @malloc(i64 80) |
| 69 | +; CHECK-NEXT: %i0_malloccache = bitcast i8* %malloccall3 to double** |
| 70 | +; CHECK-NEXT: br label %for.body5.preheader |
| 71 | + |
| 72 | +; CHECK: for.cond.cleanup: ; preds = %for.cond.cleanup4 |
| 73 | +; CHECK-NEXT: store double 0.000000e+00, double* %data, align 8, !tbaa !2 |
| 74 | +; CHECK-NEXT: store double 0.000000e+00, double* %"data'", align 8 |
| 75 | +; CHECK-NEXT: br label %invertfor.cond.cleanup4 |
| 76 | + |
| 77 | +; CHECK: for.body5.preheader: ; preds = %for.cond.cleanup4, %entry |
| 78 | +; CHECK-NEXT: %iv = phi i64 [ %iv.next, %for.cond.cleanup4 ], [ 0, %entry ] |
| 79 | +; CHECK-NEXT: %iv.next = add nuw nsw i64 %iv, 1 |
| 80 | +; CHECK-NEXT: %call = tail call i64 @getSize() |
| 81 | +; CHECK-NEXT: %0 = add i64 %call, -1 |
| 82 | +; CHECK-NEXT: %1 = getelementptr inbounds i64, i64* %_malloccache, i64 %iv |
| 83 | +; CHECK-NEXT: store i64 %0, i64* %1, align 8, !invariant.group !6 |
| 84 | +; CHECK-NEXT: %2 = getelementptr inbounds double*, double** %i0_malloccache, i64 %iv |
| 85 | +; CHECK-NEXT: %mallocsize = mul nuw nsw i64 %call, 8 |
| 86 | +; CHECK-NEXT: %malloccall5 = tail call noalias nonnull i8* @malloc(i64 %mallocsize) |
| 87 | +; CHECK-NEXT: %i0_malloccache6 = bitcast i8* %malloccall5 to double* |
| 88 | +; CHECK-NEXT: store double* %i0_malloccache6, double** %2, align 8, !invariant.group !7 |
| 89 | +; CHECK-NEXT: %3 = getelementptr inbounds double*, double** %i0_malloccache, i64 %iv |
| 90 | +; CHECK-NEXT: %4 = load double*, double** %3, align 8, !dereferenceable !8, !invariant.group !7 |
| 91 | +; CHECK-NEXT: %5 = bitcast double* %4 to i8* |
| 92 | +; CHECK-NEXT: %6 = bitcast double* %data to i8* |
| 93 | +; CHECK-NEXT: %7 = mul nuw nsw i64 8, %call |
| 94 | +; CHECK-NEXT: call void @llvm.memcpy.p0i8.p0i8.i64(i8* nonnull align 8 %5, i8* nonnull align 8 %6, i64 %7, i1 false) |
| 95 | +; CHECK-NEXT: br label %for.body5 |
| 96 | + |
| 97 | +; CHECK: for.cond.cleanup4: ; preds = %for.body5 |
| 98 | +; CHECK-NEXT: %arrayidx7 = getelementptr inbounds double, double* %out, i64 %iv |
| 99 | +; CHECK-NEXT: store double %add, double* %arrayidx7, align 8, !tbaa !2 |
| 100 | +; CHECK-NEXT: %exitcond29 = icmp eq i64 %iv.next, 10 |
| 101 | +; CHECK-NEXT: br i1 %exitcond29, label %for.cond.cleanup, label %for.body5.preheader |
| 102 | + |
| 103 | +; CHECK: for.body5: ; preds = %for.body5, %for.body5.preheader |
| 104 | +; CHECK-NEXT: %iv1 = phi i64 [ %iv.next2, %for.body5 ], [ 0, %for.body5.preheader ] |
| 105 | +; CHECK-NEXT: %res.026 = phi double [ %add, %for.body5 ], [ 0.000000e+00, %for.body5.preheader ] |
| 106 | +; CHECK-NEXT: %iv.next2 = add nuw nsw i64 %iv1, 1 |
| 107 | +; CHECK-NEXT: %arrayidx = getelementptr inbounds double, double* %data, i64 %iv1 |
| 108 | +; CHECK-NEXT: %i0 = load double, double* %arrayidx, align 8, !tbaa !2 |
| 109 | +; CHECK-NEXT: %mul = fmul double %i0, %i0 |
| 110 | +; CHECK-NEXT: %add = fadd double %res.026, %mul |
| 111 | +; CHECK-NEXT: %exitcond = icmp eq i64 %iv.next2, %call |
| 112 | +; CHECK-NEXT: br i1 %exitcond, label %for.cond.cleanup4, label %for.body5 |
| 113 | + |
| 114 | +; CHECK: invertentry: ; preds = %invertfor.body5.preheader |
| 115 | +; CHECK-NEXT: tail call void @free(i8* nonnull %malloccall) |
| 116 | +; CHECK-NEXT: tail call void @free(i8* nonnull %malloccall3) |
| 117 | +; CHECK-NEXT: ret void |
| 118 | + |
| 119 | +; CHECK: invertfor.body5.preheader: ; preds = %invertfor.body5 |
| 120 | +; CHECK-NEXT: %8 = icmp eq i64 %"iv'ac.0", 0 |
| 121 | +; CHECK-NEXT: %_unwrap7 = getelementptr inbounds double*, double** %i0_malloccache, i64 %"iv'ac.0" |
| 122 | +; CHECK-NEXT: %forfree8 = load double*, double** %_unwrap7, align 8, !dereferenceable !8, !invariant.group !7 |
| 123 | +; CHECK-NEXT: %9 = bitcast double* %forfree8 to i8* |
| 124 | +; CHECK-NEXT: tail call void @free(i8* nonnull %9) |
| 125 | +; CHECK-NEXT: br i1 %8, label %invertentry, label %incinvertfor.body5.preheader |
| 126 | + |
| 127 | +; CHECK: incinvertfor.body5.preheader: ; preds = %invertfor.body5.preheader |
| 128 | +; CHECK-NEXT: %10 = add nsw i64 %"iv'ac.0", -1 |
| 129 | +; CHECK-NEXT: br label %invertfor.cond.cleanup4 |
| 130 | + |
| 131 | +; CHECK: invertfor.cond.cleanup4: ; preds = %incinvertfor.body5.preheader, %for.cond.cleanup |
| 132 | +; CHECK-NEXT: %"add'de.0" = phi double [ 0.000000e+00, %for.cond.cleanup ], [ %23, %incinvertfor.body5.preheader ] |
| 133 | +; CHECK-NEXT: %"iv'ac.0" = phi i64 [ 9, %for.cond.cleanup ], [ %10, %incinvertfor.body5.preheader ] |
| 134 | +; CHECK-NEXT: %"arrayidx7'ipg_unwrap" = getelementptr inbounds double, double* %"out'", i64 %"iv'ac.0" |
| 135 | +; CHECK-NEXT: %11 = load double, double* %"arrayidx7'ipg_unwrap", align 8 |
| 136 | +; CHECK-NEXT: store double 0.000000e+00, double* %"arrayidx7'ipg_unwrap", align 8 |
| 137 | +; CHECK-NEXT: %12 = fadd fast double %"add'de.0", %11 |
| 138 | +; CHECK-NEXT: %13 = getelementptr inbounds i64, i64* %_malloccache, i64 %"iv'ac.0" |
| 139 | +; CHECK-NEXT: %14 = load i64, i64* %13, align 8, !invariant.group !6 |
| 140 | +; CHECK-NEXT: br label %invertfor.body5 |
| 141 | + |
| 142 | +; CHECK: invertfor.body5: ; preds = %incinvertfor.body5, %invertfor.cond.cleanup4 |
| 143 | +; CHECK-NEXT: %"add'de.1" = phi double [ %12, %invertfor.cond.cleanup4 ], [ %23, %incinvertfor.body5 ] |
| 144 | +; CHECK-NEXT: %"iv1'ac.0" = phi i64 [ %14, %invertfor.cond.cleanup4 ], [ %24, %incinvertfor.body5 ] |
| 145 | +; CHECK-NEXT: %15 = getelementptr inbounds double*, double** %i0_malloccache, i64 %"iv'ac.0" |
| 146 | +; CHECK-NEXT: %16 = load double*, double** %15, align 8, !dereferenceable !8, !invariant.group !7 |
| 147 | +; CHECK-NEXT: %17 = getelementptr inbounds double, double* %16, i64 %"iv1'ac.0" |
| 148 | +; CHECK-NEXT: %18 = load double, double* %17, align 8, !invariant.group !9 |
| 149 | +; CHECK-NEXT: %m0diffei0 = fmul fast double %"add'de.1", %18 |
| 150 | +; CHECK-NEXT: %m1diffei0 = fmul fast double %"add'de.1", %18 |
| 151 | +; CHECK-NEXT: %19 = fadd fast double %m0diffei0, %m1diffei0 |
| 152 | +; CHECK-NEXT: %"arrayidx'ipg_unwrap" = getelementptr inbounds double, double* %"data'", i64 %"iv1'ac.0" |
| 153 | +; CHECK-NEXT: %20 = load double, double* %"arrayidx'ipg_unwrap", align 8 |
| 154 | +; CHECK-NEXT: %21 = fadd fast double %20, %19 |
| 155 | +; CHECK-NEXT: store double %21, double* %"arrayidx'ipg_unwrap", align 8 |
| 156 | +; CHECK-NEXT: %22 = icmp eq i64 %"iv1'ac.0", 0 |
| 157 | +; CHECK-NEXT: %23 = select{{( fast)?}} i1 %22, double 0.000000e+00, double %"add'de.1" |
| 158 | +; CHECK-NEXT: br i1 %22, label %invertfor.body5.preheader, label %incinvertfor.body5 |
| 159 | + |
| 160 | +; CHECK: incinvertfor.body5: ; preds = %invertfor.body5 |
| 161 | +; CHECK-NEXT: %24 = add nsw i64 %"iv1'ac.0", -1 |
| 162 | +; CHECK-NEXT: br label %invertfor.body5 |
| 163 | +; CHECK-NEXT: } |
0 commit comments