Commit 3e52250f authored by lxq's avatar lxq

optimize for constant int get

parent 06a9b882
...@@ -197,6 +197,15 @@ CodeGen::value2reg(Value *v, int i, string recommend) { ...@@ -197,6 +197,15 @@ CodeGen::value2reg(Value *v, int i, string recommend) {
if (dynamic_cast<Constant *>(v)) { if (dynamic_cast<Constant *>(v)) {
if (v == CONST_0) if (v == CONST_0)
return "$zero"; return "$zero";
if (dynamic_cast<ConstantInt *>(v)) {
auto const_int_v = static_cast<ConstantInt *>(v)->get_value();
auto [l, h] = immRange(12, false);
if (l <= const_int_v and const_int_v <= h) {
output.push_back("addi.d " + reg_name + ", $zero, " +
to_string(const_int_v));
return reg_name;
}
}
auto constant = static_cast<Constant *>(v); auto constant = static_cast<Constant *>(v);
if (ROdata.find(constant) == ROdata.end()) if (ROdata.find(constant) == ROdata.end())
ROdata[constant] = ".LC" + to_string(ROdata.size()); ROdata[constant] = ".LC" + to_string(ROdata.size());
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment