Translate power-of-two floor-division into ashr
authorTobias Grosser <tobias@grosser.es>
Wed, 3 Jun 2015 06:31:30 +0000 (06:31 +0000)
committerTobias Grosser <tobias@grosser.es>
Wed, 3 Jun 2015 06:31:30 +0000 (06:31 +0000)
commitcb73f150d4dee783784b5c3bb9deac4d3357624a
tree8d4b46ce7e30c33debf031afeb6cd4ee4a01330a
parentdc9293d051e290ed3f3438a082cbf0d10c773245
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
polly/lib/CodeGen/IslExprBuilder.cpp
polly/test/Isl/CodeGen/exprModDiv.ll
polly/test/Isl/CodeGen/exprModDiv___%for.cond---%for.end.jscop
polly/test/Isl/CodeGen/exprModDiv___%for.cond---%for.end.jscop.pow2 [new file with mode: 0644]