mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-08-22 10:29:35 +00:00
SLPVectorizer: Sink and enable CSE for ExtractElements.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@186145 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
ac226bbf45
commit
523cd85b50
@ -1320,6 +1320,9 @@ void BoUpSLP::vectorizeTree() {
|
|||||||
it != e; ++it) {
|
it != e; ++it) {
|
||||||
Value *Scalar = it->Scalar;
|
Value *Scalar = it->Scalar;
|
||||||
llvm::User *User = it->User;
|
llvm::User *User = it->User;
|
||||||
|
|
||||||
|
// Skip users that we already RAUW. This happens when one instruction
|
||||||
|
// has multiple uses of the same value.
|
||||||
if (std::find(Scalar->use_begin(), Scalar->use_end(), User) ==
|
if (std::find(Scalar->use_begin(), Scalar->use_end(), User) ==
|
||||||
Scalar->use_end())
|
Scalar->use_end())
|
||||||
continue;
|
continue;
|
||||||
@ -1337,8 +1340,18 @@ void BoUpSLP::vectorizeTree() {
|
|||||||
Instruction *Loc = 0;
|
Instruction *Loc = 0;
|
||||||
if (PHINode *PN = dyn_cast<PHINode>(Vec)) {
|
if (PHINode *PN = dyn_cast<PHINode>(Vec)) {
|
||||||
Loc = PN->getParent()->getFirstInsertionPt();
|
Loc = PN->getParent()->getFirstInsertionPt();
|
||||||
} else if (Instruction *Iv = dyn_cast<Instruction>(Vec)){
|
} else if (isa<Instruction>(Vec)){
|
||||||
Loc = ++((BasicBlock::iterator)*Iv);
|
if (PHINode *PH = dyn_cast<PHINode>(User)) {
|
||||||
|
for (int i = 0, e = PH->getNumIncomingValues(); i != e; ++i) {
|
||||||
|
if (PH->getIncomingValue(i) == Scalar) {
|
||||||
|
Loc = PH->getIncomingBlock(i)->getTerminator();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
assert(Loc && "Unable to find incoming value for the PHI");
|
||||||
|
} else {
|
||||||
|
Loc = cast<Instruction>(User);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
Loc = F->getEntryBlock().begin();
|
Loc = F->getEntryBlock().begin();
|
||||||
}
|
}
|
||||||
@ -1433,24 +1446,25 @@ void BoUpSLP::optimizeGatherSequence() {
|
|||||||
BasicBlock *BB = *I;
|
BasicBlock *BB = *I;
|
||||||
// For all instructions in the function:
|
// For all instructions in the function:
|
||||||
for (BasicBlock::iterator it = BB->begin(), e = BB->end(); it != e; ++it) {
|
for (BasicBlock::iterator it = BB->begin(), e = BB->end(); it != e; ++it) {
|
||||||
InsertElementInst *Insert = dyn_cast<InsertElementInst>(it);
|
Instruction *In = it;
|
||||||
if (!Insert || !GatherSeq.count(Insert))
|
if ((!isa<InsertElementInst>(In) && !isa<ExtractElementInst>(In)) ||
|
||||||
|
!GatherSeq.count(In))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// Check if we can replace this instruction with any of the
|
// Check if we can replace this instruction with any of the
|
||||||
// visited instructions.
|
// visited instructions.
|
||||||
for (SmallPtrSet<Instruction*, 16>::iterator v = Visited.begin(),
|
for (SmallPtrSet<Instruction*, 16>::iterator v = Visited.begin(),
|
||||||
ve = Visited.end(); v != ve; ++v) {
|
ve = Visited.end(); v != ve; ++v) {
|
||||||
if (Insert->isIdenticalTo(*v) &&
|
if (In->isIdenticalTo(*v) &&
|
||||||
DT->dominates((*v)->getParent(), Insert->getParent())) {
|
DT->dominates((*v)->getParent(), In->getParent())) {
|
||||||
Insert->replaceAllUsesWith(*v);
|
In->replaceAllUsesWith(*v);
|
||||||
ToRemove.push_back(Insert);
|
ToRemove.push_back(In);
|
||||||
Insert = 0;
|
In = 0;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (Insert)
|
if (In)
|
||||||
Visited.insert(Insert);
|
Visited.insert(In);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -51,8 +51,8 @@ entry:
|
|||||||
|
|
||||||
; CHECK: @extr_user
|
; CHECK: @extr_user
|
||||||
; CHECK: load <4 x i32>
|
; CHECK: load <4 x i32>
|
||||||
; CHECK-NEXT: extractelement <4 x i32>
|
|
||||||
; CHECK: store <4 x i32>
|
; CHECK: store <4 x i32>
|
||||||
|
; CHECK: extractelement <4 x i32>
|
||||||
; CHECK-NEXT: ret
|
; CHECK-NEXT: ret
|
||||||
define i32 @extr_user(i32* noalias nocapture %B, i32* noalias nocapture %A, i32 %n, i32 %m) {
|
define i32 @extr_user(i32* noalias nocapture %B, i32* noalias nocapture %A, i32 %n, i32 %m) {
|
||||||
entry:
|
entry:
|
||||||
@ -81,8 +81,8 @@ entry:
|
|||||||
; In this example we have an external user that is not the first element in the vector.
|
; In this example we have an external user that is not the first element in the vector.
|
||||||
; CHECK: @extr_user1
|
; CHECK: @extr_user1
|
||||||
; CHECK: load <4 x i32>
|
; CHECK: load <4 x i32>
|
||||||
; CHECK-NEXT: extractelement <4 x i32>
|
|
||||||
; CHECK: store <4 x i32>
|
; CHECK: store <4 x i32>
|
||||||
|
; CHECK: extractelement <4 x i32>
|
||||||
; CHECK-NEXT: ret
|
; CHECK-NEXT: ret
|
||||||
define i32 @extr_user1(i32* noalias nocapture %B, i32* noalias nocapture %A, i32 %n, i32 %m) {
|
define i32 @extr_user1(i32* noalias nocapture %B, i32* noalias nocapture %A, i32 %n, i32 %m) {
|
||||||
entry:
|
entry:
|
||||||
|
@ -26,9 +26,9 @@ target triple = "x86_64-apple-macosx10.8.0"
|
|||||||
;CHECK: phi <2 x double>
|
;CHECK: phi <2 x double>
|
||||||
;CHECK: fadd <2 x double>
|
;CHECK: fadd <2 x double>
|
||||||
;CHECK: fmul <2 x double>
|
;CHECK: fmul <2 x double>
|
||||||
;CHECK: extractelement <2 x double>
|
|
||||||
;CHECK: br
|
;CHECK: br
|
||||||
;CHECK: store <2 x double>
|
;CHECK: store <2 x double>
|
||||||
|
;CHECK: extractelement <2 x double>
|
||||||
;CHECK: ret double
|
;CHECK: ret double
|
||||||
|
|
||||||
define double @ext_user(double* noalias nocapture %B, double* noalias nocapture %A, i32 %n, i32 %m) {
|
define double @ext_user(double* noalias nocapture %B, double* noalias nocapture %A, i32 %n, i32 %m) {
|
||||||
|
@ -23,10 +23,10 @@ target triple = "i386-apple-macosx10.9.0"
|
|||||||
;CHECK: fmul <3 x float>
|
;CHECK: fmul <3 x float>
|
||||||
;CHECK: fadd <3 x float>
|
;CHECK: fadd <3 x float>
|
||||||
; At the moment we don't sink extractelements.
|
; At the moment we don't sink extractelements.
|
||||||
;CHECK: extractelement
|
|
||||||
;CHECK: extractelement
|
|
||||||
;CHECK: extractelement
|
|
||||||
;CHECK: br
|
;CHECK: br
|
||||||
|
;CHECK: extractelement
|
||||||
|
;CHECK: extractelement
|
||||||
|
;CHECK: extractelement
|
||||||
;CHECK: ret
|
;CHECK: ret
|
||||||
|
|
||||||
define float @foo(float* nocapture readonly %A) {
|
define float @foo(float* nocapture readonly %A) {
|
||||||
|
Loading…
Reference in New Issue
Block a user