[llvm-branch-commits] [llvm] 7a0ee8a - [CodeGen] Fix incorrect insertion point selection for reduction nodes in ComplexDeinterleavingPass

Tobias Hieta via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Sun Sep 10 23:58:51 PDT 2023


Author: Igor Kirillov
Date: 2023-09-11T08:54:42+02:00
New Revision: 7a0ee8a81d86ce4ba73545e3367b10ab685185cb

URL: https://github.com/llvm/llvm-project/commit/7a0ee8a81d86ce4ba73545e3367b10ab685185cb
DIFF: https://github.com/llvm/llvm-project/commit/7a0ee8a81d86ce4ba73545e3367b10ab685185cb.diff

LOG: [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 https://github.com/llvm/llvm-project/issues/65044

Differential Revision: https://reviews.llvm.org/D159209

(cherry picked from commit e2cb07c322e85604dc48f9caec52b3570db0e1d8)

Added: 
    

Modified: 
    llvm/lib/CodeGen/ComplexDeinterleavingPass.cpp
    llvm/test/CodeGen/AArch64/complex-deinterleaving-crash.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/CodeGen/ComplexDeinterleavingPass.cpp b/llvm/lib/CodeGen/ComplexDeinterleavingPass.cpp
index 952f454f8f6a280..7979ac9a5fb7924 100644
--- a/llvm/lib/CodeGen/ComplexDeinterleavingPass.cpp
+++ b/llvm/lib/CodeGen/ComplexDeinterleavingPass.cpp
@@ -1424,7 +1424,17 @@ bool ComplexDeinterleavingGraph::identifyNodes(Instruction *RootI) {
   // CompositeNode we should choose only one either Real or Imag instruction to
   // use as an anchor for generating complex instruction.
   auto It = RootToNode.find(RootI);
-  if (It != RootToNode.end() && It->second->Real == RootI) {
+  if (It != RootToNode.end()) {
+    auto RootNode = It->second;
+    assert(RootNode->Operation ==
+           ComplexDeinterleavingOperation::ReductionOperation);
+    // Find out which part, Real or Imag, comes later, and only if we come to
+    // the latest part, add it to OrderedRoots.
+    auto *R = cast<Instruction>(RootNode->Real);
+    auto *I = cast<Instruction>(RootNode->Imag);
+    auto *ReplacementAnchor = R->comesBefore(I) ? I : R;
+    if (ReplacementAnchor != RootI)
+      return false;
     OrderedRoots.push_back(RootI);
     return true;
   }

diff  --git a/llvm/test/CodeGen/AArch64/complex-deinterleaving-crash.ll b/llvm/test/CodeGen/AArch64/complex-deinterleaving-crash.ll
index e2216f9ece6b9f1..68cb29f8f5c8f86 100644
--- a/llvm/test/CodeGen/AArch64/complex-deinterleaving-crash.ll
+++ b/llvm/test/CodeGen/AArch64/complex-deinterleaving-crash.ll
@@ -1,4 +1,4 @@
-; XFAIL: *
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 2
 ; RUN: llc %s --mattr=+complxnum -o - | FileCheck %s
 
 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"
@@ -6,6 +6,10 @@ target triple = "aarch64-none-linux-gnu"
 
 ; Check that deinterleaving pass doesn't generate broken IR
 define void @check_deinterleave_crash() #0 {
+; CHECK-LABEL: check_deinterleave_crash:
+; CHECK:       // %bb.0: // %bb
+; CHECK-NEXT:    mov x8, xzr
+; CHECK-NEXT:    str wzr, [x8]
 bb:
   br label %bb173
 


        


More information about the llvm-branch-commits mailing list