indexing - LLVM GEP and store vs load and insertvalue: Storing value to a pointer to an aggregate -


what difference between getelementptr , store vs. load , insertvalue when storing value pointer aggregate type? 1 preferred in circumstances? , if why? or headed entirely in wrong direction?

example:

; contrived example %x = type {i32, i64}  define i32 @main(i32 %argc, i8** %argv) { entry:   %sx.0 = alloca %x    ; change first value gep + store   %val1 = getelementptr %x, %x* %sx.0, i32 0, i32 0   store i32 42, i32* %val1    ; change second value load + insertvalue   %sx.1 = load %x, %x* %sx.0   %sx.2 = insertvalue %x %sx.1, i64 42, 1   store %x %sx.2, %x* %sx.0 ; suppose considered less ideal                             ; in cases nice have                             ; struct `load`ed   ret i32 0 } 

interestingly using llc -o=0 ... both compile the same instructions. amounts following, had hoped.

movl $42, -16(%rsp) # gep + store movq $42, -8(%rsp)  # load + insertvalue 

background:

i reading llvm language reference , reading insertvalue. reference notes extractvalue instructions similarity gep , following differences.

the major differences getelementptr indexing are:

  • since value being indexed not pointer, first index omitted , assumed zero.

  • at least 1 index must specified.

  • not struct indices array indices must in bounds.

the following question on stackoverflow mentions use of getelementptr , insertvalue, different reasons. llvm insertvalue bad optimized?

semantically, loading , later storeing entire object more wasteful. if it's huge struct? if it's array of structs? gep allows access exact location in memory want load/store, without need load/store else.

while 2 forms lowered same instructions in example, isn't guaranteed.


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -