https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109057
Bug ID: 109057
Summary: Does GCC interpret assembly when deciding to optimize
away a variable?
Product: gcc
Version: unknown
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: hbucher at gmail dot com
Target Milestone: ---
I'm trying to figure out why GCC optimizes away a uint8_value that is passed
into assembly, basically discarding it. This is in context of Google
benchmarks.
#include <stdint.h>
inline void DoNotOptimize( uint8_t value) {
asm volatile("" : : "r,m"(value) : "memory");
}
static const uint8_t LUT[8] = {1,5,3,0,2,7,1,2};
void func1(uint8_t val) {
DoNotOptimize(LUT[val]);
}
In this case Gcc generates
func1(unsigned char):
movzbl %dil, %edi
ret
More importantly, the entire static array LUT was optimized away from the
object file.
https://godbolt.org/z/Tab5T84dM
Is this the correct behavior in your understanding?