[llvm] r332375 - [InstCombine] fix binop-of-shuffles to check uses
Sanjay Patel via llvm-commits
llvm-commits at lists.llvm.org
Tue May 15 10:14:23 PDT 2018
Author: spatel
Date: Tue May 15 10:14:23 2018
New Revision: 332375
URL: http://llvm.org/viewvc/llvm-project?rev=332375&view=rev
Log:
[InstCombine] fix binop-of-shuffles to check uses
Modified:
llvm/trunk/lib/Transforms/InstCombine/InstructionCombining.cpp
llvm/trunk/test/Transforms/InstCombine/vec_shuffle.ll
Modified: llvm/trunk/lib/Transforms/InstCombine/InstructionCombining.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstructionCombining.cpp?rev=332375&r1=332374&r2=332375&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstructionCombining.cpp (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstructionCombining.cpp Tue May 15 10:14:23 2018
@@ -1381,18 +1381,16 @@ Value *InstCombiner::SimplifyVectorOp(Bi
assert(cast<VectorType>(RHS->getType())->getNumElements() == VWidth);
// If both arguments of the binary operation are shuffles that use the same
- // mask and shuffle within a single vector, move the shuffle after the binop:
- // Op(shuffle(v1, m), shuffle(v2, m)) -> shuffle(Op(v1, v2), m)
- auto *LShuf = dyn_cast<ShuffleVectorInst>(LHS);
- auto *RShuf = dyn_cast<ShuffleVectorInst>(RHS);
- if (LShuf && RShuf && LShuf->getMask() == RShuf->getMask() &&
- isa<UndefValue>(LShuf->getOperand(1)) &&
- isa<UndefValue>(RShuf->getOperand(1)) &&
- LShuf->getOperand(0)->getType() == RShuf->getOperand(0)->getType()) {
- Value *NewBO = CreateBinOpAsGiven(Inst, LShuf->getOperand(0),
- RShuf->getOperand(0), Builder);
- return Builder.CreateShuffleVector(
- NewBO, UndefValue::get(NewBO->getType()), LShuf->getMask());
+ // mask and shuffle within a single vector, move the shuffle after the binop.
+ Value *V1, *V2;
+ Constant *Mask;
+ if (match(LHS, m_ShuffleVector(m_Value(V1), m_Undef(), m_Constant(Mask))) &&
+ match(RHS, m_ShuffleVector(m_Value(V2), m_Undef(), m_Specific(Mask))) &&
+ V1->getType() == V2->getType() &&
+ (LHS->hasOneUse() || RHS->hasOneUse() || LHS == RHS)) {
+ // Op(shuffle(V1, Mask), shuffle(V2, Mask)) -> shuffle(Op(V1, V2), Mask)
+ Value *B = CreateBinOpAsGiven(Inst, V1, V2, Builder);
+ return Builder.CreateShuffleVector(B, UndefValue::get(V1->getType()), Mask);
}
// If one argument is a shuffle within one vector, the other is a constant,
Modified: llvm/trunk/test/Transforms/InstCombine/vec_shuffle.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/vec_shuffle.ll?rev=332375&r1=332374&r2=332375&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/vec_shuffle.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/vec_shuffle.ll Tue May 15 10:14:23 2018
@@ -331,17 +331,16 @@ define <2 x float> @shuffle_fdiv_multius
ret <2 x float> %r
}
-; FIXME: But 2 extra uses would require an extra instruction.
+; But 2 extra uses would require an extra instruction.
define <2 x float> @shuffle_fsub_multiuse(<2 x float> %v1, <2 x float> %v2) {
; CHECK-LABEL: @shuffle_fsub_multiuse(
; CHECK-NEXT: [[T1:%.*]] = shufflevector <2 x float> [[V1:%.*]], <2 x float> undef, <2 x i32> <i32 1, i32 0>
; CHECK-NEXT: [[T2:%.*]] = shufflevector <2 x float> [[V2:%.*]], <2 x float> undef, <2 x i32> <i32 1, i32 0>
-; CHECK-NEXT: [[TMP1:%.*]] = fsub <2 x float> [[V1]], [[V2]]
-; CHECK-NEXT: [[TMP2:%.*]] = shufflevector <2 x float> [[TMP1]], <2 x float> undef, <2 x i32> <i32 1, i32 0>
+; CHECK-NEXT: [[R:%.*]] = fsub <2 x float> [[T1]], [[T2]]
; CHECK-NEXT: call void @use(<2 x float> [[T1]])
; CHECK-NEXT: call void @use(<2 x float> [[T2]])
-; CHECK-NEXT: ret <2 x float> [[TMP2]]
+; CHECK-NEXT: ret <2 x float> [[R]]
;
%t1 = shufflevector <2 x float> %v1, <2 x float> undef, <2 x i32> <i32 1, i32 0>
%t2 = shufflevector <2 x float> %v2, <2 x float> undef, <2 x i32> <i32 1, i32 0>
More information about the llvm-commits
mailing list