[polly] r238905 - Translate power-of-two floor-division into ashr
Tobias Grosser
tobias at grosser.es
Wed Jun 3 07:56:42 PDT 2015
On 06/03/2015 09:58 AM, David Majnemer wrote:
>
>
> On Tue, Jun 2, 2015 at 11:31 PM, Tobias Grosser <tobias at grosser.es
> <mailto:tobias at grosser.es>> wrote:
>
> Author: grosser
> Date: Wed Jun 3 01:31:30 2015
> New Revision: 238905
>
> URL: http://llvm.org/viewvc/llvm-project?rev=238905&view=rev
> Log:
> 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:
>
>
> This only holds if the numerator is non-negative. -1/INT_MIN should
> give 0 but calculating it with a right-shift would give -1.
Your example -1/INT_MIN is uses negative operands in both the numerator
and the denominator. This it indeed failed with my code. However, the
case of negative numerators with positive denominators should be fine,
as we are translating here a division with rounding towards -inf, not
rounding towards zero as the sdiv instruction in LLVM uses. Or did I
miss something here.
I know exclude negative values 'b' from this optimization and also fixed
the dyn_cast issue in 238927.
Best,
Tobias
More information about the llvm-commits
mailing list