<div dir="ltr">Hi, I received an internal test case from a game team (it wasn't about this in particular), and I was wondering if there was maybe an opportunity to canonicalize a particular code pattern:<div><br></div><div><div>  %inputi = bitcast <4 x float> %input to <4 x i32></div><div><br></div><div>  %row0i = and <4 x i32> %inputi, <i32 -1, i32 0, i32 0, i32 0></div><div>  %row0 = bitcast <4 x i32> %row0i to <4 x float></div><div><br></div><div>  %row1i = and <4 x i32> %inputi, <i32 0, i32 -1, i32 0, i32 0></div><div>  %row1 = bitcast <4 x i32> %row1i to <4 x float></div><div><br></div><div>  %row2i = and <4 x i32> %inputi, <i32 0, i32 0, i32 -1, i32 0></div><div>  %row2 = bitcast <4 x i32> %row2i to <4 x float></div><div><br></div><div>  %row3i = and <4 x i32> %inputi, <i32 0, i32 0, i32 0, i32 -1></div><div>  %row3 = bitcast <4 x i32> %row3i to <4 x float></div></div><div><br></div><div>This arises from code which expands a vector of scale factors into the diagonal of a 4x4 diagonal matrix. This code pattern is coming from intrinsics which are explicitly doing the masking like this.</div><div><br></div><div>My question is: should we canonicalize this to:</div><div><br></div><div><div><div>  %row0 = shufflevector <4 x float> %input, <4 x float> zeroinitializer, <4 x i32> <i32 0, i32 4, i32 4, i32 4></div><div>  %row1 = shufflevector <4 x float> %input, <4 x float> zeroinitializer, <4 x i32> <i32 4, i32 1, i32 4, i32 4></div><div>  %row2 = shufflevector <4 x float> %input, <4 x float> zeroinitializer, <4 x i32> <i32 4, i32 4, i32 2, i32 4></div><div>  %row3 = shufflevector <4 x float> %input, <4 x float> zeroinitializer, <4 x i32> <i32 4, i32 4, i32 4, i32 3></div></div></div><div><br></div><div>which seems to better express the intent, or a sequence of insertelement and extract element (which is what we get for the attached code), or leave it as is? (or any better ideas?)</div><div><br></div><div>Forgive my naivete if there's something obvious I'm missing since I haven't done much w.r.t. vectors in LLVM.</div><div><br></div><div>-- Sean Silva</div></div>