Skip to content

SPEED: Redundant GET_FIELD_PTR and PUSH_LOCAL_PTR generated for pointers to structs #530

@ske2004

Description

@ske2004
type T = struct {
    x: int
}

type TT = struct {
    x: T
}

type TTT = struct {
    x: TT
}

fn test() {
    var a: ^TTT = &TTT{{{420}}}
    printf("%v\n", a.x.x.x)
}
Function: test

000000001     16                  ENTER_FRAME 000002F04B218358
000000002     14          PUSH_LOCAL_PTR_ZERO -24 8
000000003     14          PUSH_LOCAL_PTR_ZERO -32 8
000000004     14          PUSH_LOCAL_PTR_ZERO -40 8
000000005     14          PUSH_LOCAL_PTR_ZERO -48 8
000000006     14                         PUSH int 420
000000007     14                       ASSIGN int 8
000000008     14               PUSH_LOCAL_PTR -48
000000009     14                       ASSIGN struct 8
000000010     14               PUSH_LOCAL_PTR -40
000000011     14                       ASSIGN struct 8
000000012     14               PUSH_LOCAL_PTR -32
000000013     14                         PUSH int 8
000000014     14                 CALL_BUILTIN TTT new
000000015     14                          DUP
000000016     14               PUSH_LOCAL_PTR -56
000000017     14                 SWAP; ASSIGN ^ 8
000000018     14                          DUP
000000019     14                      POP_REG HEAP_COPY
000000020     14                 SWAP; ASSIGN struct 8
000000021     14                     PUSH_REG HEAP_COPY
000000022     14        CHANGE_REF_CNT_ASSIGN ^TTT
000000023     15                         PUSH int 0
000000024     15                         PUSH ^ 0000000000000000
000000025     15                         PUSH ^ 000002F04B1E7E58
000000026     15                   PUSH_LOCAL ^ -24
000000027     15                GET_FIELD_PTR 0
000000028     15                GET_FIELD_PTR 0
000000029     15                GET_FIELD_PTR int 0; DEREF
000000030     15                 CALL_BUILTIN int printf
000000031     15                         PUSH int 0
000000032     15                 CALL_BUILTIN void printf
000000033     15                          POP 3
000000034     16         CHANGE_REF_CNT_LOCAL -- ^TTT -56
000000035     16         CHANGE_REF_CNT_LOCAL -- ^TTT -24
000000036     16                  LEAVE_FRAME
000000037     16                       RETURN 2

000000038     16        CHANGE_REF_CNT_GLOBAL -- [1]str 000002F04B1E3F48
000000039     16                         HALT

All of these are contained by value, there's no reason to call GET_FIELD_PTR nor PUSH_LOCAL_PTR/ZERO multiple times

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions