Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix calling convention and other small bugs #16

Merged
merged 12 commits into from
Oct 15, 2019
Prev Previous commit
Next Next commit
fix subtle if bug
  • Loading branch information
wsmoses committed Oct 12, 2019
commit d04d3e437c9e0a5bfc995e7a8a1d6f462f6cd977
22 changes: 13 additions & 9 deletions enzyme/Enzyme/ActiveVariable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -473,15 +473,19 @@ bool isconstantM(Instruction* inst, SmallPtrSetImpl<Value*> &constants, SmallPtr
return false;
}
}

constants.insert(inst);
constants.insert(constants2.begin(), constants2.end());
constants.insert(constants_tmp.begin(), constants_tmp.end());
//if (directions == 3)
// nonconstant.insert(nonconstant2.begin(), nonconstant2.end());
if (printconst)
llvm::errs() << "constant(" << (int)directions << ") call:" << *inst << "\n";
return true;

//! TODO: Really need an attribute that determines whether a function can access a global (not even necessarily read)
//if (ci->hasFnAttr(Attribute::ReadNone) || ci->hasFnAttr(Attribute::ArgMemOnly))
{
constants.insert(inst);
constants.insert(constants2.begin(), constants2.end());
constants.insert(constants_tmp.begin(), constants_tmp.end());
//if (directions == 3)
// nonconstant.insert(nonconstant2.begin(), nonconstant2.end());
if (printconst)
llvm::errs() << "constant(" << (int)directions << ") call:" << *inst << "\n";
return true;
}
} else {
for(auto& a: inst->operands()) {
if (!isconstantValueM(a, constants2, nonconstant2, retvals, originalInstructions, UP)) {
Expand Down
6 changes: 6 additions & 0 deletions enzyme/Enzyme/GradientUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -958,6 +958,12 @@ void GradientUtils::branchToCorrespondingTarget(BasicBlock* ctx, IRBuilder <>& B
llvm::errs() << *branch << "\n";
llvm_unreachable("unknown successor for replacephi");
}
if (&*BuilderM.GetInsertPoint() == pair.second) {
if (pair.second->getNextNode())
BuilderM.SetInsertPoint(pair.second->getNextNode());
else
BuilderM.SetInsertPoint(pair.second->getParent());
}
pair.second->replaceAllUsesWith(val);
pair.second->eraseFromParent();
}
Expand Down
1 change: 1 addition & 0 deletions enzyme/test/Enzyme/insertsort.ll
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
; RUN: opt < %s %loadEnzyme -enzyme -enzyme_preopt=false -inline -mem2reg -instcombine -correlated-propagation -adce -instcombine -simplifycfg -early-cse -simplifycfg -S | FileCheck %s
; XFAIL: *

; Function Attrs: noinline norecurse nounwind uwtable
define dso_local void @insertion_sort_inner(float* nocapture %array, i32 %i) local_unnamed_addr #0 {
entry:
Expand Down
36 changes: 14 additions & 22 deletions enzyme/test/Enzyme/recursum.ll
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
; RUN: opt < %s %loadEnzyme -enzyme -enzyme_preopt=false -inline -mem2reg -instsimplify -adce -loop-deletion -correlated-propagation -simplifycfg -ipconstprop -deadargelim -S -early-cse -instcombine -print-after-all | FileCheck %s
; RUN: opt < %s %loadEnzyme -enzyme -enzyme_preopt=false -inline -mem2reg -instsimplify -adce -loop-deletion -correlated-propagation -simplifycfg -ipconstprop -deadargelim -S -early-cse -instcombine -jump-threading | FileCheck %s

; #include <stdio.h>
; #include <stdlib.h>
Expand Down Expand Up @@ -67,37 +67,29 @@ attributes #2 = { nounwind }
; CHECK: define internal {{(dso_local )?}}double @differecsum.1(double* %x, double* %"x'", i32 %n)
; CHECK-NEXT: entry:
; CHECK-NEXT: switch i32 %n, label %if.end3 [
; CHECK-NEXT: i32 0, label %invertreturn
; CHECK-NEXT: i32 1, label %if.then2
; CHECK-NEXT: i32 0, label %invertentry
; CHECK-NEXT: i32 1, label %invertif.then2
; CHECK-NEXT: ]

; CHECK: if.then2: ; preds = %entry
; CHECK-NEXT: %0 = load double, double* %x, align 8, !tbaa !2
; CHECK-NEXT: br label %invertreturn

; CHECK: if.end3: ; preds = %entry
; CHECK-NEXT: %div = lshr i32 %n, 1
; CHECK-NEXT: %idx.ext = zext i32 %div to i64
; CHECK-NEXT: %add.ptr = getelementptr inbounds double, double* %x, i64 %idx.ext
; CHECK-NEXT: %"add.ptr'ipg" = getelementptr double, double* %"x'", i64 %idx.ext
; CHECK-NEXT: %1 = sub i32 %n, %div
; CHECK-NEXT: %2 = call double @differecsum.1(double* %add.ptr, double* %"add.ptr'ipg", i32 %1)
; CHECK-NEXT: %3 = call double @differecsum.1(double* %x, double* %"x'", i32 %div)
; CHECK-NEXT: %add = fadd fast double %2, %3
; CHECK-NEXT: %[[sub:.+]] = sub i32 %n, %div
; CHECK-NEXT: %[[dsum1:.+]] = call double @differecsum.1(double* %add.ptr, double* %"add.ptr'ipg", i32 %[[sub]])
; CHECK-NEXT: %[[dsum2:.+]] = call double @differecsum.1(double* %x, double* %"x'", i32 %div)
; CHECK-NEXT: %add = fadd fast double %[[dsum1]], %[[dsum2]]
; CHECK-NEXT: br label %invertentry

; CHECK: invertentry: ; preds = %invertreturn, %if.end3, %invertif.then2
; CHECK-NEXT: %toreturn.0 = phi double [ %add, %if.end3 ], [ %retval.0, %invertif.then2 ], [ %retval.0, %invertreturn ]
; CHECK: invertentry:
; CHECK-NEXT: %toreturn.0 = phi double [ %add, %if.end3 ], [ %[[xload:.+]], %invertif.then2 ], [ 0.000000e+00, %entry ]
; CHECK-NEXT: ret double %toreturn.0

; CHECK: invertif.then2: ; preds = %invertreturn
; CHECK-NEXT: %4 = load double, double* %"x'", align 8
; CHECK-NEXT: %5 = fadd fast double %4, 1.000000e+00
; CHECK-NEXT: store double %5, double* %"x'", align 8
; CHECK: invertif.then2:
; CHECK-NEXT: %[[xload]] = load double, double* %x, align 8, !tbaa !2
; CHECK-NEXT: %[[predx:.+]] = load double, double* %"x'", align 8
; CHECK-NEXT: %[[postdx:.+]] = fadd fast double %[[predx]], 1.000000e+00
; CHECK-NEXT: store double %[[postdx]], double* %"x'", align 8
; CHECK-NEXT: br label %invertentry

; CHECK: invertreturn: ; preds = %entry, %if.then2
; CHECK-NEXT: %[[where:.+]] = phi i1 [ true, %if.then2 ], [ false, %entry ]
; CHECK-NEXT: %retval.0 = phi double [ %0, %if.then2 ], [ 0.000000e+00, %entry ]
; CHECK-NEXT: br i1 %[[where]], label %invertif.then2, label %invertentry
; CHECK-NEXT: }