summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSerguei Katkov <serguei.katkov@azul.com>2017-07-11 06:24:44 +0000
committerSerguei Katkov <serguei.katkov@azul.com>2017-07-11 06:24:44 +0000
commit0b7b59ada33abb48d5b992ddae0fc8ddca0232fa (patch)
tree91f73e71d5eaee09a4264e6411603d3e862feff1
parent3606ebf6d6fd9c6435686b2fbe021a2284ce9ef1 (diff)
downloadbcm5719-llvm-0b7b59ada33abb48d5b992ddae0fc8ddca0232fa.tar.gz
bcm5719-llvm-0b7b59ada33abb48d5b992ddae0fc8ddca0232fa.zip
[CGP] Relax a bit restriction for optimizeMemoryInst to extend scope
CodeGenPrepare::optimizeMemoryInst contains a check that we do nothing if all instructions combining the address for memory instruction is in the same block as memory instruction itself. However if any of these instruction are placed after memory instruction then address calculation will not be folded to memory instruction. The added test case shows an example. Reviewers: loladiro, spatel, efriedma Reviewed By: efriedma Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D34862 llvm-svn: 307628
-rw-r--r--llvm/lib/CodeGen/CodeGenPrepare.cpp7
-rw-r--r--llvm/test/CodeGen/X86/sink-gep-before-mem-inst.ll25
2 files changed, 30 insertions, 2 deletions
diff --git a/llvm/lib/CodeGen/CodeGenPrepare.cpp b/llvm/lib/CodeGen/CodeGenPrepare.cpp
index b50e76f2e3b..9351f2dd46b 100644
--- a/llvm/lib/CodeGen/CodeGenPrepare.cpp
+++ b/llvm/lib/CodeGen/CodeGenPrepare.cpp
@@ -4270,6 +4270,7 @@ bool CodeGenPrepare::optimizeMemoryInst(Instruction *MemoryInst, Value *Addr,
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 @@ bool CodeGenPrepare::optimizeMemoryInst(Instruction *MemoryInst, Value *Addr,
if (PHINode *P = dyn_cast<PHINode>(V)) {
for (Value *IncValue : P->incoming_values())
worklist.push_back(IncValue);
+ PhiSeen = true;
continue;
}
@@ -4342,9 +4344,10 @@ bool CodeGenPrepare::optimizeMemoryInst(Instruction *MemoryInst, Value *Addr,
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;
}
diff --git a/llvm/test/CodeGen/X86/sink-gep-before-mem-inst.ll b/llvm/test/CodeGen/X86/sink-gep-before-mem-inst.ll
new file mode 100644
index 00000000000..b9c94adda99
--- /dev/null
+++ b/llvm/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
+}
OpenPOWER on IntegriCloud