ref: 3ff334c28bef9d70eee5566e0fe66616b34167bd
parent: bcedb21933bb5b585d6e65bd17eb2aaadf5f95a6
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Thu Nov 4 11:08:27 EDT 2021
cc2/qbe: Simplify field() The offset check is not needed because qbe can figure out the optimization. This target is the simplest of all the targets because the big part of the problem is solved by qbe, so it is better to try to keep it as simple as possible in a way that can be used as skeleton for other targets.
--- a/src/cmd/cc/cc2/target/qbe/cgen.c
+++ b/src/cmd/cc/cc2/target/qbe/cgen.c
@@ -262,8 +262,6 @@
return from;
}
-/* TODO: Do field() transformation in sethi */
-
static Node *
field(Node *np, int islhs)
{
@@ -271,19 +269,15 @@
TUINT offset = np->right->u.sym->u.off;
addr = rhs(np->left);
+ tmp = node(OADD);
+ tmp->type = ptrtype;
+ tmp->left = addr;
+ tmp->right = constnode(NULL, offset, &ptrtype);
+ addr = rhs(tmp);
- if (offset != 0) {
- tmp = node(OADD);
- tmp->type = ptrtype;
- tmp->left = addr;
- tmp->right = constnode(NULL, offset, &ptrtype);
- addr = rhs(tmp);
- }
-
- if (islhs)
- return addr;
- else
- return load(&np->type, addr);
+ if (!islhs)
+ addr = load(&np->type, addr);
+ return addr;
}
static Node *