Skip to content

[RISCV] missed optimization: use sh or sw when can infer the offset from alignment #143215

Open
@BaoshanPang

Description

@BaoshanPang

https://godbolt.org/z/j78cddY1W

For the C code:

typedef struct {
    char a;
    char b;
    char c;
    int len;
    char e;
    int len2;
} __attribute__((packed)) str_t;

void foo(str_t *p __attribute__((align_value(4)))) {
    p->len = 0;
    p->len2 = 0;
}

The asm generated is:

foo:
        sb      zero, 3(a0)
        sb      zero, 4(a0)
        sb      zero, 5(a0)
        sb      zero, 6(a0)
        sw      zero, 8(a0)
        ret

For 'len', the middle two 'sb' can be converted to one 'sh'.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions