mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-07-18 10:24:45 +00:00
[InstCombine] Generalize sub of selects optimization to all BinaryOperators
This exposes further optimization opportunities if the selects are correlated. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@242235 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -623,6 +623,33 @@ Value *InstCombiner::SimplifyUsingDistributiveLaws(BinaryOperator &I) {
|
||||
}
|
||||
}
|
||||
|
||||
// (op (select (a, c, b)), (select (a, d, b))) -> (select (a, (op c, d), 0))
|
||||
// (op (select (a, b, c)), (select (a, b, d))) -> (select (a, 0, (op c, d)))
|
||||
if (auto *SI0 = dyn_cast<SelectInst>(LHS)) {
|
||||
if (auto *SI1 = dyn_cast<SelectInst>(RHS)) {
|
||||
if (SI0->getCondition() == SI1->getCondition()) {
|
||||
Value *SI = nullptr;
|
||||
if (Value *V = SimplifyBinOp(TopLevelOpcode, SI0->getFalseValue(),
|
||||
SI1->getFalseValue(), DL, TLI, DT, AC))
|
||||
SI = Builder->CreateSelect(SI0->getCondition(),
|
||||
Builder->CreateBinOp(TopLevelOpcode,
|
||||
SI0->getTrueValue(),
|
||||
SI1->getTrueValue()),
|
||||
V);
|
||||
if (Value *V = SimplifyBinOp(TopLevelOpcode, SI0->getTrueValue(),
|
||||
SI1->getTrueValue(), DL, TLI, DT, AC))
|
||||
SI = Builder->CreateSelect(
|
||||
SI0->getCondition(), V,
|
||||
Builder->CreateBinOp(TopLevelOpcode, SI0->getFalseValue(),
|
||||
SI1->getFalseValue()));
|
||||
if (SI) {
|
||||
SI->takeName(&I);
|
||||
return SI;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user