[midend]删除了错误的sra指令生成逻辑
This commit is contained in:
@@ -389,26 +389,7 @@ void SysYIRGenerator::compute() {
|
|||||||
case BinaryOp::ADD: resultValue = builder.createAddInst(lhs, rhs); break;
|
case BinaryOp::ADD: resultValue = builder.createAddInst(lhs, rhs); break;
|
||||||
case BinaryOp::SUB: resultValue = builder.createSubInst(lhs, rhs); break;
|
case BinaryOp::SUB: resultValue = builder.createSubInst(lhs, rhs); break;
|
||||||
case BinaryOp::MUL: resultValue = builder.createMulInst(lhs, rhs); break;
|
case BinaryOp::MUL: resultValue = builder.createMulInst(lhs, rhs); break;
|
||||||
case BinaryOp::DIV: {
|
case BinaryOp::DIV: resultValue = builder.createDivInst(lhs, rhs); break;
|
||||||
ConstantInteger *rhsConst = dynamic_cast<ConstantInteger *>(rhs);
|
|
||||||
if (rhsConst) {
|
|
||||||
int divisor = rhsConst->getInt();
|
|
||||||
if (divisor > 0 && (divisor & (divisor - 1)) == 0) {
|
|
||||||
int shift = 0;
|
|
||||||
int temp = divisor;
|
|
||||||
while (temp > 1) {
|
|
||||||
temp >>= 1;
|
|
||||||
shift++;
|
|
||||||
}
|
|
||||||
resultValue = builder.createSRAInst(lhs, ConstantInteger::get(shift));
|
|
||||||
} else {
|
|
||||||
resultValue = builder.createDivInst(lhs, rhs);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
resultValue = builder.createDivInst(lhs, rhs);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case BinaryOp::MOD: resultValue = builder.createRemInst(lhs, rhs); break;
|
case BinaryOp::MOD: resultValue = builder.createRemInst(lhs, rhs); break;
|
||||||
}
|
}
|
||||||
} else if (commonType == Type::getFloatType()) {
|
} else if (commonType == Type::getFloatType()) {
|
||||||
|
|||||||
Reference in New Issue
Block a user