aboutsummaryrefslogtreecommitdiffhomepage
path: root/amd64/isel.c
diff options
context:
space:
mode:
authorlemon <lsof@mailbox.org>2023-06-12 19:16:39 +0200
committerlemon <lsof@mailbox.org>2023-06-12 19:16:39 +0200
commit106fe60243bd61d017d28795f6eba68fecc981b4 (patch)
tree7fbb5c1a84346af8243630cb6c0057ab9b475978 /amd64/isel.c
parent6df4f80c99609162ad3e46bfdce46d0c10696a45 (diff)
dec,inc,sub
Diffstat (limited to 'amd64/isel.c')
-rw-r--r--amd64/isel.c18
1 files changed, 17 insertions, 1 deletions
diff --git a/amd64/isel.c b/amd64/isel.c
index 8ab11a7..30ad222 100644
--- a/amd64/isel.c
+++ b/amd64/isel.c
@@ -171,7 +171,11 @@ sel(struct function *fn, struct instr *ins, struct block *blk, int *curi)
insertinstr(blk, ++(*curi), temp);
break;
case Osub:
- if (iscon(ins->l)) {
+ if (ins->r.bits == mkref(RICON, 1).bits) {
+ /* sub x,1 -> dec x */
+ ins->op = Oxdec;
+ ins->r = NOREF;
+ } else if (iscon(ins->l)) {
/* sub imm, x -> sub x, imm; neg x */
struct instr sub = *ins;
rswap(sub.l, sub.r);
@@ -181,6 +185,18 @@ sel(struct function *fn, struct instr *ins, struct block *blk, int *curi)
}
goto ALU;
case Oadd:
+ if (ins->l.bits == mkref(RICON, 1).bits) {
+ /* add 1,x -> inc x */
+ ins->op = Oxinc;
+ ins->l = ins->r;
+ ins->r = NOREF;
+ goto ALU;
+ } else if (ins->r.bits == mkref(RICON, 1).bits) {
+ /* add x,1 -> inc x */
+ ins->op = Oxinc;
+ ins->r = NOREF;
+ goto ALU;
+ }
if (kisint(ins->cls) && (addarg4addrp(ins->l) || addarg4addrp(ins->r))) {
temp.op = Ocopy;
temp.cls = ins->cls;