summaryrefslogtreecommitdiffstats
path: root/polly/lib
diff options
context:
space:
mode:
Diffstat (limited to 'polly/lib')
-rw-r--r--polly/lib/CodeGen/CodeGeneration.cpp3
-rw-r--r--polly/lib/CodeGen/IslCodeGeneration.cpp33
-rw-r--r--polly/lib/CodeGen/LoopGenerators.cpp8
3 files changed, 34 insertions, 10 deletions
diff --git a/polly/lib/CodeGen/CodeGeneration.cpp b/polly/lib/CodeGen/CodeGeneration.cpp
index f1d1487b6f2..804ff9f7ce9 100644
--- a/polly/lib/CodeGen/CodeGeneration.cpp
+++ b/polly/lib/CodeGen/CodeGeneration.cpp
@@ -448,7 +448,8 @@ void ClastStmtCodeGen::codegenForSequential(const clast_for *f) {
UpperBound = ExpGen.codegen(f->UB, IntPtrTy);
Stride = Builder.getInt(APInt_from_MPZ(f->stride));
- IV = createLoop(LowerBound, UpperBound, Stride, Builder, P, AfterBB);
+ IV = createLoop(LowerBound, UpperBound, Stride, Builder, P, AfterBB,
+ CmpInst::ICMP_SLE);
// Add loop iv to symbols.
ClastVars[f->iterator] = IV;
diff --git a/polly/lib/CodeGen/IslCodeGeneration.cpp b/polly/lib/CodeGen/IslCodeGeneration.cpp
index 48e2eba1d46..e0856eacafc 100644
--- a/polly/lib/CodeGen/IslCodeGeneration.cpp
+++ b/polly/lib/CodeGen/IslCodeGeneration.cpp
@@ -380,9 +380,15 @@ Value *IslExprBuilder::createOpICmp(__isl_take isl_ast_expr *Expr) {
case isl_ast_op_le:
Res = Builder.CreateICmpSLE(LHS, RHS);
break;
+ case isl_ast_op_lt:
+ Res = Builder.CreateICmpSLT(LHS, RHS);
+ break;
case isl_ast_op_ge:
Res = Builder.CreateICmpSGE(LHS, RHS);
break;
+ case isl_ast_op_gt:
+ Res = Builder.CreateICmpSGT(LHS, RHS);
+ break;
}
isl_ast_expr_free(Expr);
@@ -464,7 +470,9 @@ Value *IslExprBuilder::createOp(__isl_take isl_ast_expr *Expr) {
return createOpBoolean(Expr);
case isl_ast_op_eq:
case isl_ast_op_le:
+ case isl_ast_op_lt:
case isl_ast_op_ge:
+ case isl_ast_op_gt:
return createOpICmp(Expr);
}
@@ -570,7 +578,8 @@ private:
// of loop iterations.
//
// 3. With the existing code, upper bounds have been easier to implement.
- __isl_give isl_ast_expr *getUpperBound(__isl_keep isl_ast_node *For);
+ __isl_give isl_ast_expr *getUpperBound(__isl_keep isl_ast_node *For,
+ CmpInst::Predicate &Predicate);
void createFor(__isl_take isl_ast_node *For);
void createIf(__isl_take isl_ast_node *If);
@@ -579,18 +588,28 @@ private:
};
__isl_give isl_ast_expr *IslNodeBuilder::getUpperBound(
- __isl_keep isl_ast_node *For) {
+ __isl_keep isl_ast_node *For, ICmpInst::Predicate &Predicate) {
isl_id *UBID, *IteratorID;
isl_ast_expr *Cond, *Iterator, *UB, *Arg0;
+ isl_ast_op_type Type;
Cond = isl_ast_node_for_get_cond(For);
Iterator = isl_ast_node_for_get_iterator(For);
+ Type = isl_ast_expr_get_op_type(Cond);
assert(isl_ast_expr_get_type(Cond) == isl_ast_expr_op
&& "conditional expression is not an atomic upper bound");
- assert(isl_ast_expr_get_op_type(Cond) == isl_ast_op_le
- && "conditional expression is not an atomic upper bound");
+ switch (Type) {
+ case isl_ast_op_le:
+ Predicate = ICmpInst::ICMP_SLE;
+ break;
+ case isl_ast_op_lt:
+ Predicate = ICmpInst::ICMP_SLT;
+ break;
+ default:
+ llvm_unreachable("Unexpected comparision type in loop conditon");
+ }
Arg0 = isl_ast_expr_get_op_arg(Cond, 0);
@@ -626,6 +645,7 @@ void IslNodeBuilder::createFor(__isl_take isl_ast_node *For) {
Type *MaxType;
BasicBlock *AfterBlock;
Value *IV;
+ CmpInst::Predicate Predicate;
Body = isl_ast_node_for_get_body(For);
@@ -639,7 +659,7 @@ void IslNodeBuilder::createFor(__isl_take isl_ast_node *For) {
Inc = isl_ast_node_for_get_inc(For);
Iterator = isl_ast_node_for_get_iterator(For);
IteratorID = isl_ast_expr_get_id(Iterator);
- UB = getUpperBound(For);
+ UB = getUpperBound(For, Predicate);
ValueLB = ExprBuilder.create(Init);
ValueUB = ExprBuilder.create(UB);
@@ -663,7 +683,8 @@ void IslNodeBuilder::createFor(__isl_take isl_ast_node *For) {
// executed at least once, which will enable a lot of loop invariant
// code motion.
- IV = createLoop(ValueLB, ValueUB, ValueInc, Builder, P, AfterBlock);
+ IV = createLoop(ValueLB, ValueUB, ValueInc, Builder, P, AfterBlock,
+ Predicate);
IDToValue[IteratorID] = IV;
create(Body);
diff --git a/polly/lib/CodeGen/LoopGenerators.cpp b/polly/lib/CodeGen/LoopGenerators.cpp
index 2b7e58d76e8..4edd01d81ac 100644
--- a/polly/lib/CodeGen/LoopGenerators.cpp
+++ b/polly/lib/CodeGen/LoopGenerators.cpp
@@ -25,7 +25,8 @@ using namespace polly;
Value *polly::createLoop(Value *LB, Value *UB, Value *Stride,
IRBuilder<> &Builder, Pass *P,
- BasicBlock *&AfterBlock) {
+ BasicBlock *&AfterBlock,
+ ICmpInst::Predicate Predicate) {
DominatorTree &DT = P->getAnalysis<DominatorTree>();
Function *F = Builder.GetInsertBlock()->getParent();
LLVMContext &Context = F->getContext();
@@ -57,7 +58,7 @@ Value *polly::createLoop(Value *LB, Value *UB, Value *Stride,
// Exit condition.
Value *CMP;
- CMP = Builder.CreateICmpSLE(IV, UB);
+ CMP = Builder.CreateICmp(Predicate, IV, UB);
Builder.CreateCondBr(CMP, BodyBB, AfterBB);
DT.addNewBlock(BodyBB, HeaderBB);
@@ -286,7 +287,8 @@ Value *OMPGenerator::createSubfunction(Value *Stride, Value *StructData,
Builder.CreateBr(CheckNextBB);
Builder.SetInsertPoint(--Builder.GetInsertPoint());
- IV = createLoop(LowerBound, UpperBound, Stride, Builder, P, AfterBB);
+ IV = createLoop(LowerBound, UpperBound, Stride, Builder, P, AfterBB,
+ ICmpInst::ICMP_SLE);
BasicBlock::iterator LoopBody = Builder.GetInsertPoint();
Builder.SetInsertPoint(AfterBB->begin());
OpenPOWER on IntegriCloud