[PATCH] [ARM64]Fix a bug when lowing shuffle vector to EXT instruction

Tim Northover t.p.northover at gmail.com
Fri Apr 25 03:26:32 PDT 2014

Hi Hao,

This logic looks horribly convoluted, given the problem it's trying to solve. I think it may be time to step back and rewrite it with UNDEF support from the beginning.

One possible idea: the width is going to be a power of 2, so if we made ExpectedElt an APInt of the correct width, any overflow might well do precisely what we *want*. Further, we then ReverseExt if and only if ExpectedElt *starts* in the second half (I think).

So the total logic might be:

    FirstRealElt = ...
    ExpectedElt = APInt(...);
    FirstWrongElt = std::find_if(M.begin(), M.end(), [&](int Elt) { return Elt != ExpectedElt++ && Elt != -1; })
    if (FirstWrongElt != M.end()) return false;
    // N.b. ExpectedElt is now back to its original value via wrapping
    if (ExpectedElt >= NumElts) {
      ReverseExt = true;
      ExpectedElt -= NumElts;
    Imm = ExpectedElt;
    return true;

How does that look?




More information about the llvm-commits mailing list