ref: e5e6cd22621169df9a8cc696500c64de3740b835
parent: 56cb1396d9f421006f2907dc4d504127f8ed0e1d
author: Roberto E. Vargas Caballero <[email protected]>
date: Wed Nov 3 18:56:02 EDT 2021
cc2/qbe: Move casts in assignation to sethi() Some basic transformations are done in sethi(), and the cast transfornation in assignment fit in that category. When the lhs has a cast it implies a cast in the rhs, because the value to store must be transformed to the type forced in the cast of the lhs.
--- a/src/cmd/cc/cc2/target/qbe/cgen.c
+++ b/src/cmd/cc/cc2/target/qbe/cgen.c
@@ -556,7 +556,6 @@
case OCAST:
return cast(tp, rhs(l, &aux1), ret);
case OASSIG:
- /* TODO: Do this transformations in sethi */
switch (np->u.subop) {
case OINC:
op = OADD;
@@ -578,15 +577,6 @@
aux2.right = np->right;
aux2.left = np->left;
r = rhs(&aux2, &aux1);
-
- if (l->op == OCAST) {
- aux3.type = l->left->type;
- aux3.op = OCAST;
- aux3.left = r;
- aux3.right = NULL;
- r = &aux3;
- l = l->left;
- }
case 0:
if (l->complex >= r->complex) {
lhs(l, &aux2);
@@ -683,6 +673,7 @@
Node *
sethi(Node *np)
{
+ int op;
Node *lp, *rp;
if (!np)
@@ -700,6 +691,21 @@
case OCONST:
np->address = 11;
break;
+ case OASSIG:
+ op = np->u.subop;
+ if (op != OINC && op != ODEC) {
+ if (lp->op == OCAST) {
+ Node *tmp = node(OCAST);
+ tmp->type = lp->left->type;
+ tmp->left = rp;
+ tmp->right = NULL;
+ rp = tmp;
+ tmp = lp;
+ lp = lp->left;
+ delnode(tmp);
+ }
+ }
+ goto binary;
case OCPL:
assert(np->type.flags & INTF);
np->op = OBXOR;