[PATCH] D154598: [CodeGen] Fix incorrectly detected reduction bug in ComplexDeinterleaving pass
Igor Kirillov via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Jul 6 05:08:56 PDT 2023
igor.kirillov created this revision.
Herald added subscribers: mgabka, hiraditya.
Herald added a project: All.
igor.kirillov requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
The bug was found after landing D153355 <https://reviews.llvm.org/D153355>
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D154598
Files:
llvm/lib/CodeGen/ComplexDeinterleavingPass.cpp
llvm/test/CodeGen/AArch64/complex-deinterleaving-reductions.ll
Index: llvm/test/CodeGen/AArch64/complex-deinterleaving-reductions.ll
===================================================================
--- llvm/test/CodeGen/AArch64/complex-deinterleaving-reductions.ll
+++ llvm/test/CodeGen/AArch64/complex-deinterleaving-reductions.ll
@@ -236,4 +236,35 @@
%.fca.0.1.insert = insertvalue %"struct.std::complex" %.fca.0.0.insert, double %18, 0, 1
ret %"struct.std::complex" %.fca.0.1.insert
}
+
+; The reduced bug from D153355. Shows that reduction was detected where it did not exist.
+define void @bug(i1 %exitcond.not) #0 {
+; CHECK-LABEL: bug:
+; CHECK: // %bb.0: // %entry
+; CHECK-NEXT: .LBB3_1: // %for.body
+; CHECK-NEXT: // =>This Inner Loop Header: Depth=1
+; CHECK-NEXT: tbz w0, #0, .LBB3_1
+; CHECK-NEXT: // %bb.2: // %for.end.loopexit
+; CHECK-NEXT: ret
+entry:
+ br label %for.body
+
+for.body: ; preds = %for.body, %entry
+ %vec_r.0190 = phi <4 x float> [ zeroinitializer, %entry ], [ %lane62, %for.body ]
+ %vec_b.0188 = phi <4 x float> [ zeroinitializer, %entry ], [ %lane76, %for.body ]
+ %add.i175 = fadd <4 x float> %vec_b.0188, %vec_r.0190
+ %vmax2.i = tail call <4 x float> @llvm.aarch64.neon.fmax.v4f32(<4 x float> zeroinitializer, <4 x float> %add.i175)
+ %vmin2.i = tail call <4 x float> @llvm.aarch64.neon.fmin.v4f32(<4 x float> zeroinitializer, <4 x float> %add.i175)
+ %lane62 = shufflevector <4 x float> zeroinitializer, <4 x float> zeroinitializer, <4 x i32> zeroinitializer
+ %lane76 = shufflevector <4 x float> zeroinitializer, <4 x float> zeroinitializer, <4 x i32> zeroinitializer
+ br i1 %exitcond.not, label %for.end.loopexit, label %for.body
+
+for.end.loopexit: ; preds = %for.body
+ %mul.i177 = fmul <4 x float> %lane62, zeroinitializer
+ %mul.i179 = fmul <4 x float> %lane76, zeroinitializer
+ ret void
+}
+
declare double @llvm.vector.reduce.fadd.v2f64(double, <2 x double>)
+declare <4 x float> @llvm.aarch64.neon.fmax.v4f32(<4 x float>, <4 x float>)
+declare <4 x float> @llvm.aarch64.neon.fmin.v4f32(<4 x float>, <4 x float>)
Index: llvm/lib/CodeGen/ComplexDeinterleavingPass.cpp
===================================================================
--- llvm/lib/CodeGen/ComplexDeinterleavingPass.cpp
+++ llvm/lib/CodeGen/ComplexDeinterleavingPass.cpp
@@ -261,6 +261,10 @@
PHINode *RealPHI = nullptr;
PHINode *ImagPHI = nullptr;
+ /// Set this flag to true if RealPHI and ImagPHI were reached during reduction
+ /// detection.
+ bool PHIsFound = false;
+
/// OldToNewPHI maps the original real PHINode to a new, double-sized PHINode.
/// The new PHINode corresponds to a vector of deinterleaved complex numbers.
/// This mapping is populated during
@@ -1419,7 +1423,8 @@
FinalReduction = dyn_cast<Instruction>(U);
}
- if (NumUsers != 2 || !FinalReduction || FinalReduction->getParent() == B)
+ if (NumUsers != 2 || !FinalReduction || FinalReduction->getParent() == B ||
+ isa<PHINode>(FinalReduction))
continue;
ReductionInfo[ReductionOp] = {&PHI, FinalReduction};
@@ -1460,6 +1465,7 @@
RealPHI = ReductionInfo[Real].first;
ImagPHI = ReductionInfo[Imag].first;
+ PHIsFound = false;
auto Node = identifyNode(Real, Imag);
if (!Node) {
std::swap(Real, Imag);
@@ -1467,9 +1473,10 @@
Node = identifyNode(Real, Imag);
}
- // If a node is identified, mark its operation instructions as used to
- // prevent re-identification and attach the node to the real part
- if (Node) {
+ // If a node is identified and reduction PHINode is used in the chain of
+ // operations, mark its operation instructions as used to prevent
+ // re-identification and attach the node to the real part
+ if (Node && PHIsFound) {
LLVM_DEBUG(dbgs() << "Identified reduction starting from instructions: "
<< *Real << " / " << *Imag << "\n");
Processed[i] = true;
@@ -1762,6 +1769,7 @@
if (Real != RealPHI || Imag != ImagPHI)
return nullptr;
+ PHIsFound = true;
NodePtr PlaceholderNode = prepareCompositeNode(
ComplexDeinterleavingOperation::ReductionPHI, Real, Imag);
return submitCompositeNode(PlaceholderNode);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D154598.537669.patch
Type: text/x-patch
Size: 4293 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230706/e2e2c8bc/attachment.bin>
More information about the llvm-commits
mailing list