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 the incredibly stupid plug AssertingVH bug #4

Merged
merged 7 commits into from
Sep 13, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
working LLVM 6?
  • Loading branch information
wsmoses committed Sep 13, 2019
commit 68a85769f726aae2cc96c197915a1d14b2d8a562
Binary file removed enzyme/Enzyme/SCEV/.ScalarEvolutionExpander.cpp.swp
Binary file not shown.
54 changes: 53 additions & 1 deletion enzyme/Enzyme/SCEV/ScalarEvolutionExpander.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1678,6 +1678,58 @@ Value *fake::SCEVExpander::visitUMaxExpr(const SCEVUMaxExpr *S) {
return LHS;
}

#if LLVM_VERSION_MAJOR == 6
Value *SCEVExpander::visitSMinExpr(const SCEVSMinExpr *S) {
Value *LHS = expand(S->getOperand(S->getNumOperands() - 1));
Type *Ty = LHS->getType();
for (int i = S->getNumOperands() - 2; i >= 0; --i) {
// In the case of mixed integer and pointer types, do the
// rest of the comparisons as integer.
Type *OpTy = S->getOperand(i)->getType();
if (OpTy->isIntegerTy() != Ty->isIntegerTy()) {
Ty = SE.getEffectiveSCEVType(Ty);
LHS = InsertNoopCastOfTo(LHS, Ty);
}
Value *RHS = expandCodeFor(S->getOperand(i), Ty);
Value *ICmp = Builder.CreateICmpSLT(LHS, RHS);
rememberInstruction(ICmp);
Value *Sel = Builder.CreateSelect(ICmp, LHS, RHS, "smin");
rememberInstruction(Sel);
LHS = Sel;
}
// In the case of mixed integer and pointer types, cast the
// final result back to the pointer type.
if (LHS->getType() != S->getType())
LHS = InsertNoopCastOfTo(LHS, S->getType());
return LHS;
}

Value *SCEVExpander::visitUMinExpr(const SCEVUMinExpr *S) {
Value *LHS = expand(S->getOperand(S->getNumOperands() - 1));
Type *Ty = LHS->getType();
for (int i = S->getNumOperands() - 2; i >= 0; --i) {
// In the case of mixed integer and pointer types, do the
// rest of the comparisons as integer.
Type *OpTy = S->getOperand(i)->getType();
if (OpTy->isIntegerTy() != Ty->isIntegerTy()) {
Ty = SE.getEffectiveSCEVType(Ty);
LHS = InsertNoopCastOfTo(LHS, Ty);
}
Value *RHS = expandCodeFor(S->getOperand(i), Ty);
Value *ICmp = Builder.CreateICmpULT(LHS, RHS);
rememberInstruction(ICmp);
Value *Sel = Builder.CreateSelect(ICmp, LHS, RHS, "umin");
rememberInstruction(Sel);
LHS = Sel;
}
// In the case of mixed integer and pointer types, cast the
// final result back to the pointer type.
if (LHS->getType() != S->getType())
LHS = InsertNoopCastOfTo(LHS, S->getType());
return LHS;
}
#endif

Value *fake::SCEVExpander::expandCodeFor(const SCEV *SH, Type *Ty,
Instruction *IP) {
setInsertPoint(IP);
Expand Down Expand Up @@ -1885,7 +1937,7 @@ fake::SCEVExpander::replaceCongruentIVs(Loop *L, const DominatorTree *DT,
Phis.push_back(&PN);

if (TTI)
llvm::sort(Phis.begin(), Phis.end(), [](Value *LHS, Value *RHS) {
std::sort(Phis.begin(), Phis.end(), [](Value *LHS, Value *RHS) {
// Put pointers at the back and make sure pointer < pointer = false.
if (!LHS->getType()->isIntegerTy() || !RHS->getType()->isIntegerTy())
return RHS->getType()->isIntegerTy() && !LHS->getType()->isIntegerTy();
Expand Down
6 changes: 6 additions & 0 deletions enzyme/Enzyme/SCEV/ScalarEvolutionExpander.h
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,12 @@ namespace llvm {

Value *visitUMaxExpr(const SCEVUMaxExpr *S);

#if LLVM_VERSION_MAJOR == 6
Value *visitSMinExpr(const SCEVSMinExpr *S);

Value *visitUMinExpr(const SCEVUMinExpr *S);
#endif

Value *visitUnknown(const SCEVUnknown *S) {
return S->getValue();
}
Expand Down