Placeholder MaryBennett accepted merge request !109: Modify xcvmem test cases to run for Os, Oz and Og at OpenHW Group / backup-20260412 / corev-gcc

Placeholder MaryBennett
2024-07-19T08:26:15Z

Partial fix issue #108 and tidy up.

Before my work, cv-mem-l[b|bu|h|hu|w|sb|sh|sw]-compile-2.c don't support Og, cv-mem-sb-compile-2.c doesn't support Os and Oz.

Noticed that for this fragment:

int char_sum = 1;

for (int i = 0; i < 200; i += j)
{
char_sum += *array_char;
array_char += j * sizeof (array_char);
}

When compiling with O1, the compiler will hoist the increment at the loop invariant code motion pass (148t.lim2), array_char += j * sizeof (array_char); will be moved to loop's outside. Then, the memory access operation and increment operation will be merged at the auto_inc_dec pass (296r.auto_inc_dec). But when compiling with Og, the compiler doesn't run the loop invariant code motion pass. Thus we need to do this task for compiler in order to merge the memory access operation and increment operation.

When in Og, the compiler will split the for loop into two basic blocks, potentially causing the auto-increment/decrement pass to fail in merging the operations. To avoid this, I replaced the for loop with a do-while loop, which the compiler generates as a single basic block.

Moreover, when compiling with Og, the compiler will put a line into the loop:

slli a5, a5, 1

to convert the type implicitly, which will make the auto_inc_dec pass fail to merge the memory access operation and increment operation. I use a trick to avoid it:

array_int = (signed int *)((int)array_int + step);

For risc-v 32-bit CPU, the size of int and pointer are equal, so we can add them with explicit type conversion.

Result of regression test:

before:

=== gcc Summary ===

# of expected passes 28220
# of unexpected failures 224
# of expected failures 58
# of unresolved testcases 190
# of unsupported tests 3937
/root/regression-test/.build/gcc/xgcc version 14.1.0 (GCC)

after:

=== gcc Summary ===

# of expected passes 28240
# of unexpected failures 224
# of expected failures 58
# of unresolved testcases 190
# of unsupported tests 3927
/root/corev-gcc/.build/gcc/xgcc version 14.1.0 (GCC)

Files changed:

cv-mem-lb-compile-2.c

cv-mem-lbu-compile-2.c

cv-mem-lh-compile-2.c

cv-mem-lhu-compile-2.c

cv-mem-lw-compile-2.c

cv-mem-sb-compile-2.c

cv-mem-sh-compile-2.c

cv-mem-sw-compile-2.c

Thanks for taking the time to contribute to GCC! Please be advised that if you are viewing this on github.com, that the mirror there is unofficial and unmonitored. The GCC community does not use github.com for their contributions. Instead, we use a mailing list (gcc-patches@gcc.gnu.org) for code submissions, code reviews, and bug reports. Please send patches there instead.