[PATCH] D43758: [CGP] Fix the remove of matched phis in complex addressing mode

Serguei Katkov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Mar 11 20:54:02 PDT 2018


This revision was automatically updated to reflect the committed changes.
Closed by commit rL327250: [CGP] Fix the remove of matched phis in complex addressing mode (authored by skatkov, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D43758?vs=137328&id=137972#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D43758

Files:
  llvm/trunk/lib/CodeGen/CodeGenPrepare.cpp
  llvm/trunk/test/Transforms/CodeGenPrepare/X86/sink-addrmode-two-phi.ll


Index: llvm/trunk/test/Transforms/CodeGenPrepare/X86/sink-addrmode-two-phi.ll
===================================================================
--- llvm/trunk/test/Transforms/CodeGenPrepare/X86/sink-addrmode-two-phi.ll
+++ llvm/trunk/test/Transforms/CodeGenPrepare/X86/sink-addrmode-two-phi.ll
@@ -0,0 +1,27 @@
+; RUN: opt -S -codegenprepare -disable-complex-addr-modes=false  %s | FileCheck %s --check-prefix=CHECK
+target datalayout =
+"e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128"
+target triple = "x86_64-unknown-linux-gnu"
+
+define void @test() {
+entry:
+  %0 = getelementptr inbounds i64, i64 * null, i64 undef
+  br label %start
+
+start:
+  %val1 = phi i64 * [ %0, %entry ], [ %val4, %exit ]
+  %val2 = phi i64 * [ null, %entry ], [ %val5, %exit ]
+  br i1 false, label %slowpath, label %exit
+
+slowpath:
+  %elem1 = getelementptr inbounds i64, i64 * undef, i64 undef
+  br label %exit
+
+exit:
+; CHECK: sunkaddr
+  %val3 = phi i64 * [ undef, %slowpath ], [ %val2, %start ]
+  %val4 = phi i64 * [ %elem1, %slowpath ], [ %val1, %start ]
+  %val5 = phi i64 * [ undef, %slowpath ], [ %val2, %start ]
+  %loadx = load i64, i64 * %val4, align 8
+  br label %start
+}
Index: llvm/trunk/lib/CodeGen/CodeGenPrepare.cpp
===================================================================
--- llvm/trunk/lib/CodeGen/CodeGenPrepare.cpp
+++ llvm/trunk/lib/CodeGen/CodeGenPrepare.cpp
@@ -2946,8 +2946,20 @@
         Matched.clear();
       }
       if (IsMatched) {
-        // Replace all matched values and erase them.
+        // If we matched phi node to different but identical phis then
+        // make a simplification here.
+        DenseMap<PHINode *, PHINode *> MatchedPHINodeMapping;
         for (auto MV : Matched) {
+          auto AlreadyMatched = MatchedPHINodeMapping.find(MV.first);
+          if (AlreadyMatched != MatchedPHINodeMapping.end()) {
+            MV.second->replaceAllUsesWith(AlreadyMatched->second);
+            ST.Put(MV.second, AlreadyMatched->second);
+            MV.second->eraseFromParent();
+          } else
+            MatchedPHINodeMapping.insert({ MV.first, MV.second });
+        }
+        // Replace all matched values and erase them.
+        for (auto MV : MatchedPHINodeMapping) {
           MV.first->replaceAllUsesWith(MV.second);
           PhiNodesToMatch.erase(MV.first);
           ST.Put(MV.first, MV.second);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D43758.137972.patch
Type: text/x-patch
Size: 2456 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180312/0d5279c1/attachment.bin>


More information about the llvm-commits mailing list