Register s1 written while cs1 is live
Closed this issue · 0 comments
mn416 commented
Hi,
If I compile the attached program App.cpp
(23 lines) using
riscv64-unknown-freebsd-clang++ -O2 -mabi=il32pc64 -march=rv32imaxcheri -nostdlib -ffreestanding -g -c App.cpp
and view the resulting object file with
riscv64-unknown-freebsd-objdump -S App.o
I see the following strange code sequence
70: 93 04 10 00 addi s1, zero, 1
74: 23 a4 94 04 csw s1, 72(cs1)
Register cs1
is killed (assuming merged reg file) and then used immediately in the next instruction.
I think the source program is ok (pasted below). Both the array alignment requirement and the dynamic array size seem important in producing the bad code.
Compiler version (built today using fresh checkout of cheribuild
):
clang version 13.0.0 (https://github.com/CTSRD-CHERI/llvm-project.git ea3e23aa96b1e39e8473d4e93b773243ba910e58)
Target: riscv64-unknown-freebsd
Thread model: posix
Here is the program App.cpp
:
struct Foo {
int x, y, z;
int *buffer;
Foo() { x = y = z = 1; }
};
extern bool isSim();
extern void fun(Foo*);
int main()
{
int N = isSim() ? 3000 : 1000000;
__attribute__ ((aligned (128))) int result[N];
Foo foo;
foo.buffer = result;
fun(&foo);
bool ok = true;
for (int i = 0; i < N; i++) ok = ok && result[i] == 3*i;
return ok;
}