[llvm-dev] LICM doesn't work for IntrReadMem intrinsic function

Xiangyang Guo via llvm-dev llvm-dev at lists.llvm.org
Tue Dec 1 12:33:06 PST 2015


Hi,

if I have the following IR, LICM doesn't work again, even if I use
'-loop-rotate' firstly. In this IR, the return value of intrinsic function
"foo" is used by another function "func2" as parameter.  However, for the
intrinsic function "foo", the parameters are still loop invariant. Do you
know why this happens? Thanks a lot.

Regards,

Xiangyang

; Function Attrs: uwtable
define void @_Z5func1ii(i32 %a, i32 %b) #0 {
  br label %1

; <label>:1                                       ; preds = %0, %1
  %i.01 = phi i32 [ 0, %0 ], [ %6, %1 ]
  %2 = call i32 @llvm.foo(i32 %a, i32 1)
  %3 = call i32 @_Z5func2ii(i32 %b, i32 %2)
  %4 = call i32 @llvm.foo(i32 %a, i32 2)
  %5 = call i32 @_Z5func2ii(i32 %3, i32 %4)
  %6 = add nsw i32 %i.01, 1
  %7 = icmp slt i32 %6, 10
  br i1 %7, label %1, label %8

; <label>:8                                       ; preds = %1
  ret void
}

; Function Attrs: nounwind readonly
declare i32 @llvm.foo(i32, i32) #1

declare i32 @_Z5func2ii(i32, i32) #2

2015-12-01 13:16 GMT-05:00 Xiangyang Guo <eceguo at gmail.com>:

> Thanks for your reply, escha,
>
> Yes, -loop-rorate makes it work.
>
> Regards,
>
> Xiangyang
>
> 2015-12-01 12:48 GMT-05:00 <escha at apple.com>:
>
>>
>> > On Dec 1, 2015, at 9:30 AM, Xiangyang Guo via llvm-dev <
>> llvm-dev at lists.llvm.org> wrote:
>> >
>> > Hi, All,
>> >
>> > Suppose I define one memory read only intrinsic function "foo" in
>> Intrinsics.td like this
>> >
>> > def int_foo : Intrinsic<[llvm_i32_ty], [llvm_i32_ty, llvm_i32_ty],
>> [IntrReadMem]>;
>> >
>> > Suppose I have the following IR, which means the intrinsic function
>> "foo" is called 10 times in a loop. Since the parameters of function "foo"
>> are invariant and the function "foo" is defined as "IntrReadMem". I assume
>> the '-licm' can move the function call 'foo' out of the loop body. However,
>> after I use "opt test.ll -basicaa -licm -S", the function call 'foo' is
>> still inside the loop body. Do I misunderstand something here? Any
>> suggestions are appreciated. Thanks a lot.
>>
>> Does it work if you call -loop-rotate first? Loop unrolling requires
>> loops to be in canonicalized rotated form first, so I wouldn’t be surprised
>> if LICM does as well.
>>
>> —escha
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20151201/0908be32/attachment.html>


More information about the llvm-dev mailing list