summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms/InstCombine
diff options
context:
space:
mode:
authorSanjay Patel <spatel@rotateright.com>2018-09-30 13:50:42 +0000
committerSanjay Patel <spatel@rotateright.com>2018-09-30 13:50:42 +0000
commit26c119a9c2f1d6866fe5996ef5a039b4fc3749ca (patch)
tree8caae0b7b55785ce1fd1fd5922fe0c360fb68734 /llvm/lib/Transforms/InstCombine
parent818cfc40ff464d426be37a552c3db8e895c94321 (diff)
downloadbcm5719-llvm-26c119a9c2f1d6866fe5996ef5a039b4fc3749ca.tar.gz
bcm5719-llvm-26c119a9c2f1d6866fe5996ef5a039b4fc3749ca.zip
[InstCombine] allow lengthening of insertelement to eliminate shuffles
As noted in post-commit comments for D52548, the limitation on increasing vector length can be applied by opcode. As a first step, this patch only allows insertelement to be widened because that has no logical downsides for IR and has little risk of pessimizing codegen. This may cause PR39132 to go into hiding during a full compile, but that bug is not fixed. llvm-svn: 343406
Diffstat (limited to 'llvm/lib/Transforms/InstCombine')
-rw-r--r--llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp10
1 files changed, 8 insertions, 2 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp b/llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp
index a87e323fd4b..c391034dc00 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp
@@ -918,6 +918,13 @@ static bool canEvaluateShuffled(Value *V, ArrayRef<int> Mask,
case Instruction::FPTrunc:
case Instruction::FPExt:
case Instruction::GetElementPtr: {
+ // Bail out if we would create longer vector ops. We could allow creating
+ // longer vector ops, but that may result in more expensive codegen. We
+ // would also need to limit the transform to avoid undefined behavior for
+ // integer div/rem.
+ Type *ITy = I->getType();
+ if (ITy->isVectorTy() && Mask.size() > ITy->getVectorNumElements())
+ return false;
for (Value *Operand : I->operands()) {
if (!canEvaluateShuffled(Operand, Mask, Depth - 1))
return false;
@@ -1464,8 +1471,7 @@ Instruction *InstCombiner::visitShuffleVectorInst(ShuffleVectorInst &SVI) {
if (isRHSID) return replaceInstUsesWith(SVI, RHS);
}
- if (isa<UndefValue>(RHS) && !SVI.increasesLength() &&
- canEvaluateShuffled(LHS, Mask)) {
+ if (isa<UndefValue>(RHS) && canEvaluateShuffled(LHS, Mask)) {
Value *V = evaluateInDifferentElementOrder(LHS, Mask);
return replaceInstUsesWith(SVI, V);
}
OpenPOWER on IntegriCloud