[polly] r238929 - Lower signed-divisions without rounding to ashr instructions
Johannes Doerfert
doerfert at cs.uni-saarland.de
Wed Jun 3 14:12:02 PDT 2015
On 06/03, David Majnemer wrote:
> On Wed, Jun 3, 2015 at 9:13 AM, Johannes Doerfert <
> doerfert at cs.uni-saarland.de> wrote:
>
> > Isnt't there a LLVM pass that will do this kind of optimization
> > (Instcombine)?
> >
>
> InstCombine optimizes signed divides to unsigned divides when doing so is
> obvious (both operands have a clear sign bit). Unsigned divides are then
> turned in shift right operations.
>
> q = n / (2**k) is equivalent to (n >= 0 ? n : -n) >> k.
>
> Modeling this in InstCombine would make it harder to analyze so we leave it
> to CodeGen to emit.
Good to know, thanks!
>
>
>
> >
> > On 06/03, Tobias Grosser wrote:
> > > Author: grosser
> > > Date: Wed Jun 3 10:14:58 2015
> > > New Revision: 238929
> > >
> > > URL: http://llvm.org/viewvc/llvm-project?rev=238929&view=rev
> > > Log:
> > > Lower signed-divisions without rounding to ashr instructions
> > >
> > > Modified:
> > > polly/trunk/lib/CodeGen/IslExprBuilder.cpp
> > > polly/trunk/test/Isl/CodeGen/exprModDiv.ll
> > >
> > > Modified: polly/trunk/lib/CodeGen/IslExprBuilder.cpp
> > > URL:
> > http://llvm.org/viewvc/llvm-project/polly/trunk/lib/CodeGen/IslExprBuilder.cpp?rev=238929&r1=238928&r2=238929&view=diff
> > >
> > ==============================================================================
> > > --- polly/trunk/lib/CodeGen/IslExprBuilder.cpp (original)
> > > +++ polly/trunk/lib/CodeGen/IslExprBuilder.cpp Wed Jun 3 10:14:58 2015
> > > @@ -295,6 +295,13 @@ Value *IslExprBuilder::createOpBin(__isl
> > > Res = Builder.CreateNSWMul(LHS, RHS);
> > > break;
> > > case isl_ast_op_div:
> > > + if (auto *Const = dyn_cast<ConstantInt>(RHS)) {
> > > + auto &Val = Const->getValue();
> > > + if (Val.isPowerOf2() && Val.isNonNegative()) {
> > > + Res = Builder.CreateAShr(LHS, Val.ceilLogBase2(),
> > "pexp.div.shr");
> > > + break;
> > > + }
> > > + }
> > > Res = Builder.CreateSDiv(LHS, RHS, "pexp.div");
> > > break;
> > > case isl_ast_op_pdiv_q: // Dividend is non-negative
> > >
> > > Modified: polly/trunk/test/Isl/CodeGen/exprModDiv.ll
> > > URL:
> > http://llvm.org/viewvc/llvm-project/polly/trunk/test/Isl/CodeGen/exprModDiv.ll?rev=238929&r1=238928&r2=238929&view=diff
> > >
> > ==============================================================================
> > > --- polly/trunk/test/Isl/CodeGen/exprModDiv.ll (original)
> > > +++ polly/trunk/test/Isl/CodeGen/exprModDiv.ll Wed Jun 3 10:14:58 2015
> > > @@ -46,10 +46,8 @@
> > > ; POW2: %polly.access.A6 = getelementptr float, float* %A, i64
> > %pexp.pdiv_r
> > >
> > > ; A[i / 128]
> > > -; POW2: %pexp.div = sdiv i64 %polly.indvar, 128
> > > +; POW2: %pexp.div.shr = ashr i64 %polly.indvar, 7
> > > ; POW2: %polly.access.B8 = getelementptr float, float* %B, i64
> > %pexp.div
> > > -;
> > > -; FIXME: Make isl mark this as an udiv expression.
> > >
> > > ; #define floord(n,d) ((n < 0) ? (n - d + 1) : n) / d
> > > ; A[p + 128 * floord(-p - 1, 128) + 128]
> > > @@ -62,8 +60,8 @@
> > > ; POW2: %polly.access.A10 = getelementptr float, float* %A, i64 %24
> > >
> > > ; A[p / 128]
> > > -; POW2: %pexp.div12 = sdiv i64 %p, 128
> > > -; POW2: %polly.access.B13 = getelementptr float, float* %B, i64
> > %pexp.div12
> > > +; POW2: %pexp.div.shr12 = ashr i64 %p, 7
> > > +; POW2: %polly.access.B13 = getelementptr float, float* %B, i64
> > %pexp.div.shr12
> > >
> > > target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
> > >
> > >
> > >
> > > _______________________________________________
> > > llvm-commits mailing list
> > > llvm-commits at cs.uiuc.edu
> > > http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
> >
> > --
> >
> > Johannes Doerfert
> > Researcher / PhD Student
> >
> > Compiler Design Lab (Prof. Hack)
> > Saarland University, Computer Science
> > Building E1.3, Room 4.31
> >
> > Tel. +49 (0)681 302-57521 : doerfert at cs.uni-saarland.de
> > Fax. +49 (0)681 302-3065 : http://www.cdl.uni-saarland.de/people/doerfert
> >
> > _______________________________________________
> > llvm-commits mailing list
> > llvm-commits at cs.uiuc.edu
> > http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
> >
> >
--
Johannes Doerfert
Researcher / PhD Student
Compiler Design Lab (Prof. Hack)
Saarland University, Computer Science
Building E1.3, Room 4.31
Tel. +49 (0)681 302-57521 : doerfert at cs.uni-saarland.de
Fax. +49 (0)681 302-3065 : http://www.cdl.uni-saarland.de/people/doerfert
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 213 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150603/08f05a26/attachment.sig>
More information about the llvm-commits
mailing list