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

            Bug ID: 112949
           Summary: evrp produces incorrect range for __builtin_clz
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: kristerw at gcc dot gnu.org
  Target Milestone: ---

The evrp pass generates incorrect ranges for __builtin_clz when it is called
within a function named __builtin_clz. While calling it in this manner seems
questionable, two relatively recent tests in the testsuite (gcc.dg/pr100521.c
and gcc.dg/pr100790.c) suggest that gcc should handle this.

The test case gcc.dg/pr100790.c is as follows:

  __builtin_clz(int x) { x ? __builtin_clz(x) : 32; }

Compiling this for x86_64 using -O3 -fpermissive results in the evrp IR:

  Global Exported: iftmp.0_3 = [irange] int [1, 31]
  __attribute__((nothrow, leaf, const))
  int __builtin_clz (int x)
  {
    int iftmp.0_3;

    <bb 2> :
    if (x_1(D) != 0)
      goto <bb 3>; [INV]
    else
      goto <bb 4>; [INV]

    <bb 3> :
    iftmp.0_3 = __builtin_clz (x_1(D));

    <bb 4> :
    return;

  }

The range for iftmp.0_3 (which is an internal call to CFN_BUILT_IN_CLZ) should
be [0, 31], not [1, 31].

Reply via email to