Skip to content

Commit af80d3a

Browse files
[SLP]Better sorting of phi instructions by comparing type sizes (#102188)
Currently SLP vectorizer compares phi instructions by the type id of the compared instructions, which may failed in case of different integer types, with the different sizes. Patch adds comparison by type sizes to fix this.
1 parent 94d5398 commit af80d3a

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18733,6 +18733,12 @@ bool SLPVectorizerPass::vectorizeChainsInBlock(BasicBlock *BB, BoUpSLP &R) {
1873318733
return true;
1873418734
if (V1->getType()->getTypeID() > V2->getType()->getTypeID())
1873518735
return false;
18736+
if (V1->getType()->getScalarSizeInBits() <
18737+
V2->getType()->getScalarSizeInBits())
18738+
return true;
18739+
if (V1->getType()->getScalarSizeInBits() >
18740+
V2->getType()->getScalarSizeInBits())
18741+
return false;
1873618742
ArrayRef<Value *> Opcodes1 = PHIToOpcodes[V1];
1873718743
ArrayRef<Value *> Opcodes2 = PHIToOpcodes[V2];
1873818744
if (Opcodes1.size() < Opcodes2.size())

llvm/test/Transforms/SLPVectorizer/X86/landing_pad.ll

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ define void @foo() personality ptr @bar {
1010
; CHECK: bb2.loopexit:
1111
; CHECK-NEXT: br label [[BB2:%.*]]
1212
; CHECK: bb2:
13-
; CHECK-NEXT: [[TMP0:%.*]] = phi <4 x i32> [ [[TMP8:%.*]], [[BB9:%.*]] ], [ poison, [[BB2_LOOPEXIT:%.*]] ]
13+
; CHECK-NEXT: [[TMP0:%.*]] = phi <4 x i32> [ [[TMP7:%.*]], [[BB9:%.*]] ], [ poison, [[BB2_LOOPEXIT:%.*]] ]
1414
; CHECK-NEXT: ret void
1515
; CHECK: bb3:
1616
; CHECK-NEXT: [[TMP1:%.*]] = phi <2 x i32> [ [[TMP3:%.*]], [[BB6:%.*]] ], [ poison, [[BB1:%.*]] ]
@@ -32,19 +32,18 @@ define void @foo() personality ptr @bar {
3232
; CHECK-NEXT: br i1 poison, label [[BB7]], label [[BB6]]
3333
; CHECK: bb9:
3434
; CHECK-NEXT: [[INDVARS_IV528799:%.*]] = phi i64 [ poison, [[BB10]] ], [ poison, [[BB12]] ]
35-
; CHECK-NEXT: [[TMP6:%.*]] = phi <2 x i32> [ [[TMP9:%.*]], [[BB10]] ], [ [[TMP10:%.*]], [[BB12]] ]
36-
; CHECK-NEXT: [[TMP7:%.*]] = shufflevector <2 x i32> [[TMP6]], <2 x i32> poison, <4 x i32> <i32 1, i32 0, i32 poison, i32 poison>
37-
; CHECK-NEXT: [[TMP8]] = shufflevector <4 x i32> [[TMP7]], <4 x i32> poison, <4 x i32> <i32 poison, i32 poison, i32 0, i32 1>
35+
; CHECK-NEXT: [[TMP6:%.*]] = phi <2 x i32> [ [[TMP8:%.*]], [[BB10]] ], [ [[TMP9:%.*]], [[BB12]] ]
36+
; CHECK-NEXT: [[TMP7]] = shufflevector <2 x i32> [[TMP6]], <2 x i32> poison, <4 x i32> <i32 poison, i32 poison, i32 1, i32 0>
3837
; CHECK-NEXT: br label [[BB2]]
3938
; CHECK: bb10:
40-
; CHECK-NEXT: [[TMP9]] = phi <2 x i32> [ [[TMP1]], [[BB3]] ]
39+
; CHECK-NEXT: [[TMP8]] = phi <2 x i32> [ [[TMP1]], [[BB3]] ]
4140
; CHECK-NEXT: [[LANDING_PAD68:%.*]] = landingpad { ptr, i32 }
4241
; CHECK-NEXT: cleanup
4342
; CHECK-NEXT: br label [[BB9]]
4443
; CHECK: bb11:
4544
; CHECK-NEXT: ret void
4645
; CHECK: bb12:
47-
; CHECK-NEXT: [[TMP10]] = phi <2 x i32> [ [[TMP4]], [[BB7]] ]
46+
; CHECK-NEXT: [[TMP9]] = phi <2 x i32> [ [[TMP4]], [[BB7]] ]
4847
; CHECK-NEXT: [[LANDING_PAD149:%.*]] = landingpad { ptr, i32 }
4948
; CHECK-NEXT: cleanup
5049
; CHECK-NEXT: br label [[BB9]]

0 commit comments

Comments
 (0)