[deploy]禁用除法强度削弱优化,禁用GVN对load和GEP指令进行优化
This commit is contained in:
@@ -237,9 +237,30 @@ bool GVNContext::processInstruction(Instruction* inst) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// 暂时完全禁用LoadInst的GVN优化,因为存在内存安全性问题
|
||||
if (dynamic_cast<LoadInst*>(inst)) {
|
||||
if (DEBUG) {
|
||||
std::cout << " Skipping LoadInst GVN optimization for safety: " << inst->getName() << std::endl;
|
||||
}
|
||||
getValueNumber(inst);
|
||||
return false;
|
||||
}
|
||||
|
||||
// 暂时完全禁用GetElementPtrInst的GVN优化,因为可能存在内存安全性问题
|
||||
if (dynamic_cast<GetElementPtrInst*>(inst)) {
|
||||
if (DEBUG) {
|
||||
std::cout << " Skipping GetElementPtrInst GVN optimization for safety: " << inst->getName() << std::endl;
|
||||
}
|
||||
getValueNumber(inst);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (DEBUG) {
|
||||
std::cout << " Processing optimizable instruction: " << inst->getName()
|
||||
<< " (kind: " << static_cast<int>(inst->getKind()) << ")" << std::endl;
|
||||
if (auto loadInst = dynamic_cast<LoadInst*>(inst)) {
|
||||
std::cout << " This is a LOAD instruction in block: " << inst->getParent()->getName() << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
// 构建表达式键
|
||||
@@ -257,6 +278,20 @@ bool GVNContext::processInstruction(Instruction* inst) {
|
||||
// 查找已存在的等价值
|
||||
Value* existing = findExistingValue(exprKey, inst);
|
||||
if (existing && existing != inst) {
|
||||
if (DEBUG) {
|
||||
std::cout << " Found potential replacement: " << existing->getName()
|
||||
<< " for " << inst->getName() << std::endl;
|
||||
if (auto loadInst = dynamic_cast<LoadInst*>(inst)) {
|
||||
std::cout << " Current instruction is LoadInst" << std::endl;
|
||||
if (auto existingLoad = dynamic_cast<LoadInst*>(existing)) {
|
||||
std::cout << " Existing value is also LoadInst in block: "
|
||||
<< existingLoad->getParent()->getName() << std::endl;
|
||||
} else {
|
||||
std::cout << " Existing value is NOT LoadInst, type: "
|
||||
<< typeid(*existing).name() << std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
// 检查支配关系
|
||||
if (auto existingInst = dynamic_cast<Instruction*>(existing)) {
|
||||
if (dominates(existingInst, inst)) {
|
||||
@@ -350,8 +385,17 @@ Value* GVNContext::findExistingValue(const std::string& exprKey, Instruction* in
|
||||
if (auto loadInst = dynamic_cast<LoadInst*>(inst)) {
|
||||
if (auto existingLoad = dynamic_cast<LoadInst*>(existing)) {
|
||||
if (!isMemorySafe(existingLoad, loadInst)) {
|
||||
if (DEBUG) {
|
||||
std::cout << " Memory safety check failed for load optimization" << std::endl;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
} else {
|
||||
// existing不是load指令,但当前指令是load,不能替换
|
||||
if (DEBUG) {
|
||||
std::cout << " Cannot replace load with non-load instruction" << std::endl;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -409,6 +453,9 @@ bool GVNContext::isMemorySafe(LoadInst* earlierLoad, LoadInst* laterLoad) {
|
||||
|
||||
if (earlierBB != laterBB) {
|
||||
// 跨基本块的情况需要更复杂的分析,暂时保守处理
|
||||
if (DEBUG) {
|
||||
std::cout << " Memory safety check: Cross-block load optimization disabled" << std::endl;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user