Skip to content

Commit 1b29435

Browse files
authored
[llvm] Fix crash caused by reprocessing complex reductions (#122077)
If a complex pattern had the shape of both a complex->complex reduction and a complex->single reduction, the matching would recognise both and deem the graph a valid transformation. Preventing this reprocessing results in only one of these matching, meaning that in the case of an invalid graph, we don't try to transform it anyway.
1 parent 4847395 commit 1b29435

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

llvm/lib/CodeGen/ComplexDeinterleavingPass.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1730,7 +1730,7 @@ void ComplexDeinterleavingGraph::identifyReductionNodes() {
17301730
auto *Real = OperationInstruction[i];
17311731
// We want to check that we have 2 operands, but the function attributes
17321732
// being counted as operands bloats this value.
1733-
if (Real->getNumOperands() < 2)
1733+
if (Processed[i] || Real->getNumOperands() < 2)
17341734
continue;
17351735

17361736
RealPHI = ReductionInfo[Real].first;
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5
2+
; RUN: opt -S --passes=complex-deinterleaving %s --mattr=+sve2 | FileCheck %s
3+
4+
target datalayout = "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128-ni:1-p2:32:8:8:32-ni:2"
5+
target triple = "aarch64-arm-none-linux"
6+
7+
; Ensure that a second reduction-like pattern doesn't override the first
8+
; We don't care what this IR produces, just that it produces something and doesn't cause a crash
9+
define void @reprocessing_crash() #0 {
10+
; CHECK-LABEL: define void @reprocessing_crash
11+
;
12+
entry:
13+
br label %vector.body
14+
15+
vector.body: ; preds = %vector.body, %entry
16+
%vec.phi18 = phi <vscale x 2 x double> [ zeroinitializer, %entry ], [ %2, %vector.body ]
17+
%vec.phi20 = phi <vscale x 2 x double> [ zeroinitializer, %entry ], [ %3, %vector.body ]
18+
%strided.vec22 = tail call { <vscale x 2 x double>, <vscale x 2 x double> } @llvm.vector.deinterleave2.nxv4f64(<vscale x 4 x double> zeroinitializer)
19+
%0 = extractvalue { <vscale x 2 x double>, <vscale x 2 x double> } %strided.vec22, 0
20+
%1 = extractvalue { <vscale x 2 x double>, <vscale x 2 x double> } %strided.vec22, 1
21+
%2 = fsub <vscale x 2 x double> %vec.phi18, %0
22+
%3 = fsub <vscale x 2 x double> %vec.phi20, %1
23+
br i1 false, label %middle.block, label %vector.body
24+
25+
middle.block: ; preds = %vector.body
26+
%bin.rdx = fadd <vscale x 2 x double> %2, zeroinitializer
27+
%bin.rdx23 = fadd <vscale x 2 x double> %3, zeroinitializer
28+
ret void
29+
}
30+
31+
; Function Attrs: nocallback nofree nosync nounwind willreturn memory(none)
32+
declare { <vscale x 2 x double>, <vscale x 2 x double> } @llvm.vector.deinterleave2.nxv4f64(<vscale x 4 x double>) #1
33+
34+
attributes #0 = { "target-cpu"="neoverse-v1" }
35+
attributes #1 = { nocallback nofree nosync nounwind willreturn memory(none) }

0 commit comments

Comments
 (0)