mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-02-27 17:31:33 +00:00
Implement select.ll:test[3-6]
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@12544 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
6d0996866c
commit
c32b30a429
@ -1994,14 +1994,42 @@ Instruction *InstCombiner::visitCastInst(CastInst &CI) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Instruction *InstCombiner::visitSelectInst(SelectInst &SI) {
|
Instruction *InstCombiner::visitSelectInst(SelectInst &SI) {
|
||||||
if (ConstantBool *C = dyn_cast<ConstantBool>(SI.getCondition()))
|
Value *CondVal = SI.getCondition();
|
||||||
|
Value *TrueVal = SI.getTrueValue();
|
||||||
|
Value *FalseVal = SI.getFalseValue();
|
||||||
|
|
||||||
|
// select true, X, Y -> X
|
||||||
|
// select false, X, Y -> Y
|
||||||
|
if (ConstantBool *C = dyn_cast<ConstantBool>(CondVal))
|
||||||
if (C == ConstantBool::True)
|
if (C == ConstantBool::True)
|
||||||
return ReplaceInstUsesWith(SI, SI.getTrueValue());
|
return ReplaceInstUsesWith(SI, TrueVal);
|
||||||
else {
|
else {
|
||||||
assert(C == ConstantBool::False);
|
assert(C == ConstantBool::False);
|
||||||
return ReplaceInstUsesWith(SI, SI.getFalseValue());
|
return ReplaceInstUsesWith(SI, FalseVal);
|
||||||
|
}
|
||||||
|
|
||||||
|
// select C, X, X -> X
|
||||||
|
if (TrueVal == FalseVal)
|
||||||
|
return ReplaceInstUsesWith(SI, TrueVal);
|
||||||
|
|
||||||
|
// Selecting between two constants?
|
||||||
|
if (Constant *TrueValC = dyn_cast<Constant>(TrueVal))
|
||||||
|
if (Constant *FalseValC = dyn_cast<Constant>(FalseVal)) {
|
||||||
|
if (SI.getType() == Type::BoolTy &&
|
||||||
|
isa<ConstantBool>(TrueValC) && isa<ConstantBool>(FalseValC)) {
|
||||||
|
// select C, true, false -> C
|
||||||
|
if (TrueValC == ConstantBool::True)
|
||||||
|
return ReplaceInstUsesWith(SI, CondVal);
|
||||||
|
// select C, false, true -> !C
|
||||||
|
return BinaryOperator::createNot(CondVal);
|
||||||
|
}
|
||||||
|
|
||||||
|
// If the true constant is a 1 and the false is a zero, turn this into a
|
||||||
|
// cast from bool.
|
||||||
|
if (FalseValC->isNullValue() && isa<ConstantInt>(TrueValC) &&
|
||||||
|
cast<ConstantInt>(TrueValC)->getRawValue() == 1)
|
||||||
|
return new CastInst(CondVal, SI.getType());
|
||||||
}
|
}
|
||||||
// Other transformations are possible!
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user