]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
s390: Deal with non-compare conditions during RTX costing [PR125972]
authorStefan Schulze Frielinghaus <stefansf@gcc.gnu.org>
Fri, 26 Jun 2026 14:46:48 +0000 (16:46 +0200)
committerStefan Schulze Frielinghaus <stefansf@gcc.gnu.org>
Fri, 26 Jun 2026 14:46:48 +0000 (16:46 +0200)
During cprop we have to cost intermediate RTXs which may have
non-compare conditions as e.g. r108={(0x1)?r113:r109} which get folded
later on.

First seen with r16-5417-g97a7d568f3d720.

PR target/125972

gcc/ChangeLog:

* config/s390/s390.cc (s390_rtx_costs): Deal with non-compare
conditions during costing.  Also fix some indentation.

gcc/testsuite/ChangeLog:

* gcc.target/s390/pr125972.c: New test.

gcc/config/s390/s390.cc
gcc/testsuite/gcc.target/s390/pr125972.c [new file with mode: 0644]

index 1bddd5e454ae747aa375b42b193e292fa37800c4..d57499a48e605cc2d6306217e29d2ccfb267f23e 100644 (file)
@@ -3977,13 +3977,15 @@ s390_rtx_costs (rtx x, machine_mode mode, int outer_code,
     case MEM:
       *total = 0;
       return true;
-      case SET: {
+    case SET:
+      {
        rtx dst = SET_DEST (x);
        rtx src = SET_SRC (x);
 
        switch (GET_CODE (src))
          {
-           case IF_THEN_ELSE: {
+         case IF_THEN_ELSE:
+           {
              /* Without this a conditional move instruction would be
                 accounted as 3 * COSTS_N_INSNS (set, if_then_else,
                 comparison operator).  That's a bit pessimistic.  */
@@ -3992,6 +3994,12 @@ s390_rtx_costs (rtx x, machine_mode mode, int outer_code,
                return false;
 
              rtx cond = XEXP (src, 0);
+             /* Intermediate RTXs may have a non-compare condition as e.g. a
+                constant like r108={(0x1)?r113:r109} which get folded later
+                on.  */
+             if (GET_RTX_CLASS (GET_CODE (cond)) != RTX_COMPARE
+                 && GET_RTX_CLASS (GET_CODE (cond)) != RTX_COMM_COMPARE)
+               return false;
              if (!CC_REG_P (XEXP (cond, 0)) || !CONST_INT_P (XEXP (cond, 1)))
                return false;
 
@@ -4050,7 +4058,8 @@ s390_rtx_costs (rtx x, machine_mode mode, int outer_code,
              /* Otherwise just cost the src.  */
              *total += rtx_cost (src, mode, SET, 1, speed);
            return true;
-           case MEM: {
+         case MEM:
+           {
              rtx address = XEXP (dst, 0);
              rtx tmp;
              HOST_WIDE_INT tmp2;
diff --git a/gcc/testsuite/gcc.target/s390/pr125972.c b/gcc/testsuite/gcc.target/s390/pr125972.c
new file mode 100644 (file)
index 0000000..a718047
--- /dev/null
@@ -0,0 +1,20 @@
+/* { dg-do compile { target int128 } } */
+/* { dg-options "-march=z16 -O3" } */
+
+int a, b, c;
+long d, e;
+int *f;
+__int128 g;
+void h() {
+  g = 0;
+  for (; g <= 33; ++g) {
+    int *i = &c;
+    *i = d - a;
+    if (*i) {
+      c = 0;
+      for (; c <= 8; ++c)
+        f = &b;
+    } else
+      ++e;
+  }
+}