mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-07-15 19:24:33 +00:00
InstCombine: Combine select sequences into a single select
Normalize select(C0, select(C1, a, b), b) -> select((C0 & C1), a, b) select(C0, a, select(C1, a, b)) -> select((C0 | C1), a, b) This normal form may enable further combines on the And/Or and shortens paths for the values. Many targets prefer the other but can go back easily in CodeGen. Differential Revision: http://reviews.llvm.org/D7399 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@228409 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -1178,20 +1178,38 @@ Instruction *InstCombiner::visitSelectInst(SelectInst &SI) {
|
||||
return NV;
|
||||
|
||||
if (SelectInst *TrueSI = dyn_cast<SelectInst>(TrueVal)) {
|
||||
// select(C, select(C, a, b), c) -> select(C, a, c)
|
||||
if (TrueSI->getCondition() == CondVal) {
|
||||
if (SI.getTrueValue() == TrueSI->getTrueValue())
|
||||
return nullptr;
|
||||
SI.setOperand(1, TrueSI->getTrueValue());
|
||||
return &SI;
|
||||
}
|
||||
// select(C0, select(C1, a, b), b) -> select(C0&C1, a, b)
|
||||
// We choose this as normal form to enable folding on the And and shortening
|
||||
// paths for the values (this helps GetUnderlyingObjects() for example).
|
||||
if (TrueSI->getFalseValue() == FalseVal && TrueSI->hasOneUse()) {
|
||||
Value *And = Builder->CreateAnd(CondVal, TrueSI->getCondition());
|
||||
SI.setOperand(0, And);
|
||||
SI.setOperand(1, TrueSI->getTrueValue());
|
||||
return &SI;
|
||||
}
|
||||
}
|
||||
if (SelectInst *FalseSI = dyn_cast<SelectInst>(FalseVal)) {
|
||||
// select(C, a, select(C, b, c)) -> select(C, a, c)
|
||||
if (FalseSI->getCondition() == CondVal) {
|
||||
if (SI.getFalseValue() == FalseSI->getFalseValue())
|
||||
return nullptr;
|
||||
SI.setOperand(2, FalseSI->getFalseValue());
|
||||
return &SI;
|
||||
}
|
||||
// select(C0, a, select(C1, a, b)) -> select(C0|C1, a, b)
|
||||
if (FalseSI->getTrueValue() == TrueVal && FalseSI->hasOneUse()) {
|
||||
Value *Or = Builder->CreateOr(CondVal, FalseSI->getCondition());
|
||||
SI.setOperand(0, Or);
|
||||
SI.setOperand(2, FalseSI->getFalseValue());
|
||||
return &SI;
|
||||
}
|
||||
}
|
||||
|
||||
if (BinaryOperator::isNot(CondVal)) {
|
||||
|
Reference in New Issue
Block a user