I am working on GCC for a target architecture where clz(0) is defined and
is 32 (TriCore).
The code under test is the following:

#include <stdio.h>
int f(unsigned int a) {
    unsigned int res = 32 - __builtin_clz(a);
    if(res > 0) printf("test");
    return res;
}

>From GCC version greater and equal to 11, the Tree SSA optimization
discards the if condition completely, and always executes the printf. This
is the optimized gimplified code at the end of the optimization for GCC12:

int f (unsigned int a)
{
  int _1;
  int _2;

  <bb 2> [local count: 1073741824]:
  _1 = __builtin_clz (a_4(D));
  _2 = 32 - _1;
  __printf_chk (1, "test");
  return _2;
}

where GCC10 produces:
f (unsigned int a)
{
  int _1;
  int _2;

  <bb 2> [local count: 1073741824]:
  _1 = __builtin_clz (a_4(D));
  _2 = 32 - _1;
  if (_2 != 0)
    goto <bb 3>; [33.00%]
  else
    goto <bb 4>; [67.00%]

  <bb 3> [local count: 354334800]:
  __printf_chk (1, "test");

  <bb 4> [local count: 1073741824]:
  return _2;
}

I tried to rebuild defining  CLZ_DEFINED_VALUE_AT_ZERO(MODE, VALUE)
((VALUE) = 32, 2) but this doesn't seem to have any effect.

I am stuck and need counseling. Can anyone suggest me the next steps? Thank
you.
Kind regards
Enrico Bragante

Reply via email to