[InstCombine] Don't look through bitcast from vector in collectInsertionElements.
authorCraig Topper <craig.topper@sifive.com>
Wed, 20 Apr 2022 16:05:35 +0000 (09:05 -0700)
committerCraig Topper <craig.topper@sifive.com>
Wed, 20 Apr 2022 16:15:32 +0000 (09:15 -0700)
We're making a recursive call here and everything in the function
assumes we're looking at scalars. This would be violated if we
looked through a bitcast from vectors.

Reviewed By: spatel

Differential Revision: https://reviews.llvm.org/D124015

llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp
llvm/test/Transforms/InstCombine/bitcast.ll

index 084702d..e27b659 100644 (file)
@@ -2271,6 +2271,8 @@ static bool collectInsertionElements(Value *V, unsigned Shift,
   switch (I->getOpcode()) {
   default: return false; // Unhandled case.
   case Instruction::BitCast:
+    if (I->getOperand(0)->getType()->isVectorTy())
+      return false;
     return collectInsertionElements(I->getOperand(0), Shift, Elements, VecEltTy,
                                     isBigEndian);
   case Instruction::ZExt:
index 94f532a..9289afc 100644 (file)
@@ -431,12 +431,14 @@ define <2 x float> @test6(float %A){
   ret <2 x float> %tmp35
 }
 
-; FIXME: This test should not be optimized by OptimizeIntegerToVectorInsertions.
-; The bitcast from vector is confusing it.
+; This test should not be optimized by OptimizeIntegerToVectorInsertions.
+; The bitcast from vector previously confused it.
 define <2 x i64> @int2vec_insertion_bitcast_from_vec(i64 %x) {
 ; CHECK-LABEL: @int2vec_insertion_bitcast_from_vec(
-; CHECK-NEXT:    [[TMP1:%.*]] = insertelement <2 x i64> <i64 poison, i64 0>, i64 [[X:%.*]], i64 0
-; CHECK-NEXT:    ret <2 x i64> [[TMP1]]
+; CHECK-NEXT:    [[A:%.*]] = bitcast i64 [[X:%.*]] to <8 x i8>
+; CHECK-NEXT:    [[B:%.*]] = zext <8 x i8> [[A]] to <8 x i16>
+; CHECK-NEXT:    [[D:%.*]] = bitcast <8 x i16> [[B]] to <2 x i64>
+; CHECK-NEXT:    ret <2 x i64> [[D]]
 ;
   %a = bitcast i64 %x to <8 x i8>
   %b = zext <8 x i8> %a to <8 x i16>