public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r12-5787] [PR103028] test ifcvt trap_if seq more strictly after reload
@ 2021-12-04  3:19 Alexandre Oliva
  0 siblings, 0 replies; only message in thread
From: Alexandre Oliva @ 2021-12-04  3:19 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:daca416fc2816a5e481b26c8d2010127101d77ce

commit r12-5787-gdaca416fc2816a5e481b26c8d2010127101d77ce
Author: Alexandre Oliva <oliva@adacore.com>
Date:   Sat Dec 4 00:17:16 2021 -0300

    [PR103028] test ifcvt trap_if seq more strictly after reload
    
    When -fif-conversion2 is enabled, we attempt to replace conditional
    branches around unconditional traps with conditional traps.  That
    canonicalizes compares, which may change an immediate that barely fits
    into one that doesn't.
    
    The compare for the trap is first checked using the predicates of
    cbranch predicates, and then, compare and conditional trap insns are
    emitted and recognized.
    
    In the failing s390x testcase, i <=u 0xffff_ffff is canonicalized into
    i <u 0x1_0000_0000, and the latter immediate doesn't fit.  The insn
    predicates (both cbranch and cmpdi_ccu) happily accept it, since the
    register allocator has no trouble getting them into registers.  The
    problem is that ifcvt2 runs after reload, so we recognize the compare
    insn successfully, but later on we barf when we find that none of the
    constraints fit.
    
    This patch arranges for the trap_if-issuing bits in ifcvt to validate
    post-reload insns using a stricter test that also checks that operands
    fit the constraints.
    
    
    for  gcc/ChangeLog
    
            PR rtl-optimization/103028
            * ifcvt.c (find_cond_trap): Validate new insns more strictly
            after reload.
    
    for  gcc/testsuite/ChangeLog
    
            PR rtl-optimization/103028
            * gcc.dg/pr103028.c: New.

Diff:
---
 gcc/ifcvt.c                     |  4 +++-
 gcc/testsuite/gcc.dg/pr103028.c | 21 +++++++++++++++++++++
 2 files changed, 24 insertions(+), 1 deletion(-)

diff --git a/gcc/ifcvt.c b/gcc/ifcvt.c
index 017944f4f79..b0052f6c5ce 100644
--- a/gcc/ifcvt.c
+++ b/gcc/ifcvt.c
@@ -4726,7 +4726,9 @@ find_cond_trap (basic_block test_bb, edge then_edge, edge else_edge)
 
   /* If that results in an invalid insn, back out.  */
   for (rtx_insn *x = seq; x; x = NEXT_INSN (x))
-    if (recog_memoized (x) < 0)
+    if (reload_completed
+	? !valid_insn_p (x)
+	: recog_memoized (x) < 0)
       return FALSE;
 
   /* Emit the new insns before cond_earliest.  */
diff --git a/gcc/testsuite/gcc.dg/pr103028.c b/gcc/testsuite/gcc.dg/pr103028.c
new file mode 100644
index 00000000000..df96c62ddd3
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr103028.c
@@ -0,0 +1,21 @@
+/* { dg-do compile } */
+/* { dg-options "-fif-conversion2 -Og" } */
+/* { dg-options "-fif-conversion2 -Og -march=z9-ec" { target { s390x-*-* } } } */
+
+unsigned char x;
+int foo(void)
+{
+  unsigned long long i = x;
+  i = i + 0x80000000;
+  unsigned long long t = 0xffffffff;
+
+  if (i > t) {
+    unsigned long long ii;
+    asm("":"=g"(ii):"0"(i));
+    if ((ii <= t))
+      __builtin_trap();
+    return x;
+  }
+
+ return 0;
+}


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-12-04  3:19 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-04  3:19 [gcc r12-5787] [PR103028] test ifcvt trap_if seq more strictly after reload Alexandre Oliva

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).