Skip to content

Commit e3f6c2d

Browse files
committed
[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
1 parent 11db0bb commit e3f6c2d

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2271,6 +2271,8 @@ static bool collectInsertionElements(Value *V, unsigned Shift,
22712271
switch (I->getOpcode()) {
22722272
default: return false; // Unhandled case.
22732273
case Instruction::BitCast:
2274+
if (I->getOperand(0)->getType()->isVectorTy())
2275+
return false;
22742276
return collectInsertionElements(I->getOperand(0), Shift, Elements, VecEltTy,
22752277
isBigEndian);
22762278
case Instruction::ZExt:

llvm/test/Transforms/InstCombine/bitcast.ll

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -431,12 +431,14 @@ define <2 x float> @test6(float %A){
431431
ret <2 x float> %tmp35
432432
}
433433

434-
; FIXME: This test should not be optimized by OptimizeIntegerToVectorInsertions.
435-
; The bitcast from vector is confusing it.
434+
; This test should not be optimized by OptimizeIntegerToVectorInsertions.
435+
; The bitcast from vector previously confused it.
436436
define <2 x i64> @int2vec_insertion_bitcast_from_vec(i64 %x) {
437437
; CHECK-LABEL: @int2vec_insertion_bitcast_from_vec(
438-
; CHECK-NEXT: [[TMP1:%.*]] = insertelement <2 x i64> <i64 poison, i64 0>, i64 [[X:%.*]], i64 0
439-
; CHECK-NEXT: ret <2 x i64> [[TMP1]]
438+
; CHECK-NEXT: [[A:%.*]] = bitcast i64 [[X:%.*]] to <8 x i8>
439+
; CHECK-NEXT: [[B:%.*]] = zext <8 x i8> [[A]] to <8 x i16>
440+
; CHECK-NEXT: [[D:%.*]] = bitcast <8 x i16> [[B]] to <2 x i64>
441+
; CHECK-NEXT: ret <2 x i64> [[D]]
440442
;
441443
%a = bitcast i64 %x to <8 x i8>
442444
%b = zext <8 x i8> %a to <8 x i16>

0 commit comments

Comments
 (0)