Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/llvm/llvm-project.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/polly/lib
diff options
context:
space:
mode:
authorTobias Grosser <tobias@grosser.es>2015-06-03 09:31:30 +0300
committerTobias Grosser <tobias@grosser.es>2015-06-03 09:31:30 +0300
commitcb73f150d4dee783784b5c3bb9deac4d3357624a (patch)
tree8d4b46ce7e30c33debf031afeb6cd4ee4a01330a /polly/lib
parentdc9293d051e290ed3f3438a082cbf0d10c773245 (diff)
Translate power-of-two floor-division into ashr
Power-of-two floor divisions can be translated into an arithmetic shift operation. This allows us to replace a complex lowering that requires division operations: %pexp.fdiv_q.0 = sub i64 %21, 128 %pexp.fdiv_q.1 = add i64 %pexp.fdiv_q.0, 1 %pexp.fdiv_q.2 = icmp slt i64 %21, 0 %pexp.fdiv_q.3 = select i1 %pexp.fdiv_q.2, i64 %pexp.fdiv_q.1, i64 %21 %pexp.fdiv_q.4 = sdiv i64 %pexp.fdiv_q.3, 128 with a simple ashr: %polly.fdiv_q.shr = ashr i64 %21, 7 llvm-svn: 238905
Diffstat (limited to 'polly/lib')
-rw-r--r--polly/lib/CodeGen/IslExprBuilder.cpp5
1 files changed, 5 insertions, 0 deletions
diff --git a/polly/lib/CodeGen/IslExprBuilder.cpp b/polly/lib/CodeGen/IslExprBuilder.cpp
index 60a46531f2e9..27c72486c7e0 100644
--- a/polly/lib/CodeGen/IslExprBuilder.cpp
+++ b/polly/lib/CodeGen/IslExprBuilder.cpp
@@ -301,6 +301,11 @@ Value *IslExprBuilder::createOpBin(__isl_take isl_ast_expr *Expr) {
Res = Builder.CreateUDiv(LHS, RHS, "pexp.p_div_q");
break;
case isl_ast_op_fdiv_q: { // Round towards -infty
+ auto &Int = dyn_cast<ConstantInt>(RHS)->getValue();
+ if (Int.isPowerOf2()) {
+ Res = Builder.CreateAShr(LHS, Int.ceilLogBase2(), "polly.fdiv_q.shr");
+ break;
+ }
// TODO: Review code and check that this calculation does not yield
// incorrect overflow in some bordercases.
//