Remove gimplify_buildN API use from complex lowering
authorRichard Biener <rguenther@suse.de>
Thu, 15 Apr 2021 09:52:16 +0000 (11:52 +0200)
committerRichard Biener <rguenther@suse.de>
Mon, 26 Apr 2021 09:04:00 +0000 (11:04 +0200)
This removes the legacy gimplify_buildN API use from complex lowering.

2021-04-15  Richard Biener  <rguenther@suse.de>

* tree-complex.c: Include gimple-fold.h.
(expand_complex_addition): Use gimple_build.
(expand_complex_multiplication_components): Likewise.
(expand_complex_multiplication): Likewise.
(expand_complex_div_straight): Likewise.
(expand_complex_div_wide): Likewise.
(expand_complex_division): Likewise.
(expand_complex_conjugate): Likewise.
(expand_complex_comparison): Likewise.

gcc/tree-complex.c

index b11da01..d7d9917 100644 (file)
@@ -40,6 +40,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "tree-hasher.h"
 #include "cfgloop.h"
 #include "cfganal.h"
+#include "gimple-fold.h"
 
 
 /* For each complex ssa name, a lattice value.  We're interested in finding
@@ -916,25 +917,27 @@ expand_complex_addition (gimple_stmt_iterator *gsi, tree inner_type,
                         complex_lattice_t al, complex_lattice_t bl)
 {
   tree rr, ri;
+  gimple_seq stmts = NULL;
+  location_t loc = gimple_location (gsi_stmt (*gsi));
 
   switch (PAIR (al, bl))
     {
     case PAIR (ONLY_REAL, ONLY_REAL):
-      rr = gimplify_build2 (gsi, code, inner_type, ar, br);
+      rr = gimple_build (&stmts, loc, code, inner_type, ar, br);
       ri = ai;
       break;
 
     case PAIR (ONLY_REAL, ONLY_IMAG):
       rr = ar;
       if (code == MINUS_EXPR)
-       ri = gimplify_build2 (gsi, MINUS_EXPR, inner_type, ai, bi);
+       ri = gimple_build (&stmts, loc, MINUS_EXPR, inner_type, ai, bi);
       else
        ri = bi;
       break;
 
     case PAIR (ONLY_IMAG, ONLY_REAL):
       if (code == MINUS_EXPR)
-       rr = gimplify_build2 (gsi, MINUS_EXPR, inner_type, ar, br);
+       rr = gimple_build (&stmts, loc, MINUS_EXPR, inner_type, ar, br);
       else
        rr = br;
       ri = ai;
@@ -942,23 +945,23 @@ expand_complex_addition (gimple_stmt_iterator *gsi, tree inner_type,
 
     case PAIR (ONLY_IMAG, ONLY_IMAG):
       rr = ar;
-      ri = gimplify_build2 (gsi, code, inner_type, ai, bi);
+      ri = gimple_build (&stmts, loc, code, inner_type, ai, bi);
       break;
 
     case PAIR (VARYING, ONLY_REAL):
-      rr = gimplify_build2 (gsi, code, inner_type, ar, br);
+      rr = gimple_build (&stmts, loc, code, inner_type, ar, br);
       ri = ai;
       break;
 
     case PAIR (VARYING, ONLY_IMAG):
       rr = ar;
-      ri = gimplify_build2 (gsi, code, inner_type, ai, bi);
+      ri = gimple_build (&stmts, loc, code, inner_type, ai, bi);
       break;
 
     case PAIR (ONLY_REAL, VARYING):
       if (code == MINUS_EXPR)
        goto general;
-      rr = gimplify_build2 (gsi, code, inner_type, ar, br);
+      rr = gimple_build (&stmts, loc, code, inner_type, ar, br);
       ri = bi;
       break;
 
@@ -966,19 +969,20 @@ expand_complex_addition (gimple_stmt_iterator *gsi, tree inner_type,
       if (code == MINUS_EXPR)
        goto general;
       rr = br;
-      ri = gimplify_build2 (gsi, code, inner_type, ai, bi);
+      ri = gimple_build (&stmts, loc, code, inner_type, ai, bi);
       break;
 
     case PAIR (VARYING, VARYING):
     general:
-      rr = gimplify_build2 (gsi, code, inner_type, ar, br);
-      ri = gimplify_build2 (gsi, code, inner_type, ai, bi);
+      rr = gimple_build (&stmts, loc, code, inner_type, ar, br);
+      ri = gimple_build (&stmts, loc, code, inner_type, ai, bi);
       break;
 
     default:
       gcc_unreachable ();
     }
 
+  gsi_insert_seq_before (gsi, stmts, GSI_SAME_STMT);
   update_complex_assignment (gsi, rr, ri);
 }
 
@@ -1059,26 +1063,26 @@ expand_complex_libcall (gimple_stmt_iterator *gsi, tree type, tree ar, tree ai,
    components of the result into RR and RI.  */
 
 static void
-expand_complex_multiplication_components (gimple_stmt_iterator *gsi,
-                                            tree type, tree ar, tree ai,
-                                            tree br, tree bi,
-                                            tree *rr, tree *ri)
+expand_complex_multiplication_components (gimple_seq *stmts, location_t loc,
+                                         tree type, tree ar, tree ai,
+                                         tree br, tree bi,
+                                         tree *rr, tree *ri)
 {
   tree t1, t2, t3, t4;
 
-  t1 = gimplify_build2 (gsi, MULT_EXPR, type, ar, br);
-  t2 = gimplify_build2 (gsi, MULT_EXPR, type, ai, bi);
-  t3 = gimplify_build2 (gsi, MULT_EXPR, type, ar, bi);
+  t1 = gimple_build (stmts, loc, MULT_EXPR, type, ar, br);
+  t2 = gimple_build (stmts, loc, MULT_EXPR, type, ai, bi);
+  t3 = gimple_build (stmts, loc, MULT_EXPR, type, ar, bi);
 
   /* Avoid expanding redundant multiplication for the common
      case of squaring a complex number.  */
   if (ar == br && ai == bi)
     t4 = t3;
   else
-    t4 = gimplify_build2 (gsi, MULT_EXPR, type, ai, br);
+    t4 = gimple_build (stmts, loc, MULT_EXPR, type, ai, br);
 
-  *rr = gimplify_build2 (gsi, MINUS_EXPR, type, t1, t2);
-  *ri = gimplify_build2 (gsi, PLUS_EXPR, type, t3, t4);
+  *rr = gimple_build (stmts, loc, MINUS_EXPR, type, t1, t2);
+  *ri = gimple_build (stmts, loc, PLUS_EXPR, type, t3, t4);
 }
 
 /* Expand complex multiplication to scalars:
@@ -1092,6 +1096,8 @@ expand_complex_multiplication (gimple_stmt_iterator *gsi, tree type,
 {
   tree rr, ri;
   tree inner_type = TREE_TYPE (type);
+  location_t loc = gimple_location (gsi_stmt (*gsi));
+  gimple_seq stmts = NULL;
 
   if (al < bl)
     {
@@ -1104,7 +1110,7 @@ expand_complex_multiplication (gimple_stmt_iterator *gsi, tree type,
   switch (PAIR (al, bl))
     {
     case PAIR (ONLY_REAL, ONLY_REAL):
-      rr = gimplify_build2 (gsi, MULT_EXPR, inner_type, ar, br);
+      rr = gimple_build (&stmts, loc, MULT_EXPR, inner_type, ar, br);
       ri = ai;
       break;
 
@@ -1114,24 +1120,24 @@ expand_complex_multiplication (gimple_stmt_iterator *gsi, tree type,
          && real_identical (&TREE_REAL_CST (ai), &dconst1))
        ri = br;
       else
-       ri = gimplify_build2 (gsi, MULT_EXPR, inner_type, ai, br);
+       ri = gimple_build (&stmts, loc, MULT_EXPR, inner_type, ai, br);
       break;
 
     case PAIR (ONLY_IMAG, ONLY_IMAG):
-      rr = gimplify_build2 (gsi, MULT_EXPR, inner_type, ai, bi);
-      rr = gimplify_build1 (gsi, NEGATE_EXPR, inner_type, rr);
+      rr = gimple_build (&stmts, loc, MULT_EXPR, inner_type, ai, bi);
+      rr = gimple_build (&stmts, loc, NEGATE_EXPR, inner_type, rr);
       ri = ar;
       break;
 
     case PAIR (VARYING, ONLY_REAL):
-      rr = gimplify_build2 (gsi, MULT_EXPR, inner_type, ar, br);
-      ri = gimplify_build2 (gsi, MULT_EXPR, inner_type, ai, br);
+      rr = gimple_build (&stmts, loc, MULT_EXPR, inner_type, ar, br);
+      ri = gimple_build (&stmts, loc, MULT_EXPR, inner_type, ai, br);
       break;
 
     case PAIR (VARYING, ONLY_IMAG):
-      rr = gimplify_build2 (gsi, MULT_EXPR, inner_type, ai, bi);
-      rr = gimplify_build1 (gsi, NEGATE_EXPR, inner_type, rr);
-      ri = gimplify_build2 (gsi, MULT_EXPR, inner_type, ar, bi);
+      rr = gimple_build (&stmts, loc, MULT_EXPR, inner_type, ai, bi);
+      rr = gimple_build (&stmts, loc, NEGATE_EXPR, inner_type, rr);
+      ri = gimple_build (&stmts, loc, MULT_EXPR, inner_type, ar, bi);
       break;
 
     case PAIR (VARYING, VARYING):
@@ -1152,7 +1158,7 @@ expand_complex_multiplication (gimple_stmt_iterator *gsi, tree type,
            {
              /* If we are not worrying about NaNs expand to
                 (ar*br - ai*bi) + i(ar*bi + br*ai) directly.  */
-             expand_complex_multiplication_components (gsi, inner_type,
+             expand_complex_multiplication_components (&stmts, loc, inner_type,
                                                        ar, ai, br, bi,
                                                        &rr, &ri);
              break;
@@ -1164,8 +1170,11 @@ expand_complex_multiplication (gimple_stmt_iterator *gsi, tree type,
                x = __muldc3 (a, b);  */
 
          tree tmpr, tmpi;
-         expand_complex_multiplication_components (gsi, inner_type, ar, ai,
+         expand_complex_multiplication_components (&stmts, loc,
+                                                   inner_type, ar, ai,
                                                    br, bi, &tmpr, &tmpi);
+         gsi_insert_seq_before (gsi, stmts, GSI_SAME_STMT);
+         stmts = NULL;
 
          gimple *check
            = gimple_build_cond (UNORDERED_EXPR, tmpr, tmpi,
@@ -1187,10 +1196,12 @@ expand_complex_multiplication (gimple_stmt_iterator *gsi, tree type,
          tree libcall_res
            = expand_complex_libcall (&cond_bb_gsi, type, ar, ai, br,
                                      bi, MULT_EXPR, false);
-         tree cond_real = gimplify_build1 (&cond_bb_gsi, REALPART_EXPR,
-                                           inner_type, libcall_res);
-         tree cond_imag = gimplify_build1 (&cond_bb_gsi, IMAGPART_EXPR,
-                                           inner_type, libcall_res);
+         gimple_seq stmts2 = NULL;
+         tree cond_real = gimple_build (&stmts2, loc, REALPART_EXPR,
+                                        inner_type, libcall_res);
+         tree cond_imag = gimple_build (&stmts2, loc, IMAGPART_EXPR,
+                                        inner_type, libcall_res);
+         gsi_insert_seq_before (&cond_bb_gsi, stmts2, GSI_SAME_STMT);
 
          basic_block join_bb = single_succ_edge (cond_bb)->dest;
          *gsi = gsi_start_nondebug_after_labels_bb (join_bb);
@@ -1213,7 +1224,8 @@ expand_complex_multiplication (gimple_stmt_iterator *gsi, tree type,
       else
        /* If we are not worrying about NaNs expand to
          (ar*br - ai*bi) + i(ar*bi + br*ai) directly.  */
-       expand_complex_multiplication_components (gsi, inner_type, ar, ai,
+       expand_complex_multiplication_components (&stmts, loc,
+                                                 inner_type, ar, ai,
                                                  br, bi, &rr, &ri);
       break;
 
@@ -1221,6 +1233,7 @@ expand_complex_multiplication (gimple_stmt_iterator *gsi, tree type,
       gcc_unreachable ();
     }
 
+  gsi_insert_seq_before (gsi, stmts, GSI_SAME_STMT);
   update_complex_assignment (gsi, rr, ri);
 }
 
@@ -1236,22 +1249,25 @@ expand_complex_div_straight (gimple_stmt_iterator *gsi, tree inner_type,
                             tree ar, tree ai, tree br, tree bi,
                             enum tree_code code)
 {
+  gimple_seq stmts = NULL;
+  location_t loc = gimple_location (gsi_stmt (*gsi));
   tree rr, ri, div, t1, t2, t3;
 
-  t1 = gimplify_build2 (gsi, MULT_EXPR, inner_type, br, br);
-  t2 = gimplify_build2 (gsi, MULT_EXPR, inner_type, bi, bi);
-  div = gimplify_build2 (gsi, PLUS_EXPR, inner_type, t1, t2);
+  t1 = gimple_build (&stmts, loc, MULT_EXPR, inner_type, br, br);
+  t2 = gimple_build (&stmts, loc, MULT_EXPR, inner_type, bi, bi);
+  div = gimple_build (&stmts, loc, PLUS_EXPR, inner_type, t1, t2);
 
-  t1 = gimplify_build2 (gsi, MULT_EXPR, inner_type, ar, br);
-  t2 = gimplify_build2 (gsi, MULT_EXPR, inner_type, ai, bi);
-  t3 = gimplify_build2 (gsi, PLUS_EXPR, inner_type, t1, t2);
-  rr = gimplify_build2 (gsi, code, inner_type, t3, div);
+  t1 = gimple_build (&stmts, loc, MULT_EXPR, inner_type, ar, br);
+  t2 = gimple_build (&stmts, loc, MULT_EXPR, inner_type, ai, bi);
+  t3 = gimple_build (&stmts, loc, PLUS_EXPR, inner_type, t1, t2);
+  rr = gimple_build (&stmts, loc, code, inner_type, t3, div);
 
-  t1 = gimplify_build2 (gsi, MULT_EXPR, inner_type, ai, br);
-  t2 = gimplify_build2 (gsi, MULT_EXPR, inner_type, ar, bi);
-  t3 = gimplify_build2 (gsi, MINUS_EXPR, inner_type, t1, t2);
-  ri = gimplify_build2 (gsi, code, inner_type, t3, div);
+  t1 = gimple_build (&stmts, loc, MULT_EXPR, inner_type, ai, br);
+  t2 = gimple_build (&stmts, loc, MULT_EXPR, inner_type, ar, bi);
+  t3 = gimple_build (&stmts, loc, MINUS_EXPR, inner_type, t1, t2);
+  ri = gimple_build (&stmts, loc, code, inner_type, t3, div);
 
+  gsi_insert_seq_before (gsi, stmts, GSI_SAME_STMT);
   update_complex_assignment (gsi, rr, ri);
 }
 
@@ -1268,13 +1284,14 @@ expand_complex_div_wide (gimple_stmt_iterator *gsi, tree inner_type,
   tree rr, ri, ratio, div, t1, t2, tr, ti, compare;
   basic_block bb_cond, bb_true, bb_false, bb_join;
   gimple *stmt;
+  gimple_seq stmts = NULL;
+  location_t loc = gimple_location (gsi_stmt (*gsi));
 
   /* Examine |br| < |bi|, and branch.  */
-  t1 = gimplify_build1 (gsi, ABS_EXPR, inner_type, br);
-  t2 = gimplify_build1 (gsi, ABS_EXPR, inner_type, bi);
-  compare = fold_build2_loc (gimple_location (gsi_stmt (*gsi)),
-                            LT_EXPR, boolean_type_node, t1, t2);
-  STRIP_NOPS (compare);
+  t1 = gimple_build (&stmts, loc, ABS_EXPR, inner_type, br);
+  t2 = gimple_build (&stmts, loc, ABS_EXPR, inner_type, bi);
+  compare = gimple_build (&stmts, loc,
+                         LT_EXPR, boolean_type_node, t1, t2);
 
   bb_cond = bb_true = bb_false = bb_join = NULL;
   rr = ri = tr = ti = NULL;
@@ -1282,15 +1299,11 @@ expand_complex_div_wide (gimple_stmt_iterator *gsi, tree inner_type,
     {
       edge e;
       gimple *stmt;
-      tree cond, tmp;
 
-      tmp = make_ssa_name (boolean_type_node);
-      stmt = gimple_build_assign (tmp, compare);
-      gsi_insert_before (gsi, stmt, GSI_SAME_STMT);
-
-      cond = fold_build2_loc (gimple_location (stmt),
-                         EQ_EXPR, boolean_type_node, tmp, boolean_true_node);
-      stmt = gimple_build_cond_from_tree (cond, NULL_TREE, NULL_TREE);
+      gsi_insert_seq_before (gsi, stmts, GSI_SAME_STMT);
+      stmts = NULL;
+      stmt = gimple_build_cond (NE_EXPR, compare, boolean_false_node,
+                               NULL_TREE, NULL_TREE);
       gsi_insert_before (gsi, stmt, GSI_SAME_STMT);
 
       /* Split the original block, and create the TRUE and FALSE blocks.  */
@@ -1326,6 +1339,11 @@ expand_complex_div_wide (gimple_stmt_iterator *gsi, tree inner_type,
       rr = create_tmp_reg (inner_type);
       ri = create_tmp_reg (inner_type);
     }
+  else
+    {
+      gimple_seq_discard (stmts);
+      stmts = NULL;
+    }
 
   /* In the TRUE branch, we compute
       ratio = br/bi;
@@ -1342,19 +1360,21 @@ expand_complex_div_wide (gimple_stmt_iterator *gsi, tree inner_type,
          gsi_insert_after (gsi, gimple_build_nop (), GSI_NEW_STMT);
        }
 
-      ratio = gimplify_build2 (gsi, code, inner_type, br, bi);
+      ratio = gimple_build (&stmts, loc, code, inner_type, br, bi);
 
-      t1 = gimplify_build2 (gsi, MULT_EXPR, inner_type, br, ratio);
-      div = gimplify_build2 (gsi, PLUS_EXPR, inner_type, t1, bi);
+      t1 = gimple_build (&stmts, loc, MULT_EXPR, inner_type, br, ratio);
+      div = gimple_build (&stmts, loc, PLUS_EXPR, inner_type, t1, bi);
 
-      t1 = gimplify_build2 (gsi, MULT_EXPR, inner_type, ar, ratio);
-      tr = gimplify_build2 (gsi, PLUS_EXPR, inner_type, t1, ai);
+      t1 = gimple_build (&stmts, loc, MULT_EXPR, inner_type, ar, ratio);
+      tr = gimple_build (&stmts, loc, PLUS_EXPR, inner_type, t1, ai);
 
-      t1 = gimplify_build2 (gsi, MULT_EXPR, inner_type, ai, ratio);
-      ti = gimplify_build2 (gsi, MINUS_EXPR, inner_type, t1, ar);
+      t1 = gimple_build (&stmts, loc, MULT_EXPR, inner_type, ai, ratio);
+      ti = gimple_build (&stmts, loc, MINUS_EXPR, inner_type, t1, ar);
 
-      tr = gimplify_build2 (gsi, code, inner_type, tr, div);
-      ti = gimplify_build2 (gsi, code, inner_type, ti, div);
+      tr = gimple_build (&stmts, loc, code, inner_type, tr, div);
+      ti = gimple_build (&stmts, loc, code, inner_type, ti, div);
+      gsi_insert_seq_before (gsi, stmts, GSI_SAME_STMT);
+      stmts = NULL;
 
      if (bb_true)
        {
@@ -1381,19 +1401,21 @@ expand_complex_div_wide (gimple_stmt_iterator *gsi, tree inner_type,
          gsi_insert_after (gsi, gimple_build_nop (), GSI_NEW_STMT);
        }
 
-      ratio = gimplify_build2 (gsi, code, inner_type, bi, br);
+      ratio = gimple_build (&stmts, loc, code, inner_type, bi, br);
 
-      t1 = gimplify_build2 (gsi, MULT_EXPR, inner_type, bi, ratio);
-      div = gimplify_build2 (gsi, PLUS_EXPR, inner_type, t1, br);
+      t1 = gimple_build (&stmts, loc, MULT_EXPR, inner_type, bi, ratio);
+      div = gimple_build (&stmts, loc, PLUS_EXPR, inner_type, t1, br);
 
-      t1 = gimplify_build2 (gsi, MULT_EXPR, inner_type, ai, ratio);
-      tr = gimplify_build2 (gsi, PLUS_EXPR, inner_type, t1, ar);
+      t1 = gimple_build (&stmts, loc, MULT_EXPR, inner_type, ai, ratio);
+      tr = gimple_build (&stmts, loc, PLUS_EXPR, inner_type, t1, ar);
 
-      t1 = gimplify_build2 (gsi, MULT_EXPR, inner_type, ar, ratio);
-      ti = gimplify_build2 (gsi, MINUS_EXPR, inner_type, ai, t1);
+      t1 = gimple_build (&stmts, loc, MULT_EXPR, inner_type, ar, ratio);
+      ti = gimple_build (&stmts, loc, MINUS_EXPR, inner_type, ai, t1);
 
-      tr = gimplify_build2 (gsi, code, inner_type, tr, div);
-      ti = gimplify_build2 (gsi, code, inner_type, ti, div);
+      tr = gimple_build (&stmts, loc, code, inner_type, tr, div);
+      ti = gimple_build (&stmts, loc, code, inner_type, ti, div);
+      gsi_insert_seq_before (gsi, stmts, GSI_SAME_STMT);
+      stmts = NULL;
 
      if (bb_false)
        {
@@ -1422,40 +1444,42 @@ expand_complex_division (gimple_stmt_iterator *gsi, tree type,
                         complex_lattice_t al, complex_lattice_t bl)
 {
   tree rr, ri;
+  gimple_seq stmts = NULL;
+  location_t loc = gimple_location (gsi_stmt (*gsi));
 
   tree inner_type = TREE_TYPE (type);
   switch (PAIR (al, bl))
     {
     case PAIR (ONLY_REAL, ONLY_REAL):
-      rr = gimplify_build2 (gsi, code, inner_type, ar, br);
+      rr = gimple_build (&stmts, loc, code, inner_type, ar, br);
       ri = ai;
       break;
 
     case PAIR (ONLY_REAL, ONLY_IMAG):
       rr = ai;
-      ri = gimplify_build2 (gsi, code, inner_type, ar, bi);
-      ri = gimplify_build1 (gsi, NEGATE_EXPR, inner_type, ri);
+      ri = gimple_build (&stmts, loc, code, inner_type, ar, bi);
+      ri = gimple_build (&stmts, loc, NEGATE_EXPR, inner_type, ri);
       break;
 
     case PAIR (ONLY_IMAG, ONLY_REAL):
       rr = ar;
-      ri = gimplify_build2 (gsi, code, inner_type, ai, br);
+      ri = gimple_build (&stmts, loc, code, inner_type, ai, br);
       break;
 
     case PAIR (ONLY_IMAG, ONLY_IMAG):
-      rr = gimplify_build2 (gsi, code, inner_type, ai, bi);
+      rr = gimple_build (&stmts, loc, code, inner_type, ai, bi);
       ri = ar;
       break;
 
     case PAIR (VARYING, ONLY_REAL):
-      rr = gimplify_build2 (gsi, code, inner_type, ar, br);
-      ri = gimplify_build2 (gsi, code, inner_type, ai, br);
+      rr = gimple_build (&stmts, loc, code, inner_type, ar, br);
+      ri = gimple_build (&stmts, loc, code, inner_type, ai, br);
       break;
 
     case PAIR (VARYING, ONLY_IMAG):
-      rr = gimplify_build2 (gsi, code, inner_type, ai, bi);
-      ri = gimplify_build2 (gsi, code, inner_type, ar, bi);
-      ri = gimplify_build1 (gsi, NEGATE_EXPR, inner_type, ri);
+      rr = gimple_build (&stmts, loc, code, inner_type, ai, bi);
+      ri = gimple_build (&stmts, loc, code, inner_type, ar, bi);
+      ri = gimple_build (&stmts, loc, NEGATE_EXPR, inner_type, ri);
       break;
 
     case PAIR (ONLY_REAL, VARYING):
@@ -1490,6 +1514,7 @@ expand_complex_division (gimple_stmt_iterator *gsi, tree type,
       gcc_unreachable ();
     }
 
+  gsi_insert_seq_before (gsi, stmts, GSI_SAME_STMT);
   update_complex_assignment (gsi, rr, ri);
 }
 
@@ -1502,10 +1527,13 @@ expand_complex_negation (gimple_stmt_iterator *gsi, tree inner_type,
                         tree ar, tree ai)
 {
   tree rr, ri;
+  gimple_seq stmts = NULL;
+  location_t loc = gimple_location (gsi_stmt (*gsi));
 
-  rr = gimplify_build1 (gsi, NEGATE_EXPR, inner_type, ar);
-  ri = gimplify_build1 (gsi, NEGATE_EXPR, inner_type, ai);
+  rr = gimple_build (&stmts, loc, NEGATE_EXPR, inner_type, ar);
+  ri = gimple_build (&stmts, loc, NEGATE_EXPR, inner_type, ai);
 
+  gsi_insert_seq_before (gsi, stmts, GSI_SAME_STMT);
   update_complex_assignment (gsi, rr, ri);
 }
 
@@ -1518,9 +1546,12 @@ expand_complex_conjugate (gimple_stmt_iterator *gsi, tree inner_type,
                          tree ar, tree ai)
 {
   tree ri;
+  gimple_seq stmts = NULL;
+  location_t loc = gimple_location (gsi_stmt (*gsi));
 
-  ri = gimplify_build1 (gsi, NEGATE_EXPR, inner_type, ai);
+  ri = gimple_build (&stmts, loc, NEGATE_EXPR, inner_type, ai);
 
+  gsi_insert_seq_before (gsi, stmts, GSI_SAME_STMT);
   update_complex_assignment (gsi, ar, ri);
 }
 
@@ -1531,15 +1562,16 @@ expand_complex_comparison (gimple_stmt_iterator *gsi, tree ar, tree ai,
                           tree br, tree bi, enum tree_code code)
 {
   tree cr, ci, cc, type;
-  gimple *stmt;
-
-  cr = gimplify_build2 (gsi, code, boolean_type_node, ar, br);
-  ci = gimplify_build2 (gsi, code, boolean_type_node, ai, bi);
-  cc = gimplify_build2 (gsi,
-                       (code == EQ_EXPR ? TRUTH_AND_EXPR : TRUTH_OR_EXPR),
-                       boolean_type_node, cr, ci);
-
-  stmt = gsi_stmt (*gsi);
+  gimple *stmt = gsi_stmt (*gsi);
+  gimple_seq stmts = NULL;
+  location_t loc = gimple_location (stmt);
+
+  cr = gimple_build (&stmts, loc, code, boolean_type_node, ar, br);
+  ci = gimple_build (&stmts, loc, code, boolean_type_node, ai, bi);
+  cc = gimple_build (&stmts, loc,
+                    (code == EQ_EXPR ? BIT_AND_EXPR : BIT_IOR_EXPR),
+                    boolean_type_node, cr, ci);
+  gsi_insert_seq_before (gsi, stmts, GSI_SAME_STMT);
 
   switch (gimple_code (stmt))
     {