Skip to content

Commit 9400270

Browse files
committed
[SLP]Fix comparator for vector operands of extractelements in PHICompare
Need to make comparator to follow strict-weak ordering to fix compiler crashes. Fixes llvm#138178
1 parent 3a492ab commit 9400270

File tree

2 files changed

+63
-4
lines changed

2 files changed

+63
-4
lines changed

llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24069,10 +24069,23 @@ bool SLPVectorizerPass::vectorizeChainsInBlock(BasicBlock *BB, BoUpSLP &R) {
2406924069
const auto *V1 = dyn_cast<Instruction>(E1->getVectorOperand());
2407024070
const auto *V2 = dyn_cast<Instruction>(E2->getVectorOperand());
2407124071
if (V1 != V2) {
24072-
if (!V1 || !V2)
24073-
continue;
24074-
if (V1->getParent() != V2->getParent())
24075-
continue;
24072+
if (V1 && !V2)
24073+
return true;
24074+
if (!V1 && V2)
24075+
return false;
24076+
DomTreeNodeBase<BasicBlock> *NodeI1 =
24077+
DT->getNode(V1->getParent());
24078+
DomTreeNodeBase<BasicBlock> *NodeI2 =
24079+
DT->getNode(V2->getParent());
24080+
if (!NodeI1)
24081+
return NodeI2 != nullptr;
24082+
if (!NodeI2)
24083+
return false;
24084+
assert((NodeI1 == NodeI2) ==
24085+
(NodeI1->getDFSNumIn() == NodeI2->getDFSNumIn()) &&
24086+
"Different nodes should have different DFS numbers");
24087+
if (NodeI1 != NodeI2)
24088+
return NodeI1->getDFSNumIn() < NodeI2->getDFSNumIn();
2407624089
return V1->comesBefore(V2);
2407724090
}
2407824091
// If we have the same vector operand, try to sort by constant
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5
2+
; RUN: opt -S --passes=slp-vectorizer -mtriple=x86_64-unknown-linux-gnu < %s | FileCheck %s
3+
4+
define void @test({ <2 x float>, float } %0, <2 x float> %1, i1 %2) {
5+
; CHECK-LABEL: define void @test(
6+
; CHECK-SAME: { <2 x float>, float } [[TMP0:%.*]], <2 x float> [[TMP1:%.*]], i1 [[TMP2:%.*]]) {
7+
; CHECK-NEXT: [[TMP4:%.*]] = extractvalue { <2 x float>, float } [[TMP0]], 0
8+
; CHECK-NEXT: [[TMP5:%.*]] = extractelement <2 x float> [[TMP4]], i64 0
9+
; CHECK-NEXT: [[TMP6:%.*]] = extractelement <2 x float> [[TMP1]], i64 1
10+
; CHECK-NEXT: [[TMP7:%.*]] = extractelement <2 x float> [[TMP1]], i64 0
11+
; CHECK-NEXT: br i1 [[TMP2]], label %[[BB9:.*]], label %[[BB8:.*]]
12+
; CHECK: [[BB8]]:
13+
; CHECK-NEXT: br label %[[BB9]]
14+
; CHECK: [[BB9]]:
15+
; CHECK-NEXT: [[TMP10:%.*]] = phi float [ 0.000000e+00, %[[BB8]] ], [ [[TMP7]], [[TMP3:%.*]] ]
16+
; CHECK-NEXT: [[TMP11:%.*]] = phi float [ 0.000000e+00, %[[BB8]] ], [ [[TMP6]], [[TMP3]] ]
17+
; CHECK-NEXT: [[TMP12:%.*]] = phi float [ 0.000000e+00, %[[BB8]] ], [ [[TMP5]], [[TMP3]] ]
18+
; CHECK-NEXT: [[TMP13:%.*]] = fpext float [[TMP12]] to double
19+
; CHECK-NEXT: [[TMP14:%.*]] = fpext float [[TMP11]] to double
20+
; CHECK-NEXT: [[TMP15:%.*]] = tail call i32 (ptr, ptr, ...) @fprintf(ptr null, ptr null, double [[TMP13]], double [[TMP14]], double 0.000000e+00)
21+
; CHECK-NEXT: [[TMP16:%.*]] = fpext float [[TMP10]] to double
22+
; CHECK-NEXT: [[TMP17:%.*]] = tail call i32 (ptr, ptr, ...) @fprintf(ptr null, ptr null, double 0.000000e+00, double [[TMP16]], double 0.000000e+00)
23+
; CHECK-NEXT: ret void
24+
;
25+
%4 = extractvalue { <2 x float>, float } %0, 0
26+
%5 = extractelement <2 x float> %4, i64 0
27+
%6 = extractelement <2 x float> %1, i64 1
28+
%7 = extractelement <2 x float> %1, i64 0
29+
br i1 %2, label %9, label %8
30+
31+
8:
32+
br label %9
33+
34+
9:
35+
%10 = phi float [ 0.000000e+00, %8 ], [ %7, %3 ]
36+
%11 = phi float [ 0.000000e+00, %8 ], [ %6, %3 ]
37+
%12 = phi float [ 0.000000e+00, %8 ], [ %5, %3 ]
38+
%13 = fpext float %12 to double
39+
%14 = fpext float %11 to double
40+
%15 = tail call i32 (ptr, ptr, ...) @fprintf(ptr null, ptr null, double %13, double %14, double 0.000000e+00)
41+
%16 = fpext float %10 to double
42+
%17 = tail call i32 (ptr, ptr, ...) @fprintf(ptr null, ptr null, double 0.000000e+00, double %16, double 0.000000e+00)
43+
ret void
44+
}
45+
46+
declare i32 @fprintf(ptr, ptr, ...)

0 commit comments

Comments
 (0)