[PATCH] D15392: [InstCombine] fold trunc ([lshr] (bitcast vector) ) --> extractelement (PR25543)

Sanjay Patel via llvm-commits llvm-commits at lists.llvm.org
Thu Dec 10 15:15:33 PST 2015


spatel added a comment.

To take this to its logical (I hope) conclusion...
We shouldn't need the transform in http://reviews.llvm.org/D14879 at all if we:

1. Canonicalize bitcasts before extractelements
2. Transform (bitcast (bitcast X)) --> bitcast X

I'm not sure why we wouldn't allow the 2nd for any types, but CastInst::isEliminableCastPair() says we're not allowed to simplify those if vector and scalar types are intermingled and it's not a roundtrip to the original type:

  // If either of the casts are a bitcast from scalar to vector, disallow the
  // merging. However, bitcast of A->B->A are allowed.

So for the 8 vector/scalar type combinations for a pair of bitcasts, we don't optimize the middle 6 in this list:

  define ppc_fp128 @bitcast_bitcast_scalar_scalar_scalar(i128 %A) {
    %bc1 = bitcast i128 %A to fp128
    %bc2 = bitcast fp128 %bc1 to ppc_fp128
    ret ppc_fp128 %bc2
  }
  
  define <2 x i32> @bitcast_bitcast_scalar_scalar_vector(i64 %A) {
    %bc1 = bitcast i64 %A to double
    %bc2 = bitcast double %bc1 to <2 x i32>
    ret <2 x i32> %bc2
  }
  
  define double @bitcast_bitcast_scalar_vector_scalar(i64 %A) {
    %bc1 = bitcast i64 %A to <2 x i32>
    %bc2 = bitcast <2 x i32> %bc1 to double
    ret double %bc2
  }
  
  define <2 x i32> @bitcast_bitcast_scalar_vector_vector(i64 %A) {
    %bc1 = bitcast i64 %A to <4 x i16>
    %bc2 = bitcast <4 x i16> %bc1 to <2 x i32>
    ret <2 x i32> %bc2
  }
  
  define i64 @bitcast_bitcast_vector_scalar_scalar(<2 x i32> %A) {
    %bc1 = bitcast <2 x i32> %A to double
    %bc2 = bitcast double %bc1 to i64
    ret i64 %bc2
  }
  
  define <4 x i16> @bitcast_bitcast_vector_scalar_vector(<2 x i32> %A) {
    %bc1 = bitcast <2 x i32> %A to double
    %bc2 = bitcast double %bc1 to <4 x i16>
    ret <4 x i16> %bc2
  }
  
  define double @bitcast_bitcast_vector_vector_scalar(<2 x float> %A) {
    %bc1 = bitcast <2 x float> %A to <4 x i16>
    %bc2 = bitcast <4 x i16> %bc1 to double
    ret double %bc2
  }
  
  define <2 x i32> @bitcast_bitcast_vector_vector_vector(<2 x float> %A) {
    %bc1 = bitcast <2 x float> %A to <4 x i16>
    %bc2 = bitcast <4 x i16> %bc1 to <2 x i32>
    ret <2 x i32> %bc2
  }



http://reviews.llvm.org/D15392





More information about the llvm-commits mailing list