When debugging compiler-rt tests failing only with optimizations enabled, I finally stumbled upon debugging machine code generated near uint64_t right shifted by (constant) 8 bits. The machine code was quite strange and hard to debug.
Then, I compiled some trivial example for uint32_t right-shifted by 1 bit and results were quite strange, too. Maybe I have mis-understood MSP430 instruction semantics, but I have not managed to find a number for which my 8-byte function diverges from "reference" 32-byte one (-O1).
// test_lshr32.c
#include <stdio.h>
uint32_t __attribute__((noinline)) test_c(uint32_t x)
{
return x >> 1;
}
uint32_t test_asm(uint32_t x);
int main()
{
const uint32_t x = TEST_X;
printf("%lx\n", TEST_FUN(x));
return 0;
}
When debugging compiler-rt tests failing only with optimizations enabled, I finally stumbled upon debugging machine code generated near
uint64_t
right shifted by (constant) 8 bits. The machine code was quite strange and hard to debug.Then, I compiled some trivial example for
uint32_t
right-shifted by 1 bit and results were quite strange, too. Maybe I have mis-understood MSP430 instruction semantics, but I have not managed to find a number for which my 8-byte function diverges from "reference" 32-byte one (-O1
).What is generated with
-O1
(only two functions are shown):Looks like it is because 32-bit arithmetic is somehow autoexpanded for 16-bit registers in a way not very handly for MSP430 backend.