mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-11-01 00:17:01 +00:00
add a new SimplifyInstruction API, which is like ConstantFoldInstruction,
except that the result may not be a constant. Switch jump threading to use it so that it gets things like (X & 0) -> 0, which occur when phi preds are deleted and the remaining phi pred was a zero. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@86637 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -17,10 +17,10 @@
|
|||||||
#define LLVM_ANALYSIS_INSTRUCTIONSIMPLIFY_H
|
#define LLVM_ANALYSIS_INSTRUCTIONSIMPLIFY_H
|
||||||
|
|
||||||
namespace llvm {
|
namespace llvm {
|
||||||
|
class Instruction;
|
||||||
class Value;
|
class Value;
|
||||||
class TargetData;
|
class TargetData;
|
||||||
|
|
||||||
|
|
||||||
/// SimplifyAndInst - Given operands for an And, see if we can
|
/// SimplifyAndInst - Given operands for an And, see if we can
|
||||||
/// fold the result. If not, this returns null.
|
/// fold the result. If not, this returns null.
|
||||||
Value *SimplifyAndInst(Value *LHS, Value *RHS,
|
Value *SimplifyAndInst(Value *LHS, Value *RHS,
|
||||||
@@ -55,6 +55,10 @@ namespace llvm {
|
|||||||
Value *SimplifyBinOp(unsigned Opcode, Value *LHS, Value *RHS,
|
Value *SimplifyBinOp(unsigned Opcode, Value *LHS, Value *RHS,
|
||||||
const TargetData *TD = 0);
|
const TargetData *TD = 0);
|
||||||
|
|
||||||
|
/// SimplifyInstruction - See if we can compute a simplified version of this
|
||||||
|
/// instruction. If not, this returns null.
|
||||||
|
Value *SimplifyInstruction(Instruction *I, const TargetData *TD = 0);
|
||||||
|
|
||||||
} // end namespace llvm
|
} // end namespace llvm
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -291,3 +291,23 @@ Value *llvm::SimplifyCmpInst(unsigned Predicate, Value *LHS, Value *RHS,
|
|||||||
return SimplifyFCmpInst(Predicate, LHS, RHS, TD);
|
return SimplifyFCmpInst(Predicate, LHS, RHS, TD);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// SimplifyInstruction - See if we can compute a simplified version of this
|
||||||
|
/// instruction. If not, this returns null.
|
||||||
|
Value *llvm::SimplifyInstruction(Instruction *I, const TargetData *TD) {
|
||||||
|
switch (I->getOpcode()) {
|
||||||
|
default:
|
||||||
|
return ConstantFoldInstruction(I, TD);
|
||||||
|
case Instruction::And:
|
||||||
|
return SimplifyAndInst(I->getOperand(0), I->getOperand(1), TD);
|
||||||
|
case Instruction::Or:
|
||||||
|
return SimplifyOrInst(I->getOperand(0), I->getOperand(1), TD);
|
||||||
|
case Instruction::ICmp:
|
||||||
|
return SimplifyICmpInst(cast<ICmpInst>(I)->getPredicate(),
|
||||||
|
I->getOperand(0), I->getOperand(1), TD);
|
||||||
|
case Instruction::FCmp:
|
||||||
|
return SimplifyFCmpInst(cast<FCmpInst>(I)->getPredicate(),
|
||||||
|
I->getOperand(0), I->getOperand(1), TD);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -16,7 +16,6 @@
|
|||||||
#include "llvm/IntrinsicInst.h"
|
#include "llvm/IntrinsicInst.h"
|
||||||
#include "llvm/LLVMContext.h"
|
#include "llvm/LLVMContext.h"
|
||||||
#include "llvm/Pass.h"
|
#include "llvm/Pass.h"
|
||||||
#include "llvm/Analysis/ConstantFolding.h"
|
|
||||||
#include "llvm/Analysis/InstructionSimplify.h"
|
#include "llvm/Analysis/InstructionSimplify.h"
|
||||||
#include "llvm/Transforms/Utils/BasicBlockUtils.h"
|
#include "llvm/Transforms/Utils/BasicBlockUtils.h"
|
||||||
#include "llvm/Transforms/Utils/Local.h"
|
#include "llvm/Transforms/Utils/Local.h"
|
||||||
@@ -223,9 +222,9 @@ static void RemovePredecessorAndSimplify(BasicBlock *BB, BasicBlock *Pred,
|
|||||||
Instruction *User = cast<Instruction>(U.getUser());
|
Instruction *User = cast<Instruction>(U.getUser());
|
||||||
U = PNV;
|
U = PNV;
|
||||||
|
|
||||||
// See if we can simplify it (constant folding).
|
// See if we can simplify it.
|
||||||
if (Constant *C = ConstantFoldInstruction(User, TD)) {
|
if (Value *V = SimplifyInstruction(User, TD)) {
|
||||||
User->replaceAllUsesWith(C);
|
User->replaceAllUsesWith(V);
|
||||||
User->eraseFromParent();
|
User->eraseFromParent();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1203,8 +1202,8 @@ bool JumpThreading::ThreadEdge(BasicBlock *BB,
|
|||||||
BI = NewBB->begin();
|
BI = NewBB->begin();
|
||||||
for (BasicBlock::iterator E = NewBB->end(); BI != E; ) {
|
for (BasicBlock::iterator E = NewBB->end(); BI != E; ) {
|
||||||
Instruction *Inst = BI++;
|
Instruction *Inst = BI++;
|
||||||
if (Constant *C = ConstantFoldInstruction(Inst, TD)) {
|
if (Value *V = SimplifyInstruction(Inst, TD)) {
|
||||||
Inst->replaceAllUsesWith(C);
|
Inst->replaceAllUsesWith(V);
|
||||||
Inst->eraseFromParent();
|
Inst->eraseFromParent();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user