Skip to content

Commit

Permalink
[InstCombine] use unary shuffle creator to reduce code duplication; NFC
Browse files Browse the repository at this point in the history
  • Loading branch information
rotateright committed Sep 21, 2020
1 parent be93505 commit 6bad3ca
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 7 deletions.
8 changes: 3 additions & 5 deletions llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp
Expand Up @@ -2075,9 +2075,8 @@ static Instruction *narrowVectorSelect(ShuffleVectorInst &Shuf,

// shuf (sel (shuf NarrowCond, undef, WideMask), X, Y), undef, NarrowMask) -->
// sel NarrowCond, (shuf X, undef, NarrowMask), (shuf Y, undef, NarrowMask)
Value *Undef = UndefValue::get(X->getType());
Value *NarrowX = Builder.CreateShuffleVector(X, Undef, Shuf.getShuffleMask());
Value *NarrowY = Builder.CreateShuffleVector(Y, Undef, Shuf.getShuffleMask());
Value *NarrowX = Builder.CreateShuffleVector(X, Shuf.getShuffleMask());
Value *NarrowY = Builder.CreateShuffleVector(Y, Shuf.getShuffleMask());
return SelectInst::Create(NarrowCond, NarrowX, NarrowY);
}

Expand Down Expand Up @@ -2444,8 +2443,7 @@ Instruction *InstCombinerImpl::visitShuffleVectorInst(ShuffleVectorInst &SVI) {
SmallVector<int, 16> ShuffleMask(SrcNumElems, -1);
for (unsigned I = 0, E = MaskElems, Idx = BegIdx; I != E; ++Idx, ++I)
ShuffleMask[I] = Idx;
V = Builder.CreateShuffleVector(V, UndefValue::get(V->getType()),
ShuffleMask,
V = Builder.CreateShuffleVector(V, ShuffleMask,
SVI.getName() + ".extract");
BegIdx = 0;
}
Expand Down
3 changes: 1 addition & 2 deletions llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
Expand Up @@ -1712,9 +1712,8 @@ Instruction *InstCombinerImpl::foldVectorBinop(BinaryOperator &Inst) {
// values followed by a splat followed by the 2nd binary operation:
// bo (splat X), (bo Y, OtherOp) --> bo (splat (bo X, Y)), OtherOp
Value *NewBO = Builder.CreateBinOp(Opcode, X, Y);
UndefValue *Undef = UndefValue::get(Inst.getType());
SmallVector<int, 8> NewMask(MaskC.size(), SplatIndex);
Value *NewSplat = Builder.CreateShuffleVector(NewBO, Undef, NewMask);
Value *NewSplat = Builder.CreateShuffleVector(NewBO, NewMask);
Instruction *R = BinaryOperator::Create(Opcode, NewSplat, OtherOp);

// Intersect FMF on both new binops. Other (poison-generating) flags are
Expand Down

0 comments on commit 6bad3ca

Please sign in to comment.