[llvm-dev] Are derived pointers caught by RS4GC?

31 views
Skip to first unread message

Kavindu Gimhan Zoysa via llvm-dev

unread,
Jul 20, 2021, 10:46:24 AM7/20/21
to llvm...@lists.llvm.org
Hi all,

If I run the --rewrite-statepoints-for-gc, against an LLVM IR with a derived pointer, that pointer is not caught by RS4GC pass as a live pointer. Is this the expected behavior?

This is the sample code I ran.

define void @dummy_func() {
  ret void
}
define i8 addrspace(1)* @test1(i8 addrspace(1)* %obj) gc "statepoint-example" {
  %gep = getelementptr i8, i8 addrspace(1)* %obj, i64 20000
  call void @dummy_func()
  %p = getelementptr i8, i8 addrspace(1)* %gep, i64 -20000
  store i8 2, i8 addrspace(1)* %gep
  ret i8 addrspace(1)* %p
}
define dso_local void @main() #0 {
  %1 = alloca i8*, align 8
  %2 = call noalias i8 addrspace(1)* @malloc(i64 8) #3
  %3 = call i8 addrspace(1)* @test1(i8 addrspace(1)* %2)
  ret void
}
declare dso_local noalias i8 addrspace(1)* @malloc(i64) #1

Since %gep is a derived pointer, I expect it should be identified as a live pointer for RS4GC as explained in https://releases.llvm.org/11.0.1/docs/Statepoints.html#base-derived-pointers .

Really appreciate your input about this.

Thank you,
Kavindu

Kavindu Gimhan Zoysa,
BSc(Hons) | ENTC | UoM,
ATL | WSO2

Philip Reames via llvm-dev

unread,
Jul 20, 2021, 1:23:38 PM7/20/21
to Kavindu Gimhan Zoysa, llvm...@lists.llvm.org

$ ./opt -S llvm-dev.ll -rewrite-statepoints-for-gc
; ModuleID = 'llvm-dev.ll'
source_filename = "llvm-dev.ll"



define void @dummy_func() {
  ret void
}

define i8 addrspace(1)* @test1(i8 addrspace(1)* %obj) gc "statepoint-example" {
  %gep = getelementptr i8, i8 addrspace(1)* %obj, i64 20000

  %statepoint_token = call token (i64, i32, void ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_isVoidf(i64 2882400000, i32 0, void ()* @dummy_func, i32 0, i32 0, i32 0, i32 0) [ "gc-live"(i8 addrspace(1)* %obj) ]
  %obj.relocated = call coldcc i8 addrspace(1)* @llvm.experimental.gc.relocate.p1i8(token %statepoint_token, i32 0, i32 0) ; (%obj, %obj)
  %gep.remat = getelementptr i8, i8 addrspace(1)* %obj.relocated, i64 20000
  %p = getelementptr i8, i8 addrspace(1)* %gep.remat, i64 -20000
  store i8 2, i8 addrspace(1)* %gep.remat, align 1
  ret i8 addrspace(1)* %p
}

Works for me.  This output is entirely correct as we relocated the base pointer and then rematerialized the derived pointer afterwards.  This is almost always profitable over directly relocating both obj and derived pointers.

Philip

Kavindu Gimhan Zoysa via llvm-dev

unread,
Jul 20, 2021, 2:23:18 PM7/20/21
to Philip Reames, llvm...@lists.llvm.org
Hi Philip,

It is the same output I got that make sense. But as explained in this example https://llvm.org/docs/Statepoints.html#base-derived-pointers (the example available in this section), I thought %gep should be included in gc-live operand bundle. Isn't that correct? 

Kavindu Gimhan Zoysa,
BSc(Hons) | ENTC | UoM,
ATL | WSO2


Philip Reames via llvm-dev

unread,
Jul 20, 2021, 2:32:49 PM7/20/21
to Kavindu Gimhan Zoysa, llvm...@lists.llvm.org

Please see my previous email re: rematerialization.  This code appears correct and as expected.

Philip

Reply all
Reply to author
Forward
0 new messages