From: Filip Navara Date: Thu, 12 Sep 2019 16:37:52 +0000 (+0200) Subject: [mini] Fix couple of R4 constant folding checks (mono/mono#16782) X-Git-Tag: submit/tizen/20210909.063632~10331^2~5^2~519 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=329ddbee8ec3497cc308a2eb1b54f090c74d015e;p=platform%2Fupstream%2Fdotnet%2Fruntime.git [mini] Fix couple of R4 constant folding checks (mono/mono#16782) * Fix couple of R4 constant folding checks * Address feedback * Split RMOVE and FMOVE Commit migrated from https://github.com/mono/mono/commit/017f21c2c6b3c23c248b5d9a2d6816edd5deeb04 --- diff --git a/src/mono/mono/mini/cfold.c b/src/mono/mono/mini/cfold.c index d413196..737f5ab 100644 --- a/src/mono/mono/mini/cfold.c +++ b/src/mono/mono/mini/cfold.c @@ -49,6 +49,12 @@ mono_is_power_of_two (guint32 val) *(double *)dest->inst_p0 = (*((double *) arg1->inst_p0)) op (*((double *) arg2->inst_p0)); \ break; +#define FOLD_RBINOP(name, op) \ + case name: \ + dest->inst_p0 = (float *)mono_domain_alloc (cfg->domain, sizeof (float)); \ + *(float *)dest->inst_p0 = (*((float *) arg1->inst_p0)) op (*((float *) arg2->inst_p0)); \ + break; + #define FOLD_BINOPC(name,op,cast) \ case name: \ dest->inst_c0 = (cast)arg1->inst_c0 op (cast)arg2->inst_c0; \ @@ -97,7 +103,7 @@ mono_constant_fold_ins (MonoCompile *cfg, MonoInst *ins, MonoInst *arg1, MonoIns switch (ins->opcode) { case OP_FADD: case OP_FMUL: - if (arg2->opcode == OP_R8CONST && arg2->opcode == OP_R8CONST){ + if (arg1->opcode == OP_R8CONST && arg2->opcode == OP_R8CONST) { ALLOC_DEST (cfg, dest, ins); switch (ins->opcode) { FOLD_FBINOP (OP_FADD, +); @@ -107,6 +113,18 @@ mono_constant_fold_ins (MonoCompile *cfg, MonoInst *ins, MonoInst *arg1, MonoIns MONO_INST_NULLIFY_SREGS (dest); } break; + case OP_RADD: + case OP_RMUL: + if (arg1->opcode == OP_R4CONST && arg2->opcode == OP_R4CONST) { + ALLOC_DEST (cfg, dest, ins); + switch (ins->opcode) { + FOLD_RBINOP (OP_RADD, +); + FOLD_RBINOP (OP_RMUL, *); + } + dest->opcode = OP_R4CONST; + MONO_INST_NULLIFY_SREGS (dest); + } + break; case OP_IMUL: case OP_IADD: case OP_IAND: @@ -258,6 +276,22 @@ mono_constant_fold_ins (MonoCompile *cfg, MonoInst *ins, MonoInst *arg1, MonoIns dest->inst_c0 = arg1->inst_c0; } break; + case OP_FMOVE: + if (arg1->opcode == OP_R8CONST) { + ALLOC_DEST (cfg, dest, ins); + dest->opcode = arg1->opcode; + dest->sreg1 = -1; + dest->inst_p0 = arg1->inst_p0; + } + break; + case OP_RMOVE: + if (arg1->opcode == OP_R4CONST) { + ALLOC_DEST (cfg, dest, ins); + dest->opcode = arg1->opcode; + dest->sreg1 = -1; + dest->inst_p0 = arg1->inst_p0; + } + break; case OP_VMOVE: if (arg1->opcode == OP_VZERO) { ALLOC_DEST (cfg, dest, ins); @@ -407,14 +441,6 @@ mono_constant_fold_ins (MonoCompile *cfg, MonoInst *ins, MonoInst *arg1, MonoIns } break; } - case OP_FMOVE: - if (arg1->opcode == OP_R8CONST) { - ALLOC_DEST (cfg, dest, ins); - dest->opcode = OP_R8CONST; - dest->sreg1 = -1; - dest->inst_p0 = arg1->inst_p0; - } - break; /* * TODO: