diff options
author | Sanjay Patel <spatel@rotateright.com> | 2016-02-24 17:00:34 +0000 |
---|---|---|
committer | Sanjay Patel <spatel@rotateright.com> | 2016-02-24 17:00:34 +0000 |
commit | dbbaca0e1b5d9a6e36ffdf523c946f02fd6c2357 (patch) | |
tree | 741a19906b698d01bdee771f340c914e79e556ea /llvm/lib/Transforms | |
parent | b508f520e7711873e002d0679af2988c6e62f431 (diff) | |
download | bcm5719-llvm-dbbaca0e1b5d9a6e36ffdf523c946f02fd6c2357.tar.gz bcm5719-llvm-dbbaca0e1b5d9a6e36ffdf523c946f02fd6c2357.zip |
[InstCombine] enable optimization of casted vector xor instructions
This is part of the payoff for the refactoring in:
http://reviews.llvm.org/rL261649
http://reviews.llvm.org/rL261707
In addition to removing a pile of duplicated code, the xor case was
missing the optimization for vector types because it checked
"SrcTy->isIntegerTy()" rather than "SrcTy->isIntOrIntVectorTy()"
like 'and' and 'or' were already doing.
This solves part of:
https://llvm.org/bugs/show_bug.cgi?id=26702
llvm-svn: 261750
Diffstat (limited to 'llvm/lib/Transforms')
-rw-r--r-- | llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp | 26 |
1 files changed, 8 insertions, 18 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp b/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp index 8fe598d9b0e..d19a0226fbc 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp @@ -1245,7 +1245,8 @@ static Instruction *matchDeMorgansLaws(BinaryOperator &I, Instruction *InstCombiner::foldCastedBitwiseLogic(BinaryOperator &I) { auto LogicOpc = I.getOpcode(); - assert((LogicOpc == Instruction::And || LogicOpc == Instruction::Or) && + assert((LogicOpc == Instruction::And || LogicOpc == Instruction::Or || + LogicOpc == Instruction::Xor) && "Unexpected opcode for bitwise logic folding"); Value *Op0 = I.getOperand(0), *Op1 = I.getOperand(1); @@ -1277,6 +1278,10 @@ Instruction *InstCombiner::foldCastedBitwiseLogic(BinaryOperator &I) { return CastInst::Create(CastOpcode, NewOp, DestTy); } + // For now, only 'and'/'or' have optimizations after this. + if (LogicOpc == Instruction::Xor) + return nullptr; + // If this is logic(cast(icmp), cast(icmp)), try to fold this even if the // cast is otherwise not optimizable. This happens for vector sexts. ICmpInst *ICmp0 = dyn_cast<ICmpInst>(Cast0Src); @@ -2732,23 +2737,8 @@ Instruction *InstCombiner::visitXor(BinaryOperator &I) { } } - // fold (xor (cast A), (cast B)) -> (cast (xor A, B)) - if (CastInst *Op0C = dyn_cast<CastInst>(Op0)) { - if (CastInst *Op1C = dyn_cast<CastInst>(Op1)) - if (Op0C->getOpcode() == Op1C->getOpcode()) { // same cast kind? - Type *SrcTy = Op0C->getOperand(0)->getType(); - if (SrcTy == Op1C->getOperand(0)->getType() && SrcTy->isIntegerTy() && - // Only do this if the casts both really cause code to be generated. - ShouldOptimizeCast(Op0C->getOpcode(), Op0C->getOperand(0), - I.getType()) && - ShouldOptimizeCast(Op1C->getOpcode(), Op1C->getOperand(0), - I.getType())) { - Value *NewOp = Builder->CreateXor(Op0C->getOperand(0), - Op1C->getOperand(0), I.getName()); - return CastInst::Create(Op0C->getOpcode(), NewOp, I.getType()); - } - } - } + if (Instruction *CastedXor = foldCastedBitwiseLogic(I)) + return CastedXor; return Changed ? &I : nullptr; } |