The following fixes PR88087 - a failure for PRE to re-materialize
call fntypes.

Bootstrapped and tested on x86_64-unknown-linux-gnu, applied.

Richard.

2018-11-20  Richard Biener  <rguent...@suse.de>

        PR tree-optimization/88087
        * tree-ssa-pre.c (create_expression_by_pieces): Re-materialize
        call fntype.
        * tree-ssa-sccvn.c (copy_reference_ops_from_call): Remember
        call fntype.

        * gcc.dg/tree-ssa/pr88087.c: New testcase.

>From 2c92b2c67a1464671c795e2c524b492ca0dce1a0 Mon Sep 17 00:00:00 2001
From: Richard Guenther <rguent...@suse.de>
Date: Mon, 19 Nov 2018 13:19:21 +0100
Subject: [PATCH] fix-pr88087


diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr88087.c 
b/gcc/testsuite/gcc.dg/tree-ssa/pr88087.c
new file mode 100644
index 00000000000..558f49f4bd7
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-ssa/pr88087.c
@@ -0,0 +1,17 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-pre-stats" } */
+
+int f();
+int d;
+void c()
+{
+  for (;;)
+    {
+      f();
+      int (*fp)() __attribute__((const)) = (void *)f;
+      d = fp();
+    }
+}
+
+/* We shouldn't ICE and hoist the const call of fp out of the loop.  */
+/* { dg-final { scan-tree-dump "Eliminated: 1" "pre" } } */
diff --git a/gcc/tree-ssa-pre.c b/gcc/tree-ssa-pre.c
index 20d3c7807a1..4d5bce83a2c 100644
--- a/gcc/tree-ssa-pre.c
+++ b/gcc/tree-ssa-pre.c
@@ -2792,9 +2792,10 @@ create_expression_by_pieces (basic_block block, pre_expr 
expr,
              args.quick_push (arg);
            }
          gcall *call = gimple_build_call_vec (fn, args);
+         gimple_call_set_fntype (call, currop->type);
          if (sc)
            gimple_call_set_chain (call, sc);
-         tree forcedname = make_ssa_name (currop->type);
+         tree forcedname = make_ssa_name (TREE_TYPE (currop->type));
          gimple_call_set_lhs (call, forcedname);
          /* There's no CCP pass after PRE which would re-compute alignment
             information so make sure we re-materialize this here.  */
diff --git a/gcc/tree-ssa-sccvn.c b/gcc/tree-ssa-sccvn.c
index 43641916d52..01bedf56662 100644
--- a/gcc/tree-ssa-sccvn.c
+++ b/gcc/tree-ssa-sccvn.c
@@ -1206,7 +1206,7 @@ copy_reference_ops_from_call (gcall *call,
 
   /* Copy the type, opcode, function, static chain and EH region, if any.  */
   memset (&temp, 0, sizeof (temp));
-  temp.type = gimple_call_return_type (call);
+  temp.type = gimple_call_fntype (call);
   temp.opcode = CALL_EXPR;
   temp.op0 = gimple_call_fn (call);
   temp.op1 = gimple_call_chain (call);

Reply via email to