summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
diff options
context:
space:
mode:
authorCraig Topper <craig.topper@intel.com>2017-07-03 05:54:15 +0000
committerCraig Topper <craig.topper@intel.com>2017-07-03 05:54:15 +0000
commit766ce6e9cfcfb78eb726499fa5e9775401ffb136 (patch)
tree7da72f70ddcbb6974600d8ea5d03413288ca11f7 /llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
parent1a79c38d5e2b9d90250596fdb9572e803bcd13b5 (diff)
downloadbcm5719-llvm-766ce6e9cfcfb78eb726499fa5e9775401ffb136.tar.gz
bcm5719-llvm-766ce6e9cfcfb78eb726499fa5e9775401ffb136.zip
[InstCombine] Support BITWISE_OP( BSWAP(x), CONSTANT ) -> BSWAP( BITWISE_OP(x, BSWAP(CONSTANT) ) ) for splat vectors.
llvm-svn: 307002
Diffstat (limited to 'llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp')
-rw-r--r--llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp30
1 files changed, 12 insertions, 18 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp b/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
index 5a73eb5cc2f..0f034107b3d 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
@@ -82,27 +82,21 @@ static Value *getFCmpValue(unsigned Code, Value *LHS, Value *RHS,
Value *InstCombiner::SimplifyBSwap(BinaryOperator &I) {
assert(I.isBitwiseLogicOp() && "Unexpected opcode for bswap simplifying");
- // TODO handle constant on one side with vectors.
- Value *OldLHS = I.getOperand(0);
- Value *OldRHS = I.getOperand(1);
- ConstantInt *ConstRHS = dyn_cast<ConstantInt>(OldRHS);
- IntrinsicInst *IntrLHS = dyn_cast<IntrinsicInst>(OldLHS);
- IntrinsicInst *IntrRHS = dyn_cast<IntrinsicInst>(OldRHS);
- bool IsBswapLHS = (IntrLHS && IntrLHS->getIntrinsicID() == Intrinsic::bswap);
- bool IsBswapRHS = (IntrRHS && IntrRHS->getIntrinsicID() == Intrinsic::bswap);
-
- if (!IsBswapLHS)
+ Value *NewLHS;
+ if (!match(I.getOperand(0), m_BSwap(m_Value(NewLHS))))
return nullptr;
- if (!IsBswapRHS && !ConstRHS)
- return nullptr;
-
- /// OP( BSWAP(x), BSWAP(y) ) -> BSWAP( OP(x, y) )
- /// OP( BSWAP(x), CONSTANT ) -> BSWAP( OP(x, BSWAP(CONSTANT) ) )
- Value *NewLHS = IntrLHS->getOperand(0);
+ Value *NewRHS;
+ const APInt *C;
- Value *NewRHS = IsBswapRHS ? IntrRHS->getOperand(0) :
- Builder->getInt(ConstRHS->getValue().byteSwap());
+ if (match(I.getOperand(1), m_BSwap(m_Value(NewRHS)))) {
+ // OP( BSWAP(x), BSWAP(y) ) -> BSWAP( OP(x, y) )
+ // NewRHS initialized by the matcher.
+ } else if (match(I.getOperand(1), m_APInt(C))) {
+ // OP( BSWAP(x), CONSTANT ) -> BSWAP( OP(x, BSWAP(CONSTANT) ) )
+ NewRHS = ConstantInt::get(I.getType(), C->byteSwap());
+ } else
+ return nullptr;
Value *BinOp = Builder->CreateBinOp(I.getOpcode(), NewLHS, NewRHS);
Function *F = Intrinsic::getDeclaration(I.getModule(), Intrinsic::bswap,
OpenPOWER on IntegriCloud