Verify NOP_EXPR LHS type in IPA ICF.
authorMartin Liska <mliska@suse.cz>
Mon, 18 Nov 2019 11:51:05 +0000 (12:51 +0100)
committerMartin Liska <marxin@gcc.gnu.org>
Mon, 18 Nov 2019 11:51:05 +0000 (11:51 +0000)
2019-11-18  Martin Liska  <mliska@suse.cz>

PR ipa/92529
* ipa-icf-gimple.c (func_checker::compare_gimple_assign):
Compare LHS types of NOP_EXPR.
2019-11-18  Martin Liska  <mliska@suse.cz>

PR ipa/92529
* gcc.dg/ipa/pr92529.c: New test.

From-SVN: r278395

gcc/ChangeLog
gcc/ipa-icf-gimple.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/ipa/pr92529.c [new file with mode: 0644]

index 78a9182..a829a68 100644 (file)
@@ -1,3 +1,9 @@
+2019-11-18  Martin Liska  <mliska@suse.cz>
+
+       PR ipa/92529
+       * ipa-icf-gimple.c (func_checker::compare_gimple_assign):
+       Compare LHS types of NOP_EXPR.
+
 2019-11-18  Matthew Malcomson  <matthew.malcomson@arm.com>
 
        * run-rtl-passes.c (run_rtl_passes): Accept and handle empty
index ac53a1d..9aa2fe0 100644 (file)
@@ -620,6 +620,13 @@ func_checker::compare_gimple_assign (gimple *s1, gimple *s2)
       arg1 = gimple_op (s1, i);
       arg2 = gimple_op (s2, i);
 
+      /* LHS types of NOP_EXPR must be compatible.  */
+      if (CONVERT_EXPR_CODE_P (code1) && i == 0)
+       {
+         if (!compatible_types_p (TREE_TYPE (arg1), TREE_TYPE (arg2)))
+           return return_false_with_msg ("GIMPLE NOP LHS type mismatch");
+       }
+
       if (!compare_operand (arg1, arg2))
        return return_false_with_msg ("GIMPLE assignment operands "
                                      "are different");
index 87705b4..8773d50 100644 (file)
@@ -1,3 +1,8 @@
+2019-11-18  Martin Liska  <mliska@suse.cz>
+
+       PR ipa/92529
+       * gcc.dg/ipa/pr92529.c: New test.
+
 2019-11-18  Matthew Malcomson  <matthew.malcomson@arm.com>
 
        * gcc.dg/rtl/aarch64/unspecified-pass-error.c: New test.
diff --git a/gcc/testsuite/gcc.dg/ipa/pr92529.c b/gcc/testsuite/gcc.dg/ipa/pr92529.c
new file mode 100644 (file)
index 0000000..0864f34
--- /dev/null
@@ -0,0 +1,28 @@
+/* PR ipa/92529 */
+/* { dg-options "-O2 -fdump-ipa-icf-optimized"  } */
+
+int
+foo(volatile int a)
+{
+  return (char)a;
+}
+
+int
+bar(volatile int a)
+{
+  return (short)a;
+}
+
+#pragma GCC optimize ("-O0")
+
+int main(int argc, char **argv)
+{
+  int r = bar(1000);
+  __builtin_printf ("global: %d\n", r);
+  if (r != 1000)
+    __builtin_abort ();
+
+  return 0;
+}
+
+/* { dg-final { scan-ipa-dump "Equal symbols: 0" "icf"  } } */