[polly] r238905 - Translate power-of-two floor-division into ashr
David Majnemer
david.majnemer at gmail.com
Wed Jun 3 10:35:45 PDT 2015
On Wed, Jun 3, 2015 at 7:56 AM, Tobias Grosser <tobias at grosser.es> wrote:
> 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.
>
Here is an example using a negative numerator and a positive denominator:
%r = sdiv i32 2550202368, 1073741824 => -1
Here is what shifting produces:
%r = ashr i32 2550202368, 30 => -2
>
> I know exclude negative values 'b' from this optimization and also fixed
> the dyn_cast issue in 238927.
>
Thanks!
>
> Best,
> Tobias
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150603/769ee071/attachment.html>
More information about the llvm-commits
mailing list