https://gcc.gnu.org/g:423786c073054b9dbb1c73eadfb47dfcbc2b6955
commit r13-10392-g423786c073054b9dbb1c73eadfb47dfcbc2b6955 Author: Stefan Schulze Frielinghaus <[email protected]> Date: Fri Jun 26 16:46:48 2026 +0200 s390: Deal with non-compare conditions during RTX costing [PR125972] 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. (cherry picked from commit f070b1aaa0f87dc6405a1840581c17c005a1f5b1) Diff: --- gcc/config/s390/s390.cc | 15 ++++++++++++--- gcc/testsuite/gcc.target/s390/pr125972.c | 20 ++++++++++++++++++++ 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/gcc/config/s390/s390.cc b/gcc/config/s390/s390.cc index 59f2f4bf7db8..08fbe1f9bce2 100644 --- a/gcc/config/s390/s390.cc +++ b/gcc/config/s390/s390.cc @@ -3678,13 +3678,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. */ @@ -3693,6 +3695,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; @@ -3751,7 +3759,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 index 000000000000..a7180477c3b7 --- /dev/null +++ b/gcc/testsuite/gcc.target/s390/pr125972.c @@ -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; + } +}
