[LLVMdev] Question on SelectionDAGBuilder

David Greene dag at cray.com
Tue Mar 30 15:54:40 PDT 2010


I ran into some odd code being generated today and I came
across something that doesn't look quite right.

In SelectionDAGBuilder::visitShuffleVector there's some code to see if we can
convert the shuffle to an EXTRACT_SUBVECTOR.  After computing min/max
values of the mask for each operand, there's a look that looks at the ranges
and determines whether an EXTRACT_SUBVECTOR can be used:

    for (int Input=0; Input < 2; ++Input) {
      if (MinRange[Input] == (int)(SrcNumElts+1) && MaxRange[Input] == -1) {
        RangeUse[Input] = 0; // Unused
        StartIdx[Input] = 0;
      } else if (MaxRange[Input] - MinRange[Input] < (int)MaskNumElts) {
        // Fits within range but we should see if we can find a good
        // start index that is a multiple of the mask length.
        if (MaxRange[Input] < (int)MaskNumElts) {
          RangeUse[Input] = 1; // Extract from beginning of the vector
          StartIdx[Input] = 0;
        } else {
          StartIdx[Input] = (MinRange[Input]/MaskNumElts)*MaskNumElts;
          if (MaxRange[Input] - StartIdx[Input] < (int)MaskNumElts &&
              StartIdx[Input] + MaskNumElts < SrcNumElts)
            RangeUse[Input] = 1; // Extract from a multiple of the mask 
length.
        }
      }
    }

Should this line:

              StartIdx[Input] + MaskNumElts < SrcNumElts)


use <= rather than <?

In my case I have the following:

	%r4 = shufflevector <8 x double> %r3, <8 x double> undef, <4 x i32> 
                    < i32 4, i32 5, i32 6, i32 7 >		; <<4 x double>> [#uses=1]

I would have expected this to result in an EXTRACT_SUBVECTOR of %r3 starting 
at index 4, but the use of < above prevents that.

I'm not totally following the logic here, so if < is indeed correct can 
someone explain why?  Thanks!

                                           -Dave




More information about the llvm-dev mailing list