<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - [OpenCL] Invalid optimization of subgroup intrinsics"
   href="https://bugs.llvm.org/show_bug.cgi?id=46199">46199</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>[OpenCL] Invalid optimization of subgroup intrinsics
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Windows NT
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>enhancement
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>OpenCL
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>piotr.fusik@intel.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>anastasia.stulova@arm.com, llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>The following OpenCL code:

kernel void test(global int *data)
{
    uint id = (uint) get_global_id(0);
    if (id < 4)
        data[id] = sub_group_elect();
    else
        data[id] = sub_group_elect();
}

when compiled with the current master
(f2c97656644e783622a6e60fe452b41ffe0f1d18) as follows: clang -cl-std=CL2.0
-include opencl-c.h -S -emit-llvm sub_group_elect_opt.cl

has an invalid optimization of combining the branches:

; Function Attrs: convergent norecurse nounwind uwtable
define dso_local spir_kernel void @test(i32* nocapture %data)
local_unnamed_addr #0 !kernel_arg_addr_space !4 !kernel_arg_access_qual !5
!kernel_arg_type !6 !kernel_arg_base_type !6 !kernel_arg_type_qual !7 {
entry:
  %call = tail call i64 @"?get_global_id@@$$J0YAKI@Z"(i32 0) #3
  %call2 = tail call i32 @"?sub_group_elect@@$$J0YAHXZ"() #4
  %idxprom = and i64 %call, 4294967295
  %arrayidx = getelementptr inbounds i32, i32* %data, i64 %idxprom
  store i32 %call2, i32* %arrayidx, align 4, !tbaa !8
  ret void
}

sub_group_elect is one of the many functions added in
<a href="https://reviews.llvm.org/D79781">https://reviews.llvm.org/D79781</a> that perform implicit communication within a
subgroup, i.e. threads implemented as SIMD on GPU. All the added functions are
affected.

<a href="https://reviews.llvm.org/D68994">https://reviews.llvm.org/D68994</a> is a proposal of addressing this problem with
the `convergent` attribute.</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>