Improve union field access in IR. #4354
Labels
compiler: codegen
Everything to do with IR->ASM, register allocation, etc.
compiler: ir
IRgen and sway-ir including optimization passes
enhancement
New feature or request
Prior to #4336 the IR would index different union fields or variants via the
extract_value
instruction. This was a bit of a convenient hack as it worked fairly well and didn't require a special extra instruction to do it instead.This behaviour has translated over to now by done by
get_elem_ptr
. It's still a hack but no longer necessary. A more proper approach would be to use acast_ptr
instruction, which is what LLVM does.Care would have to be taken though in ASMgen since we lay out memory in a big-endian format, simply changing the type but not the actual address may not point to the proper field value bytes. (This is an advantage of using little-endian memory!)
The text was updated successfully, but these errors were encountered: