Hi!

The find_cond_trap code isn't really prepared to turn conditional return
into unconditional when converting non-conditional trap into conditional,
without RTL checking it generates (label_ref (return)), the edges updates
are also wrong.
This patch just disables that transformation, IMHO trading conditional
return + unconditional trap with conditional trap + unconditional return
isn't worth it.

Martin Sebor has kindly bootstrapped/regtested this on powerpc64le-linux,
ok for trunk?

2015-12-23  Jakub Jelinek  <ja...@redhat.com>

        PR target/69015
        * ifcvt.c (find_cond_trap): Give up if returnjump_p (jump).

        * gcc.dg/pr69015.c: New test.

--- gcc/ifcvt.c.jj      2015-12-10 17:01:06.000000000 +0100
+++ gcc/ifcvt.c 2015-12-22 19:43:07.404639873 +0100
@@ -4526,8 +4526,11 @@ find_cond_trap (basic_block test_bb, edg
     return FALSE;
 
   /* If the conditional jump is more than just a conditional jump, then
-     we can not do if-conversion on this block.  */
-  if (! onlyjump_p (jump))
+     we can not do if-conversion on this block.  Give up for returnjump_p,
+     changing a conditional return followed by unconditional trap for
+     conditional trap followed by unconditional return is likely not
+     beneficial and harder to handle.  */
+  if (! onlyjump_p (jump) || returnjump_p (jump))
     return FALSE;
 
   /* We must be comparing objects whose modes imply the size.  */
--- gcc/testsuite/gcc.dg/pr69015.c.jj   2015-12-22 19:52:32.457756578 +0100
+++ gcc/testsuite/gcc.dg/pr69015.c      2015-12-22 19:53:39.544820625 +0100
@@ -0,0 +1,10 @@
+/* PR target/69015 */
+/* { dg-do compile } */
+/* { dg-options "-O2 -fno-if-conversion" } */
+
+void
+foo (int c)
+{
+  if (c)
+    __builtin_trap ();
+}

        Jakub

Reply via email to