[llvm-commits] [llvm] r68768 - /llvm/trunk/include/llvm/Support/IRBuilder.h

Chris Lattner clattner at apple.com
Thu Apr 9 23:33:37 PDT 2009


On Apr 9, 2009, at 11:08 PM, Jeffrey Yasskin wrote:

> On Thu, Apr 9, 2009 at 10:35 PM, Chris Lattner <clattner at apple.com>  
> wrote:
>> On Apr 9, 2009, at 10:30 PM, Nick Lewycky wrote:
>>>
>>> URL: http://llvm.org/viewvc/llvm-project?rev=68768&view=rev
>>> Log:
>>> Add utility function to IRBuilder that takes the difference  
>>> between two
>>> pointers, taking into account the size of the pointed-to object.
>>> Patch by Jeffrey Yasskin!
>>
>> looks good to me.  Incidentally, clang and llvm-gcc specialize the  
>> case when
>> the element size is a power of two into a signed right shift.  This  
>> is legal
>> because C only allows pointer subtraction between elements in the  
>> same
>> array, which means the division must be "exact".  In this case, SRA  
>> x, c is
>> the same as sdiv x, 2^c.  I don't know if you care about this case  
>> though.
>
> It would be nice to optimize that, or provide enough information to
> let a downstream pass optimize it, but I don't know a reliable way to
> do it in the IRBuilder, which doesn't have target data. Is there a
> way?


Ok, I didn't realize that IRBuilder didn't have TargetData directly.   
This is probably implementable in TargetFolder, which can be used as a  
template parameter to IRBuilder.

The ideal way to handle this is to just mark the sdiv as being exact,  
and letting instcombine do it later.  We don't have direct support for  
that in LLVM IR yet though.  This is the subject of:
http://llvm.org/bugs/show_bug.cgi?id=2247

The right way to handle this is to parameterize sdiv/udiv on a general  
integer rounding mode, one of which is "this divide is known to be  
exact".

-Chris



More information about the llvm-commits mailing list