Skip to content

Commit f427890

Browse files
committed
[SLP]Fix PHI comparator to make it follow weak strict ordering restriction
Fixes llvm#137164
1 parent 10f6c3e commit f427890

File tree

2 files changed

+43
-1
lines changed

2 files changed

+43
-1
lines changed

llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23979,6 +23979,8 @@ bool SLPVectorizerPass::vectorizeChainsInBlock(BasicBlock *BB, BoUpSLP &R) {
2397923979
assert(isValidElementType(V1->getType()) &&
2398023980
isValidElementType(V2->getType()) &&
2398123981
"Expected vectorizable types only.");
23982+
if (V1 == V2)
23983+
return false;
2398223984
// It is fine to compare type IDs here, since we expect only vectorizable
2398323985
// types, like ints, floats and pointers, we don't care about other type.
2398423986
if (V1->getType()->getTypeID() < V2->getType()->getTypeID())
@@ -24015,7 +24017,7 @@ bool SLPVectorizerPass::vectorizeChainsInBlock(BasicBlock *BB, BoUpSLP &R) {
2401524017
if (NodeI1 != NodeI2)
2401624018
return NodeI1->getDFSNumIn() < NodeI2->getDFSNumIn();
2401724019
InstructionsState S = getSameOpcode({I1, I2}, *TLI);
24018-
if (S && !S.isAltShuffle()) {
24020+
if (S && !S.isAltShuffle() && I1->getOpcode() == I2->getOpcode()) {
2401924021
const auto *E1 = dyn_cast<ExtractElementInst>(I1);
2402024022
const auto *E2 = dyn_cast<ExtractElementInst>(I2);
2402124023
if (!E1 || !E2)
@@ -24047,6 +24049,8 @@ bool SLPVectorizerPass::vectorizeChainsInBlock(BasicBlock *BB, BoUpSLP &R) {
2404724049

2404824050
continue;
2404924051
}
24052+
if (I1->getOpcode() == I2->getOpcode())
24053+
continue;
2405024054
return I1->getOpcode() < I2->getOpcode();
2405124055
}
2405224056
if (I1)
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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(i32 %julianDay, i1 %cmp, i8 %0, i16 %1) {
5+
; CHECK-LABEL: define void @test(
6+
; CHECK-SAME: i32 [[JULIANDAY:%.*]], i1 [[CMP:%.*]], i8 [[TMP0:%.*]], i16 [[TMP1:%.*]]) {
7+
; CHECK-NEXT: [[ENTRY:.*]]:
8+
; CHECK-NEXT: br i1 [[CMP]], label %[[IF_THEN2:.*]], label %[[IF_END33:.*]]
9+
; CHECK: [[IF_THEN2]]:
10+
; CHECK-NEXT: [[CONV_I:%.*]] = sext i8 [[TMP0]] to i32
11+
; CHECK-NEXT: [[CONV_I2:%.*]] = sext i16 [[TMP1]] to i32
12+
; CHECK-NEXT: br label %[[IF_END33]]
13+
; CHECK: [[IF_END33]]:
14+
; CHECK-NEXT: [[MONTH_0:%.*]] = phi i32 [ [[CONV_I]], %[[IF_THEN2]] ], [ 0, %[[ENTRY]] ]
15+
; CHECK-NEXT: [[DAYOFMONTH_0:%.*]] = phi i32 [ [[CONV_I]], %[[IF_THEN2]] ], [ [[JULIANDAY]], %[[ENTRY]] ]
16+
; CHECK-NEXT: [[DAYOFYEAR_0:%.*]] = phi i32 [ [[CONV_I2]], %[[IF_THEN2]] ], [ 0, %[[ENTRY]] ]
17+
; CHECK-NEXT: store volatile i32 [[MONTH_0]], ptr null, align 4294967296
18+
; CHECK-NEXT: store volatile i32 [[DAYOFMONTH_0]], ptr null, align 4294967296
19+
; CHECK-NEXT: store volatile i32 [[DAYOFYEAR_0]], ptr null, align 4294967296
20+
; CHECK-NEXT: ret void
21+
;
22+
entry:
23+
br i1 %cmp, label %if.then2, label %if.end33
24+
25+
if.then2:
26+
%conv.i = sext i8 %0 to i32
27+
%conv.i2 = sext i16 %1 to i32
28+
br label %if.end33
29+
30+
if.end33:
31+
%month.0 = phi i32 [ %conv.i, %if.then2 ], [ 0, %entry ]
32+
%dayOfMonth.0 = phi i32 [ %conv.i, %if.then2 ], [ %julianDay, %entry ]
33+
%dayOfYear.0 = phi i32 [ %conv.i2, %if.then2 ], [ 0, %entry ]
34+
store volatile i32 %month.0, ptr null, align 4294967296
35+
store volatile i32 %dayOfMonth.0, ptr null, align 4294967296
36+
store volatile i32 %dayOfYear.0, ptr null, align 4294967296
37+
ret void
38+
}

0 commit comments

Comments
 (0)