Skip to content

Commit 20638bc

Browse files
committed
Remove Instruction check difference
1 parent ae9596f commit 20638bc

File tree

2 files changed

+22
-12
lines changed

2 files changed

+22
-12
lines changed

llvm/lib/Transforms/Vectorize/VectorCombine.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1746,7 +1746,7 @@ static Value *generateNewInstTree(ArrayRef<InstLane> Item, FixedVectorType *Ty,
17461746
return Builder.CreateCmp(CI->getPredicate(), Ops[0], Ops[1]);
17471747
if (auto *SI = dyn_cast<SelectInst>(I))
17481748
return Builder.CreateSelect(Ops[0], Ops[1], Ops[2], "", SI);
1749-
if (auto CI = dyn_cast<CastInst>(I))
1749+
if (auto *CI = dyn_cast<CastInst>(I))
17501750
return Builder.CreateCast((Instruction::CastOps)CI->getOpcode(), Ops[0],
17511751
DstTy);
17521752
if (II)
@@ -1760,7 +1760,8 @@ static Value *generateNewInstTree(ArrayRef<InstLane> Item, FixedVectorType *Ty,
17601760
// do so.
17611761
bool VectorCombine::foldShuffleToIdentity(Instruction &I) {
17621762
auto *Ty = dyn_cast<FixedVectorType>(I.getType());
1763-
if (!Ty)
1763+
if (!Ty || !isa<Instruction>(I.getOperand(0)) ||
1764+
!isa<Instruction>(I.getOperand(1)))
17641765
return false;
17651766

17661767
SmallVector<InstLane> Start(Ty->getNumElements());

llvm/test/Transforms/VectorCombine/AArch64/shuffletoidentity.ll

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ define <8 x i8> @trivial(<8 x i8> %a) {
1515

1616
define <4 x i32> @add_same_operands(<4 x i32> %x) {
1717
; CHECK-LABEL: @add_same_operands(
18-
; CHECK-NEXT: [[REVSHUF:%.*]] = add <4 x i32> [[X:%.*]], [[X]]
18+
; CHECK-NEXT: [[SHUF:%.*]] = shufflevector <4 x i32> [[X:%.*]], <4 x i32> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>
19+
; CHECK-NEXT: [[ADD:%.*]] = add <4 x i32> [[SHUF]], [[SHUF]]
20+
; CHECK-NEXT: [[REVSHUF:%.*]] = shufflevector <4 x i32> [[ADD]], <4 x i32> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>
1921
; CHECK-NEXT: ret <4 x i32> [[REVSHUF]]
2022
;
2123
%shuf = shufflevector <4 x i32> %x, <4 x i32> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>
@@ -362,7 +364,8 @@ define <8 x i8> @inner_shuffle(<8 x i8> %a, <8 x i8> %b, <8 x i8> %c) {
362364
define <4 x i32> @extrause_add_same_operands(<4 x i32> %x) {
363365
; CHECK-LABEL: @extrause_add_same_operands(
364366
; CHECK-NEXT: [[SHUF:%.*]] = shufflevector <4 x i32> [[X:%.*]], <4 x i32> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>
365-
; CHECK-NEXT: [[REVSHUF:%.*]] = add <4 x i32> [[X]], [[X]]
367+
; CHECK-NEXT: [[ADD:%.*]] = add <4 x i32> [[SHUF]], [[SHUF]]
368+
; CHECK-NEXT: [[REVSHUF:%.*]] = shufflevector <4 x i32> [[ADD]], <4 x i32> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>
366369
; CHECK-NEXT: [[ADD2:%.*]] = add <4 x i32> [[SHUF]], [[REVSHUF]]
367370
; CHECK-NEXT: ret <4 x i32> [[ADD2]]
368371
;
@@ -510,7 +513,9 @@ define <8 x half> @fma(<8 x half> %a, <8 x half> %b, <8 x half> %c) {
510513

511514
define <4 x i64> @single_zext(<4 x i32> %x) {
512515
; CHECK-LABEL: @single_zext(
513-
; CHECK-NEXT: [[REVSHUF:%.*]] = zext <4 x i32> [[X:%.*]] to <4 x i64>
516+
; CHECK-NEXT: [[SHUF:%.*]] = shufflevector <4 x i32> [[X:%.*]], <4 x i32> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>
517+
; CHECK-NEXT: [[ZEXT:%.*]] = zext <4 x i32> [[SHUF]] to <4 x i64>
518+
; CHECK-NEXT: [[REVSHUF:%.*]] = shufflevector <4 x i64> [[ZEXT]], <4 x i64> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>
514519
; CHECK-NEXT: ret <4 x i64> [[REVSHUF]]
515520
;
516521
%shuf = shufflevector <4 x i32> %x, <4 x i32> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>
@@ -690,8 +695,10 @@ define void @trunc(<8 x i64> %a, <8 x i64> %b, ptr %p) {
690695

691696
define <4 x i64> @zext_chain(<4 x i16> %x) {
692697
; CHECK-LABEL: @zext_chain(
693-
; CHECK-NEXT: [[TMP1:%.*]] = zext <4 x i16> [[X:%.*]] to <4 x i32>
694-
; CHECK-NEXT: [[REVSHUF:%.*]] = sext <4 x i32> [[TMP1]] to <4 x i64>
698+
; CHECK-NEXT: [[SHUF:%.*]] = shufflevector <4 x i16> [[X:%.*]], <4 x i16> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>
699+
; CHECK-NEXT: [[ZEXT:%.*]] = zext <4 x i16> [[SHUF]] to <4 x i32>
700+
; CHECK-NEXT: [[SEXT:%.*]] = sext <4 x i32> [[ZEXT]] to <4 x i64>
701+
; CHECK-NEXT: [[REVSHUF:%.*]] = shufflevector <4 x i64> [[SEXT]], <4 x i64> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>
695702
; CHECK-NEXT: ret <4 x i64> [[REVSHUF]]
696703
;
697704
%shuf = shufflevector <4 x i16> %x, <4 x i16> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>
@@ -892,11 +899,13 @@ entry:
892899

893900
define <4 x i8> @singleop(<4 x i8> %a, <4 x i8> %b) {
894901
; CHECK-LABEL: @singleop(
895-
; CHECK-NEXT: [[TMP1:%.*]] = shufflevector <4 x i8> [[B:%.*]], <4 x i8> poison, <4 x i32> zeroinitializer
896-
; CHECK-NEXT: [[TMP2:%.*]] = zext <4 x i8> [[A:%.*]] to <4 x i16>
897-
; CHECK-NEXT: [[TMP3:%.*]] = zext <4 x i8> [[TMP1]] to <4 x i16>
898-
; CHECK-NEXT: [[TMP4:%.*]] = add <4 x i16> [[TMP2]], [[TMP3]]
899-
; CHECK-NEXT: [[R:%.*]] = trunc <4 x i16> [[TMP4]] to <4 x i8>
902+
; CHECK-NEXT: [[A1:%.*]] = shufflevector <4 x i8> [[A:%.*]], <4 x i8> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>
903+
; CHECK-NEXT: [[B1:%.*]] = shufflevector <4 x i8> [[B:%.*]], <4 x i8> poison, <4 x i32> zeroinitializer
904+
; CHECK-NEXT: [[A2:%.*]] = zext <4 x i8> [[A1]] to <4 x i16>
905+
; CHECK-NEXT: [[B2:%.*]] = zext <4 x i8> [[B1]] to <4 x i16>
906+
; CHECK-NEXT: [[AB:%.*]] = add <4 x i16> [[A2]], [[B2]]
907+
; CHECK-NEXT: [[T:%.*]] = trunc <4 x i16> [[AB]] to <4 x i8>
908+
; CHECK-NEXT: [[R:%.*]] = shufflevector <4 x i8> [[T]], <4 x i8> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>
900909
; CHECK-NEXT: ret <4 x i8> [[R]]
901910
;
902911
%a1 = shufflevector <4 x i8> %a, <4 x i8> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>

0 commit comments

Comments
 (0)