(expand_increment): Convert constant subtract to add before setting single_insn.
authorRichard Stallman <rms@gnu.org>
Tue, 20 Jul 1993 06:23:58 +0000 (06:23 +0000)
committerRichard Stallman <rms@gnu.org>
Tue, 20 Jul 1993 06:23:58 +0000 (06:23 +0000)
(expand_increment): Convert constant subtract to add
before setting single_insn.  Compensate for this when choosing
the tree code to pass to `build'.

From-SVN: r4944

gcc/expr.c

index 965eabc2c762837e5a4bdba9853178b5729e727a..9ba19e5d3a3fc022ad9f288d4fc1287f024e44c7 100644 (file)
@@ -6898,6 +6898,14 @@ expand_increment (exp, post)
       || TREE_CODE (exp) == PREDECREMENT_EXPR)
     this_optab = sub_optab;
 
+  /* Convert decrement by a constant into a negative increment.  */
+  if (this_optab == sub_optab
+      && GET_CODE (op1) == CONST_INT)
+    {
+      op1 = GEN_INT (- INTVAL (op1));
+      this_optab = add_optab;
+    }
+
   /* For a preincrement, see if we can do this with a single instruction.  */
   if (!post)
     {
@@ -6924,8 +6932,9 @@ expand_increment (exp, post)
         in which case it was stabilized above, or (2) it is an array_ref
         with constant index in an array in a register, which is
         safe to reevaluate.  */
-      tree newexp = build ((this_optab == add_optab
-                           ? PLUS_EXPR : MINUS_EXPR),
+      tree newexp = build (((TREE_CODE (exp) == POSTDECREMENT_EXPR
+                            || TREE_CODE (exp) == PREDECREMENT_EXPR)
+                           ? MINUS_EXPR : PLUS_EXPR),
                           TREE_TYPE (exp),
                           incremented,
                           TREE_OPERAND (exp, 1));
@@ -6933,14 +6942,6 @@ expand_increment (exp, post)
       return post ? op0 : temp;
     }
 
-  /* Convert decrement by a constant into a negative increment.  */
-  if (this_optab == sub_optab
-      && GET_CODE (op1) == CONST_INT)
-    {
-      op1 = GEN_INT (- INTVAL (op1));
-      this_optab = add_optab;
-    }
-
   if (post)
     {
       /* We have a true reference to the value in OP0.