Skip to content

Commit 29c8cff

Browse files
committed
prefer AltOp instead of interchangeable instructions of MainOp
1 parent bf43fff commit 29c8cff

File tree

2 files changed

+14
-18
lines changed

2 files changed

+14
-18
lines changed

llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1036,17 +1036,20 @@ static bool getInterchangeableInstruction(
10361036

10371037
static bool isConvertible(Instruction *I, Instruction *MainOp,
10381038
Instruction *AltOp) {
1039-
if (!I->isBinaryOp())
1040-
return I->getOpcode() == MainOp->getOpcode() ||
1041-
I->getOpcode() == AltOp->getOpcode();
10421039
assert(MainOp && "MainOp cannot be nullptr.");
1040+
if (I->getOpcode() == MainOp->getOpcode())
1041+
return true;
1042+
assert(AltOp && "AltOp cannot be nullptr.");
1043+
if (I->getOpcode() == AltOp->getOpcode())
1044+
return true;
1045+
if (!I->isBinaryOp())
1046+
return false;
10431047
SmallVector<std::unique_ptr<InterchangeableInstruction>> Candidate(
10441048
getInterchangeableInstruction(I));
10451049
for (std::unique_ptr<InterchangeableInstruction> &C : Candidate)
10461050
if (C->isSame(I) && C->isSame(MainOp))
10471051
return true;
10481052
Candidate = getInterchangeableInstruction(I);
1049-
assert(AltOp && "AltOp cannot be nullptr.");
10501053
for (std::unique_ptr<InterchangeableInstruction> &C : Candidate)
10511054
if (C->isSame(I) && C->isSame(AltOp))
10521055
return true;
@@ -1056,10 +1059,12 @@ static bool isConvertible(Instruction *I, Instruction *MainOp,
10561059
static std::pair<Instruction *, SmallVector<Value *>>
10571060
convertTo(Instruction *I, Instruction *MainOp, Instruction *AltOp) {
10581061
assert(isConvertible(I, MainOp, AltOp) && "Cannot convert the instruction.");
1059-
if (!I->isBinaryOp())
1060-
return std::make_pair(I->getOpcode() == MainOp->getOpcode() ? MainOp
1061-
: AltOp,
1062-
SmallVector<Value *>(I->operands()));
1062+
if (I->getOpcode() == MainOp->getOpcode())
1063+
return std::make_pair(MainOp, SmallVector<Value *>(I->operands()));
1064+
// Prefer AltOp instead of interchangeable instruction of MainOp.
1065+
if (I->getOpcode() == AltOp->getOpcode())
1066+
return std::make_pair(AltOp, SmallVector<Value *>(I->operands()));
1067+
assert(I->isBinaryOp() && "Cannot convert the instruction.");
10631068
SmallVector<std::unique_ptr<InterchangeableInstruction>> Candidate(
10641069
getInterchangeableInstruction(I));
10651070
for (std::unique_ptr<InterchangeableInstruction> &C : Candidate)

llvm/test/Transforms/SLPVectorizer/AArch64/gather-with-minbith-user.ll

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,7 @@ define void @h() {
55
; CHECK-LABEL: define void @h() {
66
; CHECK-NEXT: entry:
77
; CHECK-NEXT: [[ARRAYIDX2:%.*]] = getelementptr i8, ptr null, i64 16
8-
; CHECK-NEXT: [[TMP0:%.*]] = call <8 x i1> @llvm.vector.insert.v8i1.v2i1(<8 x i1> <i1 false, i1 false, i1 false, i1 false, i1 poison, i1 poison, i1 false, i1 false>, <2 x i1> zeroinitializer, i64 4)
9-
; CHECK-NEXT: [[TMP1:%.*]] = call <8 x i1> @llvm.vector.insert.v8i1.v2i1(<8 x i1> <i1 poison, i1 poison, i1 poison, i1 poison, i1 false, i1 false, i1 poison, i1 poison>, <2 x i1> zeroinitializer, i64 0)
10-
; CHECK-NEXT: [[TMP2:%.*]] = call <8 x i1> @llvm.vector.insert.v8i1.v2i1(<8 x i1> [[TMP1]], <2 x i1> zeroinitializer, i64 2)
11-
; CHECK-NEXT: [[TMP3:%.*]] = call <8 x i1> @llvm.vector.insert.v8i1.v2i1(<8 x i1> [[TMP2]], <2 x i1> zeroinitializer, i64 6)
12-
; CHECK-NEXT: [[TMP4:%.*]] = sub <8 x i1> [[TMP0]], [[TMP3]]
13-
; CHECK-NEXT: [[TMP5:%.*]] = add <8 x i1> [[TMP0]], [[TMP3]]
14-
; CHECK-NEXT: [[TMP6:%.*]] = shufflevector <8 x i1> [[TMP4]], <8 x i1> [[TMP5]], <8 x i32> <i32 0, i32 1, i32 2, i32 3, i32 12, i32 13, i32 14, i32 15>
15-
; CHECK-NEXT: [[TMP7:%.*]] = or <8 x i1> [[TMP6]], zeroinitializer
16-
; CHECK-NEXT: [[TMP8:%.*]] = zext <8 x i1> [[TMP7]] to <8 x i16>
17-
; CHECK-NEXT: store <8 x i16> [[TMP8]], ptr [[ARRAYIDX2]], align 2
8+
; CHECK-NEXT: store <8 x i16> zeroinitializer, ptr [[ARRAYIDX2]], align 2
189
; CHECK-NEXT: ret void
1910
;
2011
entry:

0 commit comments

Comments
 (0)