mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-02-10 04:33:40 +00:00
eliminate AssociativeOpt and its last uses.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@92697 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
a317e044fb
commit
dea34da6f8
@ -288,23 +288,6 @@ static Constant *SubOne(ConstantInt *C) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// AssociativeOpt - Perform an optimization on an associative operator. This
|
|
||||||
/// function is designed to check a chain of associative operators for a
|
|
||||||
/// potential to apply a certain optimization. Since the optimization may be
|
|
||||||
/// applicable if the expression was reassociated, this checks the chain, then
|
|
||||||
/// reassociates the expression as necessary to expose the optimization
|
|
||||||
/// opportunity. This makes use of a special Functor, which must define
|
|
||||||
/// 'shouldApply' and 'apply' methods.
|
|
||||||
///
|
|
||||||
template<typename Functor>
|
|
||||||
static Instruction *AssociativeOpt(BinaryOperator &Root, const Functor &F) {
|
|
||||||
// Quick check, see if the immediate LHS matches...
|
|
||||||
if (F.shouldApply(Root.getOperand(0)))
|
|
||||||
return F.apply(Root);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static Value *FoldOperationIntoSelectOperand(Instruction &I, Value *SO,
|
static Value *FoldOperationIntoSelectOperand(Instruction &I, Value *SO,
|
||||||
InstCombiner *IC) {
|
InstCombiner *IC) {
|
||||||
if (CastInst *CI = dyn_cast<CastInst>(&I))
|
if (CastInst *CI = dyn_cast<CastInst>(&I))
|
||||||
@ -2801,20 +2784,6 @@ Instruction *InstCombiner::visitOr(BinaryOperator &I) {
|
|||||||
return Changed ? &I : 0;
|
return Changed ? &I : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace {
|
|
||||||
|
|
||||||
// XorSelf - Implements: X ^ X --> 0
|
|
||||||
struct XorSelf {
|
|
||||||
Value *RHS;
|
|
||||||
XorSelf(Value *rhs) : RHS(rhs) {}
|
|
||||||
bool shouldApply(Value *LHS) const { return LHS == RHS; }
|
|
||||||
Instruction *apply(BinaryOperator &Xor) const {
|
|
||||||
return &Xor;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
Instruction *InstCombiner::visitXor(BinaryOperator &I) {
|
Instruction *InstCombiner::visitXor(BinaryOperator &I) {
|
||||||
bool Changed = SimplifyCommutative(I);
|
bool Changed = SimplifyCommutative(I);
|
||||||
Value *Op0 = I.getOperand(0), *Op1 = I.getOperand(1);
|
Value *Op0 = I.getOperand(0), *Op1 = I.getOperand(1);
|
||||||
@ -2827,11 +2796,9 @@ Instruction *InstCombiner::visitXor(BinaryOperator &I) {
|
|||||||
return ReplaceInstUsesWith(I, Op1); // X ^ undef -> undef
|
return ReplaceInstUsesWith(I, Op1); // X ^ undef -> undef
|
||||||
}
|
}
|
||||||
|
|
||||||
// xor X, X = 0, even if X is nested in a sequence of Xor's.
|
// xor X, X = 0
|
||||||
if (Instruction *Result = AssociativeOpt(I, XorSelf(Op1))) {
|
if (Op0 == Op1)
|
||||||
assert(Result == &I && "AssociativeOpt didn't work?"); Result=Result;
|
|
||||||
return ReplaceInstUsesWith(I, Constant::getNullValue(I.getType()));
|
return ReplaceInstUsesWith(I, Constant::getNullValue(I.getType()));
|
||||||
}
|
|
||||||
|
|
||||||
// See if we can simplify any instructions used by the instruction whose sole
|
// See if we can simplify any instructions used by the instruction whose sole
|
||||||
// purpose is to compute bits we don't care about.
|
// purpose is to compute bits we don't care about.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user