<div dir="ltr">Hi<div>I am spotting this code is not optimized</div><div><br></div><div><div>typedef float float4 __attribute__((ext_vector_type(4))); </div><div><br></div><div><br></div><div>float4 f(float4 RGBA)</div><div>
{</div><div><span class="" style="white-space:pre">       </span>return RGBA.yzxw+RGBA.xxyw*3.4f;</div><div>}</div><div><br></div><div>float4 g(int x , float z ) </div><div>{</div><div><span class="" style="white-space:pre">        </span>float4 W;</div>
<div><span class="" style="white-space:pre">    </span>W.x=W.y=W.z=W.w=x+1;</div><div><span class="" style="white-space:pre">       </span>for(int i=0;i<10;i++)</div><div><span class="" style="white-space:pre">   </span>{</div><div>
<span class="" style="white-space:pre">               </span>W=f(-W);</div><div><span class="" style="white-space:pre">   </span>}</div><div><span class="" style="white-space:pre">  </span>return W;</div><div>}</div></div><div>LLVM misses the posibility to reorder instructions and group constants. ( optimization is not done as well with float instead of float4)</div>
<div><br></div><div>Is this suppose to happen? maximum optimization could be constant*vector+vector in this case.</div><div><br></div><div>when I compile with</div><div>clang temp.cpp -S -emit-llvm  -O3 -ffast-math<br></div>
<div>I get this code.</div><div><br></div><div><div>define <4 x float> @_Z1gif(i32 %x, float %z) #0 {</div><div>entry:</div><div>  %add = add nsw i32 %x, 1</div><div>  %conv = sitofp i32 %add to float</div><div>  %0 = insertelement <4 x float> undef, float %conv, i32 3</div>
<div>  %1 = insertelement <4 x float> %0, float %conv, i32 2</div><div>  %2 = insertelement <4 x float> %1, float %conv, i32 1</div><div>  %3 = insertelement <4 x float> %2, float %conv, i32 0</div><div>
  %sub = fsub fast <4 x float> <float -0.000000e+00, float -0.000000e+00, float -0.000000e+00, float -0.000000e+00>, %3</div><div>  %4 = shufflevector <4 x float> %sub, <4 x float> undef, <4 x i32> <i32 1, i32 2, i32 0, i32 3></div>
<div>  %5 = shufflevector <4 x float> %sub, <4 x float> undef, <4 x i32> <i32 0, i32 0, i32 1, i32 3></div><div>  %mul.i = fmul fast <4 x float> %5, <float 0x400B333340000000, float 0x400B333340000000, float 0x400B333340000000, float 0x400B333340000000></div>
<div>  %add.i = fadd fast <4 x float> %4, %mul.i</div><div>  %sub.1 = fsub fast <4 x float> <float -0.000000e+00, float -0.000000e+00, float -0.000000e+00, float -0.000000e+00>, %add.i</div><div>  %6 = shufflevector <4 x float> %sub.1, <4 x float> undef, <4 x i32> <i32 1, i32 2, i32 0, i32 3></div>
<div>  %7 = shufflevector <4 x float> %sub.1, <4 x float> undef, <4 x i32> <i32 0, i32 0, i32 1, i32 3></div><div>  %mul.i.1 = fmul fast <4 x float> %7, <float 0x400B333340000000, float 0x400B333340000000, float 0x400B333340000000, float 0x400B333340000000></div>
<div>  %add.i.1 = fadd fast <4 x float> %6, %mul.i.1</div><div>  %sub.2 = fsub fast <4 x float> <float -0.000000e+00, float -0.000000e+00, float -0.000000e+00, float -0.000000e+00>, %add.i.1</div><div>  %8 = shufflevector <4 x float> %sub.2, <4 x float> undef, <4 x i32> <i32 1, i32 2, i32 0, i32 3></div>
<div>  %9 = shufflevector <4 x float> %sub.2, <4 x float> undef, <4 x i32> <i32 0, i32 0, i32 1, i32 3></div><div>  %mul.i.2 = fmul fast <4 x float> %9, <float 0x400B333340000000, float 0x400B333340000000, float 0x400B333340000000, float 0x400B333340000000></div>
<div>  %add.i.2 = fadd fast <4 x float> %8, %mul.i.2</div><div>  %sub.3 = fsub fast <4 x float> <float -0.000000e+00, float -0.000000e+00, float -0.000000e+00, float -0.000000e+00>, %add.i.2</div><div>  %10 = shufflevector <4 x float> %sub.3, <4 x float> undef, <4 x i32> <i32 1, i32 2, i32 0, i32 3></div>
<div>  %11 = shufflevector <4 x float> %sub.3, <4 x float> undef, <4 x i32> <i32 0, i32 0, i32 1, i32 3></div><div>  %mul.i.3 = fmul fast <4 x float> %11, <float 0x400B333340000000, float 0x400B333340000000, float 0x400B333340000000, float 0x400B333340000000></div>
<div>  %add.i.3 = fadd fast <4 x float> %10, %mul.i.3</div><div>  %sub.4 = fsub fast <4 x float> <float -0.000000e+00, float -0.000000e+00, float -0.000000e+00, float -0.000000e+00>, %add.i.3</div><div>  %12 = shufflevector <4 x float> %sub.4, <4 x float> undef, <4 x i32> <i32 1, i32 2, i32 0, i32 3></div>
<div>  %13 = shufflevector <4 x float> %sub.4, <4 x float> undef, <4 x i32> <i32 0, i32 0, i32 1, i32 3></div><div>  %mul.i.4 = fmul fast <4 x float> %13, <float 0x400B333340000000, float 0x400B333340000000, float 0x400B333340000000, float 0x400B333340000000></div>
<div>  %add.i.4 = fadd fast <4 x float> %12, %mul.i.4</div><div>  %sub.5 = fsub fast <4 x float> <float -0.000000e+00, float -0.000000e+00, float -0.000000e+00, float -0.000000e+00>, %add.i.4</div><div>  %14 = shufflevector <4 x float> %sub.5, <4 x float> undef, <4 x i32> <i32 1, i32 2, i32 0, i32 3></div>
<div>  %15 = shufflevector <4 x float> %sub.5, <4 x float> undef, <4 x i32> <i32 0, i32 0, i32 1, i32 3></div><div>  %mul.i.5 = fmul fast <4 x float> %15, <float 0x400B333340000000, float 0x400B333340000000, float 0x400B333340000000, float 0x400B333340000000></div>
<div>  %add.i.5 = fadd fast <4 x float> %14, %mul.i.5</div><div>  %sub.6 = fsub fast <4 x float> <float -0.000000e+00, float -0.000000e+00, float -0.000000e+00, float -0.000000e+00>, %add.i.5</div><div>  %16 = shufflevector <4 x float> %sub.6, <4 x float> undef, <4 x i32> <i32 1, i32 2, i32 0, i32 3></div>
<div>  %17 = shufflevector <4 x float> %sub.6, <4 x float> undef, <4 x i32> <i32 0, i32 0, i32 1, i32 3></div><div>  %mul.i.6 = fmul fast <4 x float> %17, <float 0x400B333340000000, float 0x400B333340000000, float 0x400B333340000000, float 0x400B333340000000></div>
<div>  %add.i.6 = fadd fast <4 x float> %16, %mul.i.6</div><div>  %sub.7 = fsub fast <4 x float> <float -0.000000e+00, float -0.000000e+00, float -0.000000e+00, float -0.000000e+00>, %add.i.6</div><div>  %18 = shufflevector <4 x float> %sub.7, <4 x float> undef, <4 x i32> <i32 1, i32 2, i32 0, i32 3></div>
<div>  %19 = shufflevector <4 x float> %sub.7, <4 x float> undef, <4 x i32> <i32 0, i32 0, i32 1, i32 3></div><div>  %mul.i.7 = fmul fast <4 x float> %19, <float 0x400B333340000000, float 0x400B333340000000, float 0x400B333340000000, float 0x400B333340000000></div>
<div>  %add.i.7 = fadd fast <4 x float> %18, %mul.i.7</div><div>  %sub.8 = fsub fast <4 x float> <float -0.000000e+00, float -0.000000e+00, float -0.000000e+00, float -0.000000e+00>, %add.i.7</div><div>  %20 = shufflevector <4 x float> %sub.8, <4 x float> undef, <4 x i32> <i32 1, i32 2, i32 0, i32 3></div>
<div>  %21 = shufflevector <4 x float> %sub.8, <4 x float> undef, <4 x i32> <i32 0, i32 0, i32 1, i32 3></div><div>  %mul.i.8 = fmul fast <4 x float> %21, <float 0x400B333340000000, float 0x400B333340000000, float 0x400B333340000000, float 0x400B333340000000></div>
<div>  %add.i.8 = fadd fast <4 x float> %20, %mul.i.8</div><div>  %sub.9 = fsub fast <4 x float> <float -0.000000e+00, float -0.000000e+00, float -0.000000e+00, float -0.000000e+00>, %add.i.8</div><div>  %22 = shufflevector <4 x float> %sub.9, <4 x float> undef, <4 x i32> <i32 1, i32 2, i32 0, i32 3></div>
<div>  %23 = shufflevector <4 x float> %sub.9, <4 x float> undef, <4 x i32> <i32 0, i32 0, i32 1, i32 3></div><div>  %mul.i.9 = fmul fast <4 x float> %23, <float 0x400B333340000000, float 0x400B333340000000, float 0x400B333340000000, float 0x400B333340000000></div>
<div>  %add.i.9 = fadd fast <4 x float> %22, %mul.i.9</div><div>  ret <4 x float> %add.i.9</div><div>}</div></div><div><br></div><div><br></div></div>