<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 - Poor handling of float3 within a float4 type"
   href="https://bugs.llvm.org/show_bug.cgi?id=50920">50920</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Poor handling of float3 within a float4 type
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>libraries
          </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>Common Code Generator Code
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>llvm-dev@redking.me.uk
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>a.bataev@hotmail.com, llvm-bugs@lists.llvm.org, spatel+llvm@rotateright.com
          </td>
        </tr></table>
      <p>
        <div>
        <pre><a href="https://godbolt.org/z/7jxnGdd7d">https://godbolt.org/z/7jxnGdd7d</a>

#include <cstdint>
#include <cfloat>
#include <x86intrin.h>

__m128 invert_float3(__m128 x) {
    for (int i = 0; i != 3; ++i) {
          x[i] = x[i] == 0 ? FLT_MAX : 1.0 / x[i];
    }
    return x;
}

define <4 x float> @invert_float3(<4 x float> %0) {
  %2 = extractelement <4 x float> %0, i32 0
  %3 = fcmp oeq float %2, 0.000000e+00
  %4 = fdiv float 1.000000e+00, %2
  %5 = select i1 %3, float 0x47EFFFFFE0000000, float %4
  %6 = shufflevector <4 x float> %0, <4 x float> undef, <2 x i32> <i32 1, i32
2>
  %7 = fcmp oeq <2 x float> %6, zeroinitializer
  %8 = fdiv <2 x float> <float 1.000000e+00, float 1.000000e+00>, %6
  %9 = select <2 x i1> %7, <2 x float> <float 0x47EFFFFFE0000000, float
0x47EFFFFFE0000000>, <2 x float> %8
  %10 = insertelement <4 x float> %0, float %5, i32 0
  %11 = shufflevector <2 x float> %9, <2 x float> poison, <4 x i32> <i32 0, i32
1, i32 undef, i32 undef>
  %12 = shufflevector <4 x float> %10, <4 x float> %11, <4 x i32> <i32 0, i32
4, i32 5, i32 3>
  ret <4 x float> %12
}

invert_float3(float __vector(4)):
        vxorps  %xmm1, %xmm1, %xmm1
        vucomiss        %xmm1, %xmm0
        jne     .LBB0_2
        jp      .LBB0_2
        vmovss  .LCPI0_0(%rip), %xmm1           # xmm1 = mem[0],zero,zero,zero
        jmp     .LBB0_3
.LBB0_2:
        vmovss  .LCPI0_1(%rip), %xmm1           # xmm1 = mem[0],zero,zero,zero
        vdivss  %xmm0, %xmm1, %xmm1
.LBB0_3:
        vmovaps .LCPI0_2(%rip), %xmm4           # xmm4 = <1.0E+0,1.0E+0,u,u>
        vpermilps       $233, %xmm0, %xmm2      # xmm2 = xmm0[1,2,2,3]
        vxorps  %xmm3, %xmm3, %xmm3
        vblendps        $3, %xmm1, %xmm0, %xmm0         # xmm0 =
xmm1[0,1],xmm0[2,3]
        vcmpeqps        %xmm3, %xmm2, %xmm3
        vdivps  %xmm2, %xmm4, %xmm2
        vblendvps       %xmm3, .LCPI0_3(%rip), %xmm2, %xmm2
        vshufps $76, %xmm2, %xmm0, %xmm0        # xmm0 = xmm0[0,3],xmm2[0,1]
        vpermilps       $120, %xmm0, %xmm0      # xmm0 = xmm0[0,2,3,1]
        retq

Many vector math libraries embed float3 vectors inside a float4 register
vector, and just ignore the [3] element. For instance, in this safe fdiv code,
only the first 3 elements are inverted. 

I'm hoping that D57059 will help with this, and ideally will generate a <float
x 3> pattern that blends with the [3] pass-through value.</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>