diff mbox

[match-and-simplify] Robusten gimple_build against non-SSA context

Message ID alpine.LSU.2.11.1408061626140.20733@zhemvz.fhfr.qr
State New
Headers show

Commit Message

Richard Biener Aug. 6, 2014, 2:27 p.m. UTC
We fold stmts from non-SSA so when we simplify a single stmt
into multiple ones (like strcat (x, "foo") -> memcpy (x + strlen ("foo"), 
....)) then gimple_build fails because it unconditionally builds
SSA names.

Fixed.

Richard.

2014-08-06  Richard Biener  <rguenther@suse.de>

	* gimple-fold.c (gimple_build): Allow to be called from
	non-SSA context.
diff mbox

Patch

Index: gcc/gimple-fold.c
===================================================================
--- gcc/gimple-fold.c	(revision 213651)
+++ gcc/gimple-fold.c	(working copy)
@@ -3733,7 +3733,10 @@  gimple_build (gimple_seq *seq, location_
   tree res = gimple_simplify (code, type, op0, seq, valueize);
   if (!res)
     {
-      res = make_ssa_name (type, NULL);
+      if (gimple_in_ssa_p (cfun))
+	res = make_ssa_name (type, NULL);
+      else
+	res = create_tmp_reg (type, NULL);
       gimple stmt;
       if (code == REALPART_EXPR
 	  || code == IMAGPART_EXPR
@@ -3763,7 +3766,10 @@  gimple_build (gimple_seq *seq, location_
   tree res = gimple_simplify (code, type, op0, op1, seq, valueize);
   if (!res)
     {
-      res = make_ssa_name (type, NULL);
+      if (gimple_in_ssa_p (cfun))
+	res = make_ssa_name (type, NULL);
+      else
+	res = create_tmp_reg (type, NULL);
       gimple stmt = gimple_build_assign_with_ops (code, res, op0, op1);
       gimple_set_location (stmt, loc);
       gimple_seq_add_stmt_without_update (seq, stmt);
@@ -3787,7 +3793,10 @@  gimple_build (gimple_seq *seq, location_
 			      seq, valueize);
   if (!res)
     {
-      res = make_ssa_name (type, NULL);
+      if (gimple_in_ssa_p (cfun))
+	res = make_ssa_name (type, NULL);
+      else
+	res = create_tmp_reg (type, NULL);
       gimple stmt;
       if (code == BIT_FIELD_REF)
 	stmt = gimple_build_assign_with_ops (code, res,
@@ -3816,7 +3825,10 @@  gimple_build (gimple_seq *seq, location_
   tree res = gimple_simplify (fn, type, arg0, seq, valueize);
   if (!res)
     {
-      res = make_ssa_name (type, NULL);
+      if (gimple_in_ssa_p (cfun))
+	res = make_ssa_name (type, NULL);
+      else
+	res = create_tmp_reg (type, NULL);
       tree decl = builtin_decl_implicit (fn);
       gimple stmt = gimple_build_call (decl, 1, arg0);
       gimple_call_set_lhs (stmt, res);