[PATCH] D126895: [SLP] Phi inputs that come from an unreachable block should be undef.
Vasileios Porpodas via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Jun 2 10:02:11 PDT 2022
vporpo created this revision.
vporpo added reviewers: ABataev, RKSimon, hvdijk.
Herald added a subscriber: hiraditya.
Herald added a project: All.
vporpo requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
Up until now when we generate a vector phi we create a poison value if the input
comes from a BB that is not reachable from the input.
For example:
bb1
%foo = ...
br bb2
unreachable_bb:
br bb2
bb2:
%phi0 = phi [%foo0, %bb1], [0, %unreachable_bb]
%phi1 = phi [%foo1, %bb1], [1, %unreachable_bb]
When we vectorize the phi, we are generating:
%vec_phi = phi [%vec_foo, %bb1], [ poison, %unreachable_bb ]
I think that this is incorrect, the input should be undef and not poison.
The value coming from an unreachable block from entry is uninitialized, which
IIUC is modeled by undef.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D126895
Files:
llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
llvm/test/Transforms/SLPVectorizer/X86/landing_pad.ll
llvm/test/Transforms/SLPVectorizer/X86/malformed_phis.ll
llvm/test/Transforms/SLPVectorizer/X86/phi-unreachable-input-block.ll
llvm/test/Transforms/SLPVectorizer/X86/reduction-same-vals.ll
llvm/test/Transforms/SLPVectorizer/X86/unreachable.ll
Index: llvm/test/Transforms/SLPVectorizer/X86/unreachable.ll
===================================================================
--- llvm/test/Transforms/SLPVectorizer/X86/unreachable.ll
+++ llvm/test/Transforms/SLPVectorizer/X86/unreachable.ll
@@ -15,7 +15,7 @@
; CHECK-NEXT: [[BAD:%.*]] = fadd float [[BAD]], 0.000000e+00
; CHECK-NEXT: br label [[BB2]]
; CHECK: bb2:
-; CHECK-NEXT: [[TMP0:%.*]] = phi <4 x i32> [ poison, [[BB1:%.*]] ], [ <i32 2, i32 2, i32 2, i32 2>, [[ENTRY:%.*]] ]
+; CHECK-NEXT: [[TMP0:%.*]] = phi <4 x i32> [ undef, [[BB1:%.*]] ], [ <i32 2, i32 2, i32 2, i32 2>, [[ENTRY:%.*]] ]
; CHECK-NEXT: [[TMP1:%.*]] = bitcast i32* [[X:%.*]] to <4 x i32>*
; CHECK-NEXT: store <4 x i32> [[TMP0]], <4 x i32>* [[TMP1]], align 4
; CHECK-NEXT: ret void
Index: llvm/test/Transforms/SLPVectorizer/X86/reduction-same-vals.ll
===================================================================
--- llvm/test/Transforms/SLPVectorizer/X86/reduction-same-vals.ll
+++ llvm/test/Transforms/SLPVectorizer/X86/reduction-same-vals.ll
@@ -8,7 +8,7 @@
; CHECK: bb2:
; CHECK-NEXT: br label [[BB3]]
; CHECK: bb3:
-; CHECK-NEXT: [[TMP0:%.*]] = phi <2 x i32> [ poison, [[BB2:%.*]] ], [ zeroinitializer, [[BB1:%.*]] ]
+; CHECK-NEXT: [[TMP0:%.*]] = phi <2 x i32> [ undef, [[BB2:%.*]] ], [ zeroinitializer, [[BB1:%.*]] ]
; CHECK-NEXT: [[SHUFFLE:%.*]] = shufflevector <2 x i32> [[TMP0]], <2 x i32> poison, <4 x i32> <i32 0, i32 0, i32 0, i32 1>
; CHECK-NEXT: [[TMP1:%.*]] = shufflevector <2 x i32> [[TMP0]], <2 x i32> poison, <8 x i32> zeroinitializer
; CHECK-NEXT: [[TMP2:%.*]] = call i32 @llvm.vector.reduce.mul.v8i32(<8 x i32> [[TMP1]])
Index: llvm/test/Transforms/SLPVectorizer/X86/phi-unreachable-input-block.ll
===================================================================
--- llvm/test/Transforms/SLPVectorizer/X86/phi-unreachable-input-block.ll
+++ llvm/test/Transforms/SLPVectorizer/X86/phi-unreachable-input-block.ll
@@ -15,7 +15,7 @@
; CHECK: bb2:
; CHECK-NEXT: br label [[BB3]]
; CHECK: bb3:
-; CHECK-NEXT: [[TMP2:%.*]] = phi <2 x i8> [ [[TMP1]], [[BB1:%.*]] ], [ poison, [[BB2:%.*]] ]
+; CHECK-NEXT: [[TMP2:%.*]] = phi <2 x i8> [ [[TMP1]], [[BB1:%.*]] ], [ undef, [[BB2:%.*]] ]
; CHECK-NEXT: [[TMP3:%.*]] = zext <2 x i8> [[TMP2]] to <2 x i64>
; CHECK-NEXT: [[GEP0:%.*]] = getelementptr i64, i64* [[PTR:%.*]], i64 0
; CHECK-NEXT: [[TMP4:%.*]] = bitcast i64* [[GEP0]] to <2 x i64>*
@@ -50,7 +50,7 @@
; CHECK: bb2:
; CHECK-NEXT: br label [[BB3]]
; CHECK: bb3:
-; CHECK-NEXT: [[TMP2:%.*]] = phi <2 x i8> [ [[TMP1]], [[BB1:%.*]] ], [ poison, [[BB2:%.*]] ]
+; CHECK-NEXT: [[TMP2:%.*]] = phi <2 x i8> [ [[TMP1]], [[BB1:%.*]] ], [ undef, [[BB2:%.*]] ]
; CHECK-NEXT: [[TMP3:%.*]] = zext <2 x i8> [[TMP2]] to <2 x i64>
; CHECK-NEXT: [[GEP0:%.*]] = getelementptr i64, i64* [[PTR:%.*]], i64 0
; CHECK-NEXT: [[TMP4:%.*]] = bitcast i64* [[GEP0]] to <2 x i64>*
@@ -85,7 +85,7 @@
; CHECK: bb2:
; CHECK-NEXT: br label [[BB3]]
; CHECK: bb3:
-; CHECK-NEXT: [[TMP2:%.*]] = phi <2 x i8> [ [[TMP1]], [[BB1:%.*]] ], [ poison, [[BB2:%.*]] ]
+; CHECK-NEXT: [[TMP2:%.*]] = phi <2 x i8> [ [[TMP1]], [[BB1:%.*]] ], [ undef, [[BB2:%.*]] ]
; CHECK-NEXT: [[TMP3:%.*]] = zext <2 x i8> [[TMP2]] to <2 x i64>
; CHECK-NEXT: [[GEP0:%.*]] = getelementptr i64, i64* [[PTR:%.*]], i64 0
; CHECK-NEXT: [[TMP4:%.*]] = bitcast i64* [[GEP0]] to <2 x i64>*
Index: llvm/test/Transforms/SLPVectorizer/X86/malformed_phis.ll
===================================================================
--- llvm/test/Transforms/SLPVectorizer/X86/malformed_phis.ll
+++ llvm/test/Transforms/SLPVectorizer/X86/malformed_phis.ll
@@ -116,7 +116,7 @@
; CHECK: bb2:
; CHECK-NEXT: br label [[BB3]]
; CHECK: bb3:
-; CHECK-NEXT: [[TMP0:%.*]] = phi <2 x i32> [ undef, [[BB1]] ], [ poison, [[BB2:%.*]] ]
+; CHECK-NEXT: [[TMP0:%.*]] = phi <2 x i32> [ undef, [[BB1]] ], [ undef, [[BB2:%.*]] ]
; CHECK-NEXT: [[SHUFFLE:%.*]] = shufflevector <2 x i32> [[TMP0]], <2 x i32> poison, <8 x i32> <i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 1>
; CHECK-NEXT: [[TMP1:%.*]] = extractelement <8 x i32> [[SHUFFLE]], i32 0
; CHECK-NEXT: [[TMP2:%.*]] = insertelement <16 x i32> poison, i32 [[TMP1]], i32 0
Index: llvm/test/Transforms/SLPVectorizer/X86/landing_pad.ll
===================================================================
--- llvm/test/Transforms/SLPVectorizer/X86/landing_pad.ll
+++ llvm/test/Transforms/SLPVectorizer/X86/landing_pad.ll
@@ -10,7 +10,7 @@
; CHECK: bb2.loopexit:
; CHECK-NEXT: br label [[BB2:%.*]]
; CHECK: bb2:
-; CHECK-NEXT: [[TMP0:%.*]] = phi <4 x i32> [ [[SHUFFLE:%.*]], [[BB9:%.*]] ], [ poison, [[BB2_LOOPEXIT:%.*]] ]
+; CHECK-NEXT: [[TMP0:%.*]] = phi <4 x i32> [ [[SHUFFLE:%.*]], [[BB9:%.*]] ], [ undef, [[BB2_LOOPEXIT:%.*]] ]
; CHECK-NEXT: ret void
; CHECK: bb3:
; CHECK-NEXT: [[TMP1:%.*]] = phi <2 x i32> [ [[TMP5:%.*]], [[BB6:%.*]] ], [ poison, [[BB1:%.*]] ]
Index: llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
===================================================================
--- llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
+++ llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
@@ -4751,7 +4751,7 @@
SmallVector<ValueList, 2> OperandsVec;
for (unsigned I = 0, E = PH->getNumIncomingValues(); I < E; ++I) {
if (!DT->isReachableFromEntry(PH->getIncomingBlock(I))) {
- ValueList Operands(VL.size(), PoisonValue::get(PH->getType()));
+ ValueList Operands(VL.size(), UndefValue::get(PH->getType()));
TE->setOperand(I, Operands);
OperandsVec.push_back(Operands);
continue;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D126895.433783.patch
Type: text/x-patch
Size: 5763 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220602/59d69659/attachment.bin>
More information about the llvm-commits
mailing list