]> git.xonotic.org Git - xonotic/gmqcc.git/blobdiff - fold.c
subtracting != adding
[xonotic/gmqcc.git] / fold.c
diff --git a/fold.c b/fold.c
index c9f1a0695c07f8fe1b9c35b62f7bbfab4eaaa360..cd827bc5aa1d376913e50565282c33bf449e97bf 100644 (file)
--- a/fold.c
+++ b/fold.c
@@ -59,9 +59,9 @@ static GMQCC_INLINE vec3_t vec3_add(vec3_t a, vec3_t b) {
 
 static GMQCC_INLINE vec3_t vec3_sub(vec3_t a, vec3_t b) {
     vec3_t out;
-    out.x = a.x + b.x;
-    out.y = a.y + b.y;
-    out.z = a.z + b.z;
+    out.x = a.x - b.x;
+    out.y = a.y - b.y;
+    out.z = a.z - b.z;
     return out;
 }
 
@@ -799,8 +799,10 @@ static ast_expression *fold_superfluous(ast_expression *left, ast_expression *ri
             break;
 
 
-        case INSTR_ADD_F:
         case INSTR_SUB_F:
+            if (swapped)
+                return NULL;
+        case INSTR_ADD_F:
             if (fold_immvalue_float(load) == 0.0f) {
                 ++opts_optimizationcount[OPTIM_PEEPHOLE];
                 ast_unref(right);
@@ -816,8 +818,10 @@ static ast_expression *fold_superfluous(ast_expression *left, ast_expression *ri
             }
             break;
 
-        case INSTR_ADD_V:
         case INSTR_SUB_V:
+            if (swapped)
+                return NULL;
+        case INSTR_ADD_V:
             if (vec3_cmp(fold_immvalue_vector(load), vec3_create(0, 0, 0))) {
                 ++opts_optimizationcount[OPTIM_PEEPHOLE];
                 ast_unref(right);