Issue |
143215
|
Summary |
[RISCV] missed optimization: use sh or sw when can infer the offset from alignment
|
Labels |
new issue
|
Assignees |
|
Reporter |
BaoshanPang
|
https://godbolt.org/z/YP9WP9rET
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__((aligned(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)
sb zero, 8(a0)
sb zero, 9(a0)
sb zero, 10(a0)
sb zero, 11(a0)
ret
```
For 'len', the middle two 'sb' can be converted to one 'sh'; for 'len2', the four sb can be converted to one 'sw'.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs