[PATCH] D34862: [CGP] Relax a bit restriction for optimizeMemoryInst to extend scope

Serguei Katkov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 10 23:25:13 PDT 2017


This revision was automatically updated to reflect the committed changes.
Closed by commit rL307628: [CGP] Relax a bit restriction for optimizeMemoryInst to extend scope (authored by skatkov).

Changed prior to commit:
  https://reviews.llvm.org/D34862?vs=105819&id=105966#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D34862

Files:
  llvm/trunk/lib/CodeGen/CodeGenPrepare.cpp
  llvm/trunk/test/CodeGen/X86/sink-gep-before-mem-inst.ll


Index: llvm/trunk/test/CodeGen/X86/sink-gep-before-mem-inst.ll
===================================================================
--- llvm/trunk/test/CodeGen/X86/sink-gep-before-mem-inst.ll
+++ llvm/trunk/test/CodeGen/X86/sink-gep-before-mem-inst.ll
@@ -0,0 +1,25 @@
+; RUN: opt < %s -S -codegenprepare -mtriple=x86_64-unknown-linux-gnu | FileCheck %s
+
+define i64 @test.after(i8 addrspace(1)* readonly align 8) {
+; CHECK-LABEL: test.after
+; CHECK: sunkaddr
+entry:
+  %.0 = getelementptr inbounds i8, i8 addrspace(1)* %0, i64 8
+  %addr = bitcast i8 addrspace(1)* %.0 to i32 addrspace(1)*
+  br label %header
+
+header:
+  %addr.in.loop = phi i32 addrspace(1)* [ %addr, %entry ], [ %addr.after, %header ]
+  %local_2_ = phi i64 [ 0, %entry ], [ %.9, %header ]
+  %.7 = load i32, i32 addrspace(1)* %addr.in.loop, align 8
+  fence acquire
+  %.1 = getelementptr inbounds i8, i8 addrspace(1)* %0, i64 8
+  %addr.after = bitcast i8 addrspace(1)* %.1 to i32 addrspace(1)*
+  %.8 = sext i32 %.7 to i64
+  %.9 = add i64 %local_2_, %.8
+  %not. = icmp sgt i64 %.9, 999
+  br i1 %not., label %exit, label %header
+
+exit:
+  ret i64 %.9
+}
Index: llvm/trunk/lib/CodeGen/CodeGenPrepare.cpp
===================================================================
--- llvm/trunk/lib/CodeGen/CodeGenPrepare.cpp
+++ llvm/trunk/lib/CodeGen/CodeGenPrepare.cpp
@@ -4270,6 +4270,7 @@
   Value *Consensus = nullptr;
   unsigned NumUsesConsensus = 0;
   bool IsNumUsesConsensusValid = false;
+  bool PhiSeen = false;
   SmallVector<Instruction*, 16> AddrModeInsts;
   ExtAddrMode AddrMode;
   TypePromotionTransaction TPT(RemovedInsts);
@@ -4289,6 +4290,7 @@
     if (PHINode *P = dyn_cast<PHINode>(V)) {
       for (Value *IncValue : P->incoming_values())
         worklist.push_back(IncValue);
+      PhiSeen = true;
       continue;
     }
 
@@ -4342,9 +4344,10 @@
   TPT.commit();
 
   // If all the instructions matched are already in this BB, don't do anything.
-  if (none_of(AddrModeInsts, [&](Value *V) {
+  // If we saw Phi node then it is not local definitely.
+  if (!PhiSeen && none_of(AddrModeInsts, [&](Value *V) {
         return IsNonLocalValue(V, MemoryInst->getParent());
-      })) {
+                  })) {
     DEBUG(dbgs() << "CGP: Found      local addrmode: " << AddrMode << "\n");
     return false;
   }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D34862.105966.patch
Type: text/x-patch
Size: 2312 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170711/8b1acccc/attachment.bin>


More information about the llvm-commits mailing list