diff options
author | dim <dim@FreeBSD.org> | 2016-01-06 20:01:02 +0000 |
---|---|---|
committer | dim <dim@FreeBSD.org> | 2016-01-06 20:01:02 +0000 |
commit | ff2ba393a56d9d99dcb76ceada542233db28af9a (patch) | |
tree | ea70b740d40cffe568a990c7aecd1acb5f83f786 /lib/Transforms/InstCombine/InstCombineVectorOps.cpp | |
parent | 7c35321d839f2c4d0fc8510bfbd8954b07908b76 (diff) | |
download | FreeBSD-src-ff2ba393a56d9d99dcb76ceada542233db28af9a.zip FreeBSD-src-ff2ba393a56d9d99dcb76ceada542233db28af9a.tar.gz |
Vendor import of llvm trunk r256945:
https://llvm.org/svn/llvm-project/llvm/trunk@256945
Diffstat (limited to 'lib/Transforms/InstCombine/InstCombineVectorOps.cpp')
-rw-r--r-- | lib/Transforms/InstCombine/InstCombineVectorOps.cpp | 29 |
1 files changed, 21 insertions, 8 deletions
diff --git a/lib/Transforms/InstCombine/InstCombineVectorOps.cpp b/lib/Transforms/InstCombine/InstCombineVectorOps.cpp index e25639a..54a9fbd 100644 --- a/lib/Transforms/InstCombine/InstCombineVectorOps.cpp +++ b/lib/Transforms/InstCombine/InstCombineVectorOps.cpp @@ -383,15 +383,28 @@ static void replaceExtractElements(InsertElementInst *InsElt, auto *WideVec = new ShuffleVectorInst(ExtVecOp, UndefValue::get(ExtVecType), ConstantVector::get(ExtendMask)); - // Replace all extracts from the original narrow vector with extracts from - // the new wide vector. - WideVec->insertBefore(ExtElt); + // Insert the new shuffle after the vector operand of the extract is defined + // or at the start of the basic block, so any subsequent extracts can use it. + bool ReplaceAllExtUsers; + if (auto *ExtVecOpInst = dyn_cast<Instruction>(ExtVecOp)) { + WideVec->insertAfter(ExtVecOpInst); + ReplaceAllExtUsers = true; + } else { + // TODO: Insert at start of function, so it's always safe to replace all? + IC.InsertNewInstWith(WideVec, *ExtElt->getParent()->getFirstInsertionPt()); + ReplaceAllExtUsers = false; + } + + // Replace extracts from the original narrow vector with extracts from the new + // wide vector. for (User *U : ExtVecOp->users()) { - if (ExtractElementInst *OldExt = dyn_cast<ExtractElementInst>(U)) { - auto *NewExt = ExtractElementInst::Create(WideVec, OldExt->getOperand(1)); - NewExt->insertAfter(WideVec); - IC.ReplaceInstUsesWith(*OldExt, NewExt); - } + ExtractElementInst *OldExt = dyn_cast<ExtractElementInst>(U); + if (!OldExt || + (!ReplaceAllExtUsers && OldExt->getParent() != WideVec->getParent())) + continue; + auto *NewExt = ExtractElementInst::Create(WideVec, OldExt->getOperand(1)); + NewExt->insertAfter(WideVec); + IC.ReplaceInstUsesWith(*OldExt, NewExt); } } |