[PATCH] D118549: apply two more cases for store combine
Baoshan Pang via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Feb 18 21:19:23 PST 2022
BaoshanPang added a comment.
In D118549#3304383 <https://reviews.llvm.org/D118549#3304383>, @spatel wrote:
> Adding more potential reviewers. It might help if the baseline tests are committed, so we can see the asm difference for each test. Is it the alignment or something else that prevents combining these stores currently?
The .ll test case is derived from this C file:
struct ab {
char a;
char b;
char c;
char d;
} __attribute__ ((aligned (2)));
void store0(struct ab *_ab, unsigned v)
{
_ab->a = v&0xff;
_ab->b = (v>>8)&0xff;
_ab->c = (v>>16)&0xff;
_ab->d = (v>>24)&0xff;
}
void store1(struct ab *_ab, unsigned v)
{
_ab->a = v&0xff;
_ab->b = (v>>8)&0xff;
}
void store2(struct ab *_ab, unsigned v)
{
_ab->c = (v>>16)&0xff;
_ab->d = (v>>24)&0xff;
}
void store3(struct ab *_ab, unsigned v)
{
_ab->c = (v)&0xff;
_ab->d = (v>>8)&0xff;
}
Before my change, the generated asm code is like this:
.text
.attribute 4, 16
.attribute 5, "rv32i2p0_m2p0_a2p0_c2p0"
.file "t.c"
.globl store0
.p2align 1
.type store0, at function
store0:
sb a1, 0(a0)
srli a2, a1, 8
sb a2, 1(a0)
srli a2, a1, 16
sb a2, 2(a0)
srli a1, a1, 24
sb a1, 3(a0)
ret
.Lfunc_end0:
.size store0, .Lfunc_end0-store0
.globl store1
.p2align 1
.type store1, at function
store1:
sh a1, 0(a0)
ret
.Lfunc_end1:
.size store1, .Lfunc_end1-store1
.globl store2
.p2align 1
.type store2, at function
store2:
srli a2, a1, 16
sb a2, 2(a0)
srli a1, a1, 24
sb a1, 3(a0)
ret
.Lfunc_end2:
.size store2, .Lfunc_end2-store2
.globl store3
.p2align 1
.type store3, at function
store3:
sh a1, 2(a0)
ret
.Lfunc_end3:
.size store3, .Lfunc_end3-store3
.ident "clang version 15.0.0 (git at 172.30.80.200:/opt/repos/fortirisc_llvm.git efb383266d04c70b8adf4ffb3f4872b36bc4653f)"
.section ".note.GNU-stack","", at progbits
.addrsig
With my change the genereated asm code is like this:
.text
.attribute 4, 16
.attribute 5, "rv32i2p0_m2p0_a2p0_c2p0"
.file "t.c"
.globl store0
.p2align 1
.type store0, at function
store0:
srli a2, a1, 16
sh a1, 0(a0)
sh a2, 16(a0)
ret
.Lfunc_end0:
.size store0, .Lfunc_end0-store0
.globl store1
.p2align 1
.type store1, at function
store1:
sh a1, 0(a0)
ret
.Lfunc_end1:
.size store1, .Lfunc_end1-store1
.globl store2
.p2align 1
.type store2, at function
store2:
srli a1, a1, 16
sh a1, 2(a0)
ret
.Lfunc_end2:
.size store2, .Lfunc_end2-store2
.globl store3
.p2align 1
.type store3, at function
store3:
sh a1, 2(a0)
ret
.Lfunc_end3:
.size store3, .Lfunc_end3-store3
.ident "clang version 15.0.0 (https://github.com/llvm/llvm-project.git 59bb18ddfec5e5d91079b163a535cb3a6879093e)"
.section ".note.GNU-stack","", at progbits
.addrsig
The difference are at function store0 and store2. For store0, it was failed to use instruction 'sw' as the alignment is 2, my change detect such case and use 2 'sh' for it; for store2, it was failed to use 'sh' because the extra shift(16), my change make it working for this case too.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D118549/new/
https://reviews.llvm.org/D118549
More information about the llvm-commits
mailing list