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

Xiangyang Guo via llvm-dev llvm-dev at lists.llvm.org
Tue Dec 1 09:30:35 PST 2015


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.

; Function Attrs: uwtable
define i32 @_Z5func1i(i32 %a) #0 {
  br label %1

; <label>:1                                       ; preds = %3, %0
  %ret.0 = phi i32 [ 0, %0 ], [ %4, %3 ]
  %i.0 = phi i32 [ 0, %0 ], [ %5, %3 ]
  %2 = icmp slt i32 %i.0, 10
  br i1 %2, label %3, label %6

; <label>:3                                       ; preds = %1
  %4 = call i32 @llvm.foo(i32 %a, i32 3)
  %5 = add nsw i32 %i.0, 1
  br label %1

; <label>:6                                       ; preds = %1
  ret i32 %ret.0
}

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

Regards,

Xiangyang
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20151201/c2e471a9/attachment.html>


More information about the llvm-dev mailing list