mirror of
https://github.com/RPCSX/llvm.git
synced 2024-12-11 21:57:55 +00:00
[InstCombine] fix formatting of FoldOpIntoSelect(); NFCI
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@286604 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
2104040e03
commit
d78e6da29d
@ -783,51 +783,53 @@ static Value *FoldOperationIntoSelectOperand(Instruction &I, Value *SO,
|
||||
/// This also works for Cast instructions, which obviously do not have a second
|
||||
/// operand.
|
||||
Instruction *InstCombiner::FoldOpIntoSelect(Instruction &Op, SelectInst *SI) {
|
||||
// Don't modify shared select instructions
|
||||
if (!SI->hasOneUse()) return nullptr;
|
||||
Value *TV = SI->getOperand(1);
|
||||
Value *FV = SI->getOperand(2);
|
||||
// Don't modify shared select instructions.
|
||||
if (!SI->hasOneUse())
|
||||
return nullptr;
|
||||
|
||||
if (isa<Constant>(TV) || isa<Constant>(FV)) {
|
||||
// Bool selects with constant operands can be folded to logical ops.
|
||||
if (SI->getType()->getScalarType()->isIntegerTy(1)) return nullptr;
|
||||
Value *TV = SI->getTrueValue();
|
||||
Value *FV = SI->getFalseValue();
|
||||
if (!(isa<Constant>(TV) || isa<Constant>(FV)))
|
||||
return nullptr;
|
||||
|
||||
// If it's a bitcast involving vectors, make sure it has the same number of
|
||||
// elements on both sides.
|
||||
if (BitCastInst *BC = dyn_cast<BitCastInst>(&Op)) {
|
||||
VectorType *DestTy = dyn_cast<VectorType>(BC->getDestTy());
|
||||
VectorType *SrcTy = dyn_cast<VectorType>(BC->getSrcTy());
|
||||
// Bool selects with constant operands can be folded to logical ops.
|
||||
if (SI->getType()->getScalarType()->isIntegerTy(1))
|
||||
return nullptr;
|
||||
|
||||
// Verify that either both or neither are vectors.
|
||||
if ((SrcTy == nullptr) != (DestTy == nullptr)) return nullptr;
|
||||
// If vectors, verify that they have the same number of elements.
|
||||
if (SrcTy && SrcTy->getNumElements() != DestTy->getNumElements())
|
||||
// If it's a bitcast involving vectors, make sure it has the same number of
|
||||
// elements on both sides.
|
||||
if (auto *BC = dyn_cast<BitCastInst>(&Op)) {
|
||||
VectorType *DestTy = dyn_cast<VectorType>(BC->getDestTy());
|
||||
VectorType *SrcTy = dyn_cast<VectorType>(BC->getSrcTy());
|
||||
|
||||
// Verify that either both or neither are vectors.
|
||||
if ((SrcTy == nullptr) != (DestTy == nullptr))
|
||||
return nullptr;
|
||||
|
||||
// If vectors, verify that they have the same number of elements.
|
||||
if (SrcTy && SrcTy->getNumElements() != DestTy->getNumElements())
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// Test if a CmpInst instruction is used exclusively by a select as
|
||||
// part of a minimum or maximum operation. If so, refrain from doing
|
||||
// any other folding. This helps out other analyses which understand
|
||||
// non-obfuscated minimum and maximum idioms, such as ScalarEvolution
|
||||
// and CodeGen. And in this case, at least one of the comparison
|
||||
// operands has at least one user besides the compare (the select),
|
||||
// which would often largely negate the benefit of folding anyway.
|
||||
if (auto *CI = dyn_cast<CmpInst>(SI->getCondition())) {
|
||||
if (CI->hasOneUse()) {
|
||||
Value *Op0 = CI->getOperand(0), *Op1 = CI->getOperand(1);
|
||||
if ((SI->getOperand(1) == Op0 && SI->getOperand(2) == Op1) ||
|
||||
(SI->getOperand(2) == Op0 && SI->getOperand(1) == Op1))
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// Test if a CmpInst instruction is used exclusively by a select as
|
||||
// part of a minimum or maximum operation. If so, refrain from doing
|
||||
// any other folding. This helps out other analyses which understand
|
||||
// non-obfuscated minimum and maximum idioms, such as ScalarEvolution
|
||||
// and CodeGen. And in this case, at least one of the comparison
|
||||
// operands has at least one user besides the compare (the select),
|
||||
// which would often largely negate the benefit of folding anyway.
|
||||
if (auto *CI = dyn_cast<CmpInst>(SI->getCondition())) {
|
||||
if (CI->hasOneUse()) {
|
||||
Value *Op0 = CI->getOperand(0), *Op1 = CI->getOperand(1);
|
||||
if ((SI->getOperand(1) == Op0 && SI->getOperand(2) == Op1) ||
|
||||
(SI->getOperand(2) == Op0 && SI->getOperand(1) == Op1))
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
Value *SelectTrueVal = FoldOperationIntoSelectOperand(Op, TV, this);
|
||||
Value *SelectFalseVal = FoldOperationIntoSelectOperand(Op, FV, this);
|
||||
|
||||
return SelectInst::Create(SI->getCondition(),
|
||||
SelectTrueVal, SelectFalseVal);
|
||||
}
|
||||
return nullptr;
|
||||
|
||||
Value *SelectTVal = FoldOperationIntoSelectOperand(Op, TV, this);
|
||||
Value *SelectFVal = FoldOperationIntoSelectOperand(Op, FV, this);
|
||||
return SelectInst::Create(SI->getCondition(), SelectTVal, SelectFVal);
|
||||
}
|
||||
|
||||
/// Given a binary operator, cast instruction, or select which has a PHI node as
|
||||
|
Loading…
Reference in New Issue
Block a user