<div dir="ltr">Hi,<div><br></div><div style>I was fiddling around today with InstCombine, trying to get it to combine shufflevectors a bit more cleverly. I came across the following comment which worried me somewhat:</div>
<div style><br></div><div style><div>  // Here we are really conservative:</div><div>  // we are absolutely afraid of producing a shuffle mask not in the input</div><div>  // program, because the code gen may not be smart enough to turn a merged</div>
<div>  // shuffle into two specific shuffles: it may produce worse code.  As such,</div><div>  // we only merge two shuffles if the result is either a splat or one of the</div><div>  // input shuffle masks.  In this case, merging the shuffles just removes</div>
<div>  // one instruction, which we know is safe.</div><div><br></div><div style>Now, there are many clever things InstCombine could do with shufflevector. The two I have in my queue at the moment are:</div><div style>  1) Where there's an insertelement into vector B that comes direct from an extractelement of vector A, and vector A's length is less than vector B's, create a shuffle to extend A then another shuffle to perform the equivalent of extract/insertelement.</div>
<div style>  2) Where two shuffles' masks could combine to make a monotonically increasing sequence, perform the combination.</div><div style><br></div><div style>Both of the above have caveats that can't be said in one sentence, but they're basically rewriting common front-end patterns to make shuffles that correspond to vector extension (VEXT instructions in ARM) or concatenation of subvectors.</div>
<div style><br></div><div style>Now, I think these would both be of use to any architecture that has decent shufflevector support, and InstCombine seems like the right place for it. But if InstCombine is supposed to be conservative, where should these optimizations go?</div>
<div style><br></div><div style>I remember Chandler being a bit worried by similar target-specific stuff going in to InstSimplify - is InstCombine similar in that it's meant to only canonicalise?</div><div style><br></div>
<div style>Input would be helpful :)</div><div style><br></div><div style>Cheers,</div><div style><br></div><div style>James</div></div></div>