Skip to content

Commit e2cb07c

Browse files
committed
[CodeGen] Fix incorrect insertion point selection for reduction nodes in ComplexDeinterleavingPass
When replacing ComplexDeinterleavingPass::ReductionOperation, we can do it either from the Real or Imaginary part. The correct way is to take whichever is later in the BasicBlock, but before the patch, we just always took the Real part. Fixes llvm#65044 Differential Revision: https://reviews.llvm.org/D159209
1 parent 69f1cd5 commit e2cb07c

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

llvm/lib/CodeGen/ComplexDeinterleavingPass.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1424,7 +1424,17 @@ bool ComplexDeinterleavingGraph::identifyNodes(Instruction *RootI) {
14241424
// CompositeNode we should choose only one either Real or Imag instruction to
14251425
// use as an anchor for generating complex instruction.
14261426
auto It = RootToNode.find(RootI);
1427-
if (It != RootToNode.end() && It->second->Real == RootI) {
1427+
if (It != RootToNode.end()) {
1428+
auto RootNode = It->second;
1429+
assert(RootNode->Operation ==
1430+
ComplexDeinterleavingOperation::ReductionOperation);
1431+
// Find out which part, Real or Imag, comes later, and only if we come to
1432+
// the latest part, add it to OrderedRoots.
1433+
auto *R = cast<Instruction>(RootNode->Real);
1434+
auto *I = cast<Instruction>(RootNode->Imag);
1435+
auto *ReplacementAnchor = R->comesBefore(I) ? I : R;
1436+
if (ReplacementAnchor != RootI)
1437+
return false;
14281438
OrderedRoots.push_back(RootI);
14291439
return true;
14301440
}

llvm/test/CodeGen/AArch64/complex-deinterleaving-crash.ll

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
1-
; XFAIL: *
1+
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 2
22
; RUN: llc %s --mattr=+complxnum -o - | FileCheck %s
33

44
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"
55
target triple = "aarch64-none-linux-gnu"
66

77
; Check that deinterleaving pass doesn't generate broken IR
88
define void @check_deinterleave_crash() #0 {
9+
; CHECK-LABEL: check_deinterleave_crash:
10+
; CHECK: // %bb.0: // %bb
11+
; CHECK-NEXT: mov x8, xzr
12+
; CHECK-NEXT: str wzr, [x8]
913
bb:
1014
br label %bb173
1115

0 commit comments

Comments
 (0)