[llvm-dev] Instcombine and llvm.ptr.annotation

De Azevedo Piovezan, Felipe via llvm-dev llvm-dev at lists.llvm.org
Wed Nov 7 10:13:01 PST 2018


Hi,

I'm trying to figure out if this behavior by Instcombine is ok, and I'd appreciate some feedback.

Suppose you have this kind of struct:

    %struct.State = type {  i32, i32,  i32, i32, %"struct.State::InnerState" }
    %"struct.State::InnerState" = type { i32, i32 }

Now suppose we have %S which is of type struct.State and we want to use two llvm.ptr.annotations:
1- one to annotate the last member of struct.State (which is of type struct.State::InnerState)
2- one to annotate the first member of %"struct.State::InnerState"

This is the IR out of clang:

define i32 @foo(%struct.State* %S)  {
  %my_inner_state = getelementptr inbounds %struct.State, %struct.State* %S, i32 0, i32 4
  %0 = bitcast %"struct.State::InnerState"* %my_inner_state to i8*
  %1 = call i8* @llvm.ptr.annotation.p0i8(i8* %0, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i32 0, i32 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i32 0, i32 0), i32 20)
  %2 = bitcast i8* %1 to %"struct.State::InnerState"*
  %inner_member = getelementptr inbounds %"struct.State::InnerState", %"struct.State::InnerState"* %2, i32 0, i32 0
  %3 = bitcast i32* %inner_member to i8*
  %4 = call i8* @llvm.ptr.annotation.p0i8(i8* %3, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i32 0, i32 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i32 0, i32 0), i32 15)
}

Instcombine is replacing the GEP with all 0 indices + bitcast with the base pointer of the GEP:

  %my_inner_state = getelementptr inbounds %struct.State, %struct.State* %S, i64 0, i32 4
  %0 = bitcast %"struct.State::InnerState"* %my_inner_state to i8*
  %1 = call i8* @llvm.ptr.annotation.p0i8(i8* %0, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i32 20)
  %2 = call i8* @llvm.ptr.annotation.p0i8(i8* %1, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i32 15)

Now we cannot distinguish between what is actually being annotated. In other words, it looks like the whole %"struct.State::InnerState" is being annotated twice.
Is this ok?

Thanks!

--
Felipe de Azevedo Piovezan

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


More information about the llvm-dev mailing list