mirror of
https://github.com/RPCSX/llvm.git
synced 2025-04-13 05:20:27 +00:00
Re-apply r112539, being more careful to respect the return values of the constant folding methods. Additionally,
use the ConstantExpr::get*() methods to simplify some constant folding. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@112550 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
6d1e29d2f2
commit
327ca7bec2
@ -16,6 +16,7 @@
|
|||||||
#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/Analysis/LazyValueInfo.h"
|
#include "llvm/Analysis/LazyValueInfo.h"
|
||||||
#include "llvm/Analysis/Loads.h"
|
#include "llvm/Analysis/Loads.h"
|
||||||
@ -325,8 +326,9 @@ ComputeValueKnownInPredecessors(Value *V, BasicBlock *BB,PredValueInfo &Result){
|
|||||||
} else if (LVI) {
|
} else if (LVI) {
|
||||||
Constant *CI = LVI->getConstantOnEdge(InVal,
|
Constant *CI = LVI->getConstantOnEdge(InVal,
|
||||||
PN->getIncomingBlock(i), BB);
|
PN->getIncomingBlock(i), BB);
|
||||||
ConstantInt *CInt = dyn_cast_or_null<ConstantInt>(CI);
|
// LVI returns null is no value could be determined.
|
||||||
if (CInt)
|
if (!CI) continue;
|
||||||
|
ConstantInt *CInt = dyn_cast<ConstantInt>(CI);
|
||||||
Result.push_back(std::make_pair(CInt, PN->getIncomingBlock(i)));
|
Result.push_back(std::make_pair(CInt, PN->getIncomingBlock(i)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -373,10 +375,6 @@ ComputeValueKnownInPredecessors(Value *V, BasicBlock *BB,PredValueInfo &Result){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return !Result.empty();
|
return !Result.empty();
|
||||||
|
|
||||||
// Try to process a few other binary operator patterns.
|
|
||||||
} else if (isa<BinaryOperator>(I)) {
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle the NOT form of XOR.
|
// Handle the NOT form of XOR.
|
||||||
@ -404,8 +402,15 @@ ComputeValueKnownInPredecessors(Value *V, BasicBlock *BB,PredValueInfo &Result){
|
|||||||
SmallVector<std::pair<ConstantInt*, BasicBlock*>, 8> LHSVals;
|
SmallVector<std::pair<ConstantInt*, BasicBlock*>, 8> LHSVals;
|
||||||
ComputeValueKnownInPredecessors(BO->getOperand(0), BB, LHSVals);
|
ComputeValueKnownInPredecessors(BO->getOperand(0), BB, LHSVals);
|
||||||
for (unsigned i = 0, e = LHSVals.size(); i != e; ++i)
|
for (unsigned i = 0, e = LHSVals.size(); i != e; ++i)
|
||||||
if (LHSVals[i].first == CI)
|
if (LHSVals[i].first == 0) {
|
||||||
Result.push_back(std::make_pair(CI, LHSVals[i].second));
|
ConstantInt *Zero =
|
||||||
|
cast<ConstantInt>(ConstantInt::get(BO->getType(), 0));
|
||||||
|
Result.push_back(std::make_pair(Zero, LHSVals[i].second));
|
||||||
|
} else if (Constant *Folded = ConstantExpr::get(BO->getOpcode(),
|
||||||
|
LHSVals[i].first, CI)) {
|
||||||
|
Result.push_back(std::make_pair(cast<ConstantInt>(Folded),
|
||||||
|
LHSVals[i].second));
|
||||||
|
}
|
||||||
|
|
||||||
return !Result.empty();
|
return !Result.empty();
|
||||||
}
|
}
|
||||||
@ -472,20 +477,18 @@ ComputeValueKnownInPredecessors(Value *V, BasicBlock *BB,PredValueInfo &Result){
|
|||||||
|
|
||||||
// Try to find a constant value for the LHS of an equality comparison,
|
// Try to find a constant value for the LHS of an equality comparison,
|
||||||
// and evaluate it statically if we can.
|
// and evaluate it statically if we can.
|
||||||
if (Cmp->getPredicate() == CmpInst::ICMP_EQ ||
|
if (Constant *CmpConst = dyn_cast<Constant>(Cmp->getOperand(1))) {
|
||||||
Cmp->getPredicate() == CmpInst::ICMP_NE) {
|
|
||||||
SmallVector<std::pair<ConstantInt*, BasicBlock*>, 8> LHSVals;
|
SmallVector<std::pair<ConstantInt*, BasicBlock*>, 8> LHSVals;
|
||||||
ComputeValueKnownInPredecessors(I->getOperand(0), BB, LHSVals);
|
ComputeValueKnownInPredecessors(I->getOperand(0), BB, LHSVals);
|
||||||
|
|
||||||
ConstantInt *True = ConstantInt::getTrue(I->getContext());
|
|
||||||
ConstantInt *False = ConstantInt::getFalse(I->getContext());
|
|
||||||
if (Cmp->getPredicate() == CmpInst::ICMP_NE) std::swap(True, False);
|
|
||||||
|
|
||||||
for (unsigned i = 0, e = LHSVals.size(); i != e; ++i) {
|
for (unsigned i = 0, e = LHSVals.size(); i != e; ++i) {
|
||||||
if (LHSVals[i].first == Cmp->getOperand(1))
|
if (LHSVals[i].first == 0)
|
||||||
Result.push_back(std::make_pair(True, LHSVals[i].second));
|
Result.push_back(std::make_pair((ConstantInt*)0,
|
||||||
else
|
LHSVals[i].second));
|
||||||
Result.push_back(std::make_pair(False, LHSVals[i].second));
|
else if (Constant *Folded = ConstantExpr::getCompare(
|
||||||
|
Cmp->getPredicate(), LHSVals[i].first, CmpConst))
|
||||||
|
Result.push_back(std::make_pair(cast<ConstantInt>(Folded),
|
||||||
|
LHSVals[i].second));
|
||||||
}
|
}
|
||||||
|
|
||||||
return !Result.empty();
|
return !Result.empty();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user