https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109057

--- Comment #10 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
(In reply to Henry from comment #9)
> Just to make it clear, I'm not saying this is a bug on GCC. 
> 
> Im just trying to understand what is happening since this is affecting some
> of our benchmarks. Then we can counter with some wit. 
> 
> Perhaps there is an alternate venue for this type of clarification? I tried
> Reddit but no dice. The GCC IRC channel perhaps?

If you use
inline void DoNotOptimize( unsigned int value) {
  asm volatile("" : : "r,m"(value) : "memory");
}
static const unsigned char LUT[8] = {1,5,3,0,2,7,1,2};
void func1(unsigned int val) {
    DoNotOptimize(LUT[val]); 
}
then obviously it can't choose the "m" variant for value, because value is
32-bit,
while LUT(%rdi) is 8-bit.  So it can choose only "r" variant and therefore it
needs
to emit an instruction that computes that (zero extends the value).
If you change LUT array to be const unsigned int LUT[8], then "m" variant can
be selected (and is in my testing).

Reply via email to