[llvm] e3f6c2d - [InstCombine] Don't look through bitcast from vector in collectInsertionElements.

Craig Topper via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 20 09:15:54 PDT 2022


Author: Craig Topper
Date: 2022-04-20T09:15:32-07:00
New Revision: e3f6c2d288ea4c67136fd88b2021ab7fb2b2f2b2

URL: https://github.com/llvm/llvm-project/commit/e3f6c2d288ea4c67136fd88b2021ab7fb2b2f2b2
DIFF: https://github.com/llvm/llvm-project/commit/e3f6c2d288ea4c67136fd88b2021ab7fb2b2f2b2.diff

LOG: [InstCombine] Don't look through bitcast from vector in collectInsertionElements.

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

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp
index 084702db41526..e27b659f2dfb9 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp
@@ -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:

diff  --git a/llvm/test/Transforms/InstCombine/bitcast.ll b/llvm/test/Transforms/InstCombine/bitcast.ll
index 94f532a461614..9289afccff311 100644
--- a/llvm/test/Transforms/InstCombine/bitcast.ll
+++ b/llvm/test/Transforms/InstCombine/bitcast.ll
@@ -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>


        


More information about the llvm-commits mailing list