|
| 1 | +; RUN: opt < %s %loadEnzyme -enzyme -enzyme_preopt=false -mem2reg -instsimplify -adce -correlated-propagation -simplifycfg -S | FileCheck %s |
| 2 | + |
| 3 | +; Function Attrs: noinline norecurse nounwind uwtable |
| 4 | +define dso_local zeroext i1 @metasubf(double* nocapture %x) local_unnamed_addr #0 { |
| 5 | +entry: |
| 6 | + %arrayidx = getelementptr inbounds double, double* %x, i64 1 |
| 7 | + store double 3.000000e+00, double* %arrayidx, align 8 |
| 8 | + %0 = load double, double* %x, align 8 |
| 9 | + %cmp = fcmp fast oeq double %0, 2.000000e+00 |
| 10 | + ret i1 %cmp |
| 11 | +} |
| 12 | + |
| 13 | +define dso_local zeroext i1 @omegasubf(double* nocapture %x) local_unnamed_addr #0 { |
| 14 | +entry: |
| 15 | + %arrayidx = getelementptr inbounds double, double* %x, i64 1 |
| 16 | + store double 3.000000e+00, double* %arrayidx, align 8 |
| 17 | + %0 = load double, double* %x, align 8 |
| 18 | + %cmp = fcmp fast oeq double %0, 2.000000e+00 |
| 19 | + ret i1 %cmp |
| 20 | +} |
| 21 | + |
| 22 | +; Function Attrs: noinline norecurse nounwind uwtable |
| 23 | +define dso_local zeroext i1 @subf(double* nocapture %x) local_unnamed_addr #0 { |
| 24 | +entry: |
| 25 | + %0 = load double, double* %x, align 8 |
| 26 | + %mul = fmul fast double %0, 2.000000e+00 |
| 27 | + store double %mul, double* %x, align 8 |
| 28 | + %call = tail call zeroext i1 @omegasubf(double* %x) |
| 29 | + %call2 = tail call zeroext i1 @metasubf(double* %x) |
| 30 | + ret i1 %call2 |
| 31 | +} |
| 32 | + |
| 33 | +; Function Attrs: noinline norecurse nounwind uwtable |
| 34 | +define dso_local void @f(double* nocapture %x) #0 { |
| 35 | +entry: |
| 36 | + %call = tail call zeroext i1 @subf(double* %x) |
| 37 | + %sel = select i1 %call, double 2.000000e+00, double 3.000000e+00 |
| 38 | + store double %sel, double* %x, align 8 |
| 39 | + ret void |
| 40 | +} |
| 41 | + |
| 42 | +; Function Attrs: noinline nounwind uwtable |
| 43 | +define dso_local double @dsumsquare(double* %x, double* %xp) local_unnamed_addr #1 { |
| 44 | +entry: |
| 45 | + %call = tail call fast double @__enzyme_autodiff(i8* bitcast (void (double*)* @f to i8*), double* %x, double* %xp) |
| 46 | + ret double %call |
| 47 | +} |
| 48 | + |
| 49 | +declare dso_local double @__enzyme_autodiff(i8*, double*, double*) local_unnamed_addr |
| 50 | + |
| 51 | +attributes #0 = { noinline norecurse nounwind uwtable } |
| 52 | +attributes #1 = { noinline nounwind uwtable } |
| 53 | + |
| 54 | +; CHECK: define internal {} @diffef(double* nocapture %x, double* %"x'") |
| 55 | +; CHECK-NEXT: entry: |
| 56 | +; CHECK-NEXT: %0 = call { { {}, {} }, i1, i1 } @augmented_subf(double* %x, double* %"x'") |
| 57 | +; CHECK-NEXT: %1 = extractvalue { { {}, {} }, i1, i1 } %0, 1 |
| 58 | +; CHECK-NEXT: %sel = select i1 %1, double 2.000000e+00, double 3.000000e+00 |
| 59 | +; CHECK-NEXT: store double %sel, double* %x, align 8 |
| 60 | +; CHECK-NEXT: store double 0.000000e+00, double* %"x'" |
| 61 | +; CHECK-NEXT: %[[dsubf:.+]] = call {} @diffesubf(double* nonnull %x, double* %"x'", { {}, {} } undef) |
| 62 | +; CHECK-NEXT: ret {} undef |
| 63 | +; CHECK-NEXT: } |
| 64 | + |
| 65 | +; CHECK: define internal { {}, i1, i1 } @augmented_metasubf(double* nocapture %x, double* %"x'") |
| 66 | +; CHECK-NEXT: entry: |
| 67 | +; CHECK-NEXT: %0 = alloca { {}, i1, i1 } |
| 68 | +; CHECK-NEXT: %arrayidx = getelementptr inbounds double, double* %x, i64 1 |
| 69 | +; CHECK-NEXT: store double 3.000000e+00, double* %arrayidx, align 8 |
| 70 | +; CHECK-NEXT: %1 = load double, double* %x, align 8 |
| 71 | +; CHECK-NEXT: %cmp = fcmp fast oeq double %1, 2.000000e+00 |
| 72 | +; CHECK-NEXT: %2 = getelementptr { {}, i1, i1 }, { {}, i1, i1 }* %0, i32 0, i32 1 |
| 73 | +; CHECK-NEXT: store i1 %cmp, i1* %2 |
| 74 | +; CHECK-NEXT: %3 = load { {}, i1, i1 }, { {}, i1, i1 }* %0 |
| 75 | +; CHECK-NEXT: ret { {}, i1, i1 } %3 |
| 76 | +; CHECK-NEXT: } |
| 77 | + |
| 78 | +; CHECK: define internal { {} } @augmented_omegasubf(double* nocapture %x, double* %"x'") |
| 79 | +; CHECK-NEXT: entry: |
| 80 | +; CHECK-NEXT: %arrayidx = getelementptr inbounds double, double* %x, i64 1 |
| 81 | +; CHECK-NEXT: store double 3.000000e+00, double* %arrayidx, align 8 |
| 82 | +; CHECK-NEXT: ret { {} } undef |
| 83 | +; CHECK-NEXT: } |
| 84 | + |
| 85 | +; CHECK: define internal { { {}, {} }, i1, i1 } @augmented_subf(double* nocapture %x, double* %"x'") |
| 86 | +; CHECK-NEXT: entry: |
| 87 | +; CHECK-NEXT: %0 = alloca { { {}, {} }, i1, i1 } |
| 88 | +; CHECK-NEXT: %1 = load double, double* %x, align 8 |
| 89 | +; CHECK-NEXT: %mul = fmul fast double %1, 2.000000e+00 |
| 90 | +; CHECK-NEXT: store double %mul, double* %x, align 8 |
| 91 | +; CHECK-NEXT: %2 = call { {} } @augmented_omegasubf(double* %x, double* %"x'") |
| 92 | +; CHECK-NEXT: %3 = call { {}, i1, i1 } @augmented_metasubf(double* %x, double* %"x'") |
| 93 | +; CHECK-NEXT: %4 = extractvalue { {}, i1, i1 } %3, 1 |
| 94 | +; CHECK-NEXT: %antiptr_call2 = extractvalue { {}, i1, i1 } %3, 2 |
| 95 | +; CHECK-NEXT: %5 = getelementptr { { {}, {} }, i1, i1 }, { { {}, {} }, i1, i1 }* %0, i32 0, i32 1 |
| 96 | +; CHECK-NEXT: store i1 %4, i1* %5 |
| 97 | +; CHECK-NEXT: %6 = getelementptr { { {}, {} }, i1, i1 }, { { {}, {} }, i1, i1 }* %0, i32 0, i32 2 |
| 98 | +; CHECK-NEXT: store i1 %antiptr_call2, i1* %6 |
| 99 | +; CHECK-NEXT: %[[toret:.+]] = load { { {}, {} }, i1, i1 }, { { {}, {} }, i1, i1 }* %0 |
| 100 | +; CHECK-NEXT: ret { { {}, {} }, i1, i1 } %[[toret]] |
| 101 | +; CHECK-NEXT: } |
| 102 | + |
| 103 | +; CHECK: define internal {} @diffesubf(double* nocapture %x, double* %"x'", { {}, {} } %tapeArg) |
| 104 | +; CHECK-NEXT: entry: |
| 105 | +; CHECK-NEXT: %0 = call {} @diffemetasubf(double* %x, double* %"x'", {} undef) |
| 106 | +; CHECK-NEXT: %1 = call {} @diffeomegasubf(double* %x, double* %"x'", {} undef) |
| 107 | +; CHECK-NEXT: %2 = load double, double* %"x'" |
| 108 | +; CHECK-NEXT: store double 0.000000e+00, double* %"x'" |
| 109 | +; CHECK-NEXT: %m0diffe = fmul fast double %2, 2.000000e+00 |
| 110 | +; CHECK-NEXT: %3 = load double, double* %"x'" |
| 111 | +; CHECK-NEXT: %4 = fadd fast double %3, %m0diffe |
| 112 | +; CHECK-NEXT: store double %4, double* %"x'" |
| 113 | +; CHECK-NEXT: ret {} undef |
| 114 | +; CHECK-NEXT: } |
| 115 | + |
| 116 | +; CHECK: define internal {} @diffemetasubf(double* nocapture %x, double* %"x'", {} %tapeArg) |
| 117 | +; CHECK-NEXT: entry: |
| 118 | +; CHECK-NEXT: %[[tostore:.+]] = getelementptr inbounds double, double* %"x'", i64 1 |
| 119 | +; CHECK-NEXT: store double 0.000000e+00, double* %[[tostore]], align 8 |
| 120 | +; CHECK-NEXT: ret {} undef |
| 121 | +; CHECK-NEXT: } |
| 122 | + |
| 123 | +; CHECK: define internal {} @diffeomegasubf(double* nocapture %x, double* %"x'", {} %tapeArg) |
| 124 | +; CHECK-NEXT: entry: |
| 125 | +; CHECK-NEXT: %[[tostore:.+]] = getelementptr inbounds double, double* %"x'", i64 1 |
| 126 | +; CHECK-NEXT: store double 0.000000e+00, double* %[[tostore]], align 8 |
| 127 | +; CHECK-NEXT: ret {} undef |
| 128 | +; CHECK-NEXT: } |
0 commit comments